Riven/srcgen/consts/champion.rs.dt

86 lines
2.5 KiB
Plaintext
Raw Normal View History

2019-10-19 09:25:09 +00:00
{{
const dotUtils = require('./dotUtils.js');
2019-10-19 09:25:09 +00:00
const champions = require('./.champion.json')
.filter(({ id }) => id > 0)
.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); };
}}{{= dotUtils.preamble() }}
2019-10-19 09:25:09 +00:00
use num_enum::{ IntoPrimitive, TryFromPrimitive };
2019-10-26 05:19:00 +00:00
use serde_repr::{ Serialize_repr, Deserialize_repr };
use strum_macros::{ EnumString, EnumIter, 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).
///
/// Implements [IntoEnumIterator](super::IntoEnumIterator).
#[non_exhaustive]
#[derive(Debug, Copy, Clone)]
#[derive(IntoPrimitive, TryFromPrimitive)]
2019-10-26 05:19:00 +00:00
#[derive(Serialize_repr, Deserialize_repr)]
#[derive(EnumString, EnumIter, Display, AsRefStr, IntoStaticStr)]
2019-10-26 05:19:00 +00:00
#[repr(i16)]
2019-10-19 09:25:09 +00:00
pub enum Champion {
/// 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
}}
/// {{= name }} (`{{= alias }}`, {{= id }}).
2021-01-05 22:38:46 +00:00
#[strum(to_string="{{= name }}"{{? name !== alias }}, 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 {
/// 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 {
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
{{
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-10-19 09:25:09 +00:00
pub fn identifier(self) -> &'static str {
match self {
Self::None => "NONE",
2019-10-19 09:25:09 +00:00
{{
for (let { name, alias } of champions) {
}}
Self::{{= enumName(name).padEnd(12) }} => "{{= alias }}",
{{
}
}}
}
}
}