2019-10-19 09:25:09 +00:00
|
|
|
{{
|
2019-10-31 08:09:20 +00:00
|
|
|
const dotUtils = require('./dotUtils.js');
|
2019-10-19 09:25:09 +00:00
|
|
|
const champions = require('./.champion.json')
|
|
|
|
.filter(({ id }) => id > 0)
|
2019-10-31 08:09:20 +00:00
|
|
|
.sortBy(({ name }) => name);
|
2019-10-19 09:25:09 +00:00
|
|
|
const hashFactor = 256;
|
|
|
|
const enumName = name => name.replace(/[^a-z]+/i, '');
|
|
|
|
const strHash = function(str) {
|
|
|
|
let h = 0;
|
|
|
|
for (let c of str)
|
|
|
|
h = hashFactor * h + c.charCodeAt(0);
|
|
|
|
return h;
|
|
|
|
};
|
|
|
|
const padId = function(id) { return ('' + id).padEnd(3); };
|
2019-10-31 08:09:20 +00:00
|
|
|
}}{{= dotUtils.preamble() }}
|
2019-10-19 09:25:09 +00:00
|
|
|
|
2019-10-26 16:23:58 +00:00
|
|
|
use num_enum::{ IntoPrimitive, TryFromPrimitive };
|
2019-10-26 05:19:00 +00:00
|
|
|
use serde_repr::{ Serialize_repr, Deserialize_repr };
|
2019-11-03 18:36:51 +00:00
|
|
|
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
2019-10-19 09:25:09 +00:00
|
|
|
|
2019-10-23 01:21:27 +00:00
|
|
|
/// League of Legend's champions.
|
|
|
|
///
|
|
|
|
/// The documentation of each variant specifies:<br>
|
|
|
|
/// NAME (`IDENTIFIER`, ID).
|
2019-10-30 20:29:23 +00:00
|
|
|
#[non_exhaustive]
|
2019-10-26 02:38:08 +00:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
2019-10-26 16:23:58 +00:00
|
|
|
#[derive(IntoPrimitive, TryFromPrimitive)]
|
2019-10-26 05:19:00 +00:00
|
|
|
#[derive(Serialize_repr, Deserialize_repr)]
|
2019-11-03 18:36:51 +00:00
|
|
|
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
|
2019-10-26 05:19:00 +00:00
|
|
|
#[repr(i16)]
|
2019-10-19 09:25:09 +00:00
|
|
|
pub enum Champion {
|
2019-11-03 18:36:51 +00:00
|
|
|
/// A champion that doesn't exist. Used in TeamBans when no champion was banned.
|
|
|
|
///
|
|
|
|
/// None (`NONE`, -1).
|
2019-10-26 05:19:00 +00:00
|
|
|
None = -1,
|
|
|
|
|
2019-10-19 09:25:09 +00:00
|
|
|
{{
|
2019-10-23 01:21:27 +00:00
|
|
|
for (let { id, alias, name } of champions) {
|
2019-10-19 09:25:09 +00:00
|
|
|
}}
|
2019-11-03 18:36:51 +00:00
|
|
|
/// {{= name }} (`{{= alias }}`, {{= id }}).
|
|
|
|
#[strum(to_string="{{= name }}", serialize="{{= alias }}")] {{= enumName(name) }} = {{= id }},
|
2019-10-19 09:25:09 +00:00
|
|
|
{{
|
|
|
|
}
|
|
|
|
}}
|
2019-10-23 01:21:27 +00:00
|
|
|
}
|
2019-10-19 09:25:09 +00:00
|
|
|
|
|
|
|
impl Champion {
|
2019-11-03 18:36:51 +00:00
|
|
|
/// The champion's name (localized `en_US`), or `"NONE"` for the None variant.
|
2019-10-19 09:25:09 +00:00
|
|
|
pub fn name(self) -> &'static str {
|
2019-11-03 18:36:51 +00:00
|
|
|
self.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The champion's identifier key. Somtimes called "key", "identifier", or "alias".
|
|
|
|
/// This is mainly used in DDragon paths.
|
|
|
|
///
|
|
|
|
/// This is generally the `en_US` name with spaces and punctuation removed,
|
|
|
|
/// but there are the following exceptions:
|
2019-11-05 07:29:20 +00:00
|
|
|
///
|
|
|
|
/// Variant | Name | Identifier
|
|
|
|
/// --------|------|-----------
|
|
|
|
/// `None` | "NONE" | "NONE"
|
2019-10-19 09:25:09 +00:00
|
|
|
{{
|
2019-11-03 18:36:51 +00:00
|
|
|
for (let { name, alias } of champions) {
|
|
|
|
if (name.replace(/[^a-zA-Z0-9]+/, '') !== alias) {
|
2019-10-19 09:25:09 +00:00
|
|
|
}}
|
2019-11-05 07:29:20 +00:00
|
|
|
/// `{{= enumName(name) }}` | "{{= name }}" | "{{= alias }}"
|
2019-10-19 09:25:09 +00:00
|
|
|
{{
|
|
|
|
}
|
|
|
|
}
|
2019-11-03 18:36:51 +00:00
|
|
|
}}
|
2019-10-19 09:25:09 +00:00
|
|
|
pub fn identifier(self) -> &'static str {
|
|
|
|
match self {
|
2019-11-03 18:36:51 +00:00
|
|
|
Self::None => "NONE",
|
2019-10-19 09:25:09 +00:00
|
|
|
{{
|
|
|
|
for (let { name, alias } of champions) {
|
|
|
|
}}
|
|
|
|
Self::{{= enumName(name).padEnd(12) }} => "{{= alias }}",
|
|
|
|
{{
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|