{{ const dotUtils = require('./dotUtils.js'); const routesTable = require('./.routesTable.json'); }}{{= dotUtils.preamble() }} use num_enum::{ IntoPrimitive, TryFromPrimitive }; use strum_macros::{ EnumString, EnumIter, Display, IntoStaticStr }; /// Regional routes, used in tournament services, Legends of Runeterra (LoR), and other some endpoints. #[derive(Debug)] #[derive(PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(IntoPrimitive, TryFromPrimitive)] #[derive(EnumString, EnumIter, Display, IntoStaticStr)] #[derive(Clone, Copy)] #[repr(u8)] #[non_exhaustive] pub enum RegionalRoute { {{ for (const [ name, { id, description, deprecated } ] of Object.entries(routesTable['regional'])) { const desc = description.split('\n'); }} {{~ desc :line }} /// {{= line }} {{~}} /// /// `{{= id }}` (riotapi-schema ID/repr) {{? deprecated }} #[deprecated] {{?}} {{= name.toUpperCase() }} = {{= id }}, {{ } }} } /// Platform routes for League of Legends (LoL), Teamfight Tactics (TFT), and Legends of Runeterra (LoR). #[derive(Debug)] #[derive(PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(IntoPrimitive, TryFromPrimitive)] #[derive(EnumString, EnumIter, Display, IntoStaticStr)] #[derive(Clone, Copy)] #[repr(u8)] #[non_exhaustive] // Note: strum(serialize = ...) actually specifies extra DEserialization values. pub enum PlatformRoute { {{ for (const [ name, { id, description, altName, deprecated } ] of Object.entries(routesTable['platform'])) { const desc = description.split('\n'); }} {{~ desc :line }} /// {{= line }} {{~}} /// /// `{{= id }}` (riotapi-schema ID/repr) {{? deprecated }} #[deprecated] {{?}} {{? altName }} #[strum(to_string="{{= name.toUpperCase() }}", serialize="{{= altName }}")] {{?}} {{= name.toUpperCase() }} = {{= id }}, {{ } }} } impl PlatformRoute { /// Converts this [`PlatformRoute`] into its corresponding /// [`RegionalRoute`] for LoL and TFT match endpoints. /// For example, [`match-v5`](crate::endpoints::MatchV5). pub fn to_regional(self) -> RegionalRoute { match self { {{ for (const [ name, { regionalRoute } ] of Object.entries(routesTable['platform'])) { }} Self::{{= name.toUpperCase() }} => RegionalRoute::{{= regionalRoute.toUpperCase() }}, {{ } }} } } /// Converts this [`PlatformRoute`] into its corresponding /// [`RegionalRoute`] for LoR endpoints. /// For example, [`lor-match-v1`](crate::endpoints::LorMatchV1). pub fn to_regional_lor(self) -> RegionalRoute { match self { {{ for (const [ name, { regionalRouteLor } ] of Object.entries(routesTable['platform'])) { }} Self::{{= name.toUpperCase() }} => RegionalRoute::{{= regionalRouteLor.toUpperCase() }}, {{ } }} } } /// Used in the LoL Tournament API. Specifically /// [`tournament-stub-v4.registerProviderData`](crate::endpoints::TournamentStubV4::register_provider_data) /// and [`tournament-v4.registerProviderData`](crate::endpoints::TournamentV4::register_provider_data). pub fn to_tournament_region(self) -> Option { match self { {{ for (const [ name, { tournamentRegion } ] of Object.entries(routesTable['platform'])) { if (!tournamentRegion) continue; }} Self::{{= name.toUpperCase() }} => Some(TournamentRegion::{{= tournamentRegion }}), {{ } }} _other => None, } } /// Get the slightly more human-friendly alternate name for this `PlatformRoute`. Specifically /// excludes any trailing numbers and appends extra N(orth), S(outh), E(ast), and/or W(est) /// suffixes to some names. Some of these are old region names which are often still used as /// user-facing names, e.g. on op.gg. /// /// Note these strings *are* handled by the `FromStr` implementation, if you wish to parse them /// back into `PlatformRoute`s. pub fn as_region_str(self) -> &'static str { match self { {{ for (const [ name, { altName } ] of Object.entries(routesTable['platform'])) { if (!altName) continue; }} Self::{{= name.toUpperCase() }} => "{{= altName }}", {{ } }} other => other.into(), } } } /// Platform routes for Valorant. #[derive(Debug)] #[derive(PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(IntoPrimitive, TryFromPrimitive)] #[derive(EnumString, EnumIter, Display, IntoStaticStr)] #[derive(Clone, Copy)] #[repr(u8)] #[non_exhaustive] pub enum ValPlatformRoute { {{ for (const [ name, { id, description, deprecated } ] of Object.entries(routesTable['val-platform'])) { const desc = description.split('\n'); }} {{~ desc :line }} /// {{= line }} {{~}} /// /// `{{= id }}` (riotapi-schema ID/repr) {{? deprecated }} #[deprecated] {{?}} {{= name.toUpperCase() }} = {{= id }}, {{ } }} } /// Tournament regions for League of Legends (LoL) used in /// [`tournament-stub-v4.registerProviderData`](crate::endpoints::TournamentStubV4::register_provider_data) /// and [`tournament-v4.registerProviderData`](crate::endpoints::TournamentV4::register_provider_data). #[derive(Debug)] #[derive(PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(IntoPrimitive, TryFromPrimitive)] #[derive(EnumString, EnumIter, Display, IntoStaticStr)] #[derive(serde::Serialize, serde::Deserialize)] #[derive(Clone, Copy)] #[repr(u8)] #[non_exhaustive] // Note: strum(serialize = ...) actually specifies extra DEserialization values. pub enum TournamentRegion { {{ for (const [ name, { id, description, tournamentRegion, deprecated } ] of Object.entries(routesTable['platform'])) { if (tournamentRegion) { const desc = description.split('\n'); }} {{~ desc :line }} /// {{= line }} {{~}} {{? deprecated }} #[deprecated] {{?}} {{= tournamentRegion }} = {{= id }}, {{ } } }} }