From d7330fcd843bb0fdacf52ee1e0b0880ac2357f59 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Fri, 20 Jan 2023 22:03:13 -0800 Subject: [PATCH] Regen, update for `TournamentRegion` enum, more `PlatformRoute` `altName`s --- riven/src/consts/queue.rs | 9 ++-- riven/src/consts/route.rs | 74 ++++++++++++++++++++++++++++++++- riven/src/consts/route_ext.rs | 8 ++++ riven/src/endpoints.rs | 2 +- riven/src/meta.rs | 2 +- riven/src/models.rs | 6 +-- riven/srcgen/consts/route.rs.dt | 58 +++++++++++++++++++++++++- 7 files changed, 147 insertions(+), 12 deletions(-) diff --git a/riven/src/consts/queue.rs b/riven/src/consts/queue.rs index f67090d..77d4c98 100644 --- a/riven/src/consts/queue.rs +++ b/riven/src/consts/queue.rs @@ -220,8 +220,11 @@ newtype_enum! { /// Dark Star: Singularity games on Cosmic Ruins COSMIC_RUINS_DARK_STAR_SINGULARITY = 610, /// `700`. - /// Clash games on Summoner's Rift + /// Summoner's Rift Clash games on Summoner's Rift SUMMONERS_RIFT_CLASH = 700, + /// `720`. + /// ARAM Clash games on Howling Abyss + HOWLING_ABYSS_ARAM_CLASH = 720, /// `800`. /// Co-op vs. AI Intermediate Bot games on Twisted Treeline /// Deprecated in patch 9.23 @@ -325,10 +328,10 @@ newtype_enum! { /// Nexus Blitz games on Nexus Blitz /// Deprecated in patch 9.2 in favor of queueId 1300 #[deprecated(note="Deprecated in patch 9.2 in favor of queueId 1300")] - NEXUS_BLITZ_NEXUS_BLITZ_DEPRECATED_1200 = 1200, + NEXUS_BLITZ_DEPRECATED_1200 = 1200, /// `1300`. /// Nexus Blitz games on Nexus Blitz - NEXUS_BLITZ_NEXUS_BLITZ = 1300, + NEXUS_BLITZ = 1300, /// `1400`. /// Ultimate Spellbook games on Summoner's Rift SUMMONERS_RIFT_ULTIMATE_SPELLBOOK = 1400, diff --git a/riven/src/consts/route.rs b/riven/src/consts/route.rs index e7b9dd5..ce121c7 100644 --- a/riven/src/consts/route.rs +++ b/riven/src/consts/route.rs @@ -117,6 +117,7 @@ pub enum PlatformRoute { /// Philippines /// /// `32` (riotapi-schema ID/repr) + #[strum(to_string="PH2", serialize="PH")] PH2 = 32, /// Russia @@ -127,11 +128,13 @@ pub enum PlatformRoute { /// Singapore /// /// `33` (riotapi-schema ID/repr) + #[strum(to_string="SG2", serialize="SG")] SG2 = 33, /// Thailand /// /// `34` (riotapi-schema ID/repr) + #[strum(to_string="TH2", serialize="TH")] TH2 = 34, /// Turkey @@ -143,11 +146,13 @@ pub enum PlatformRoute { /// Taiwan /// /// `35` (riotapi-schema ID/repr) + #[strum(to_string="TW2", serialize="TW")] TW2 = 35, /// Vietnam /// /// `36` (riotapi-schema ID/repr) + #[strum(to_string="VN2", serialize="VN")] VN2 = 36, /// Public Beta Environment, special beta testing platform. Located in North America. @@ -209,7 +214,32 @@ impl PlatformRoute { } } - /// Used in LoL Tournament API. + /// 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 { + Self::BR1 => Some(TournamentRegion::BR), + Self::EUN1 => Some(TournamentRegion::EUNE), + Self::EUW1 => Some(TournamentRegion::EUW), + Self::JP1 => Some(TournamentRegion::JP), + Self::LA1 => Some(TournamentRegion::LAN), + Self::LA2 => Some(TournamentRegion::LAS), + Self::NA1 => Some(TournamentRegion::NA), + Self::OC1 => Some(TournamentRegion::OCE), + Self::TR1 => Some(TournamentRegion::TR), + Self::PBE1 => Some(TournamentRegion::PBE), + _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 { Self::BR1 => "BR", @@ -220,9 +250,14 @@ impl PlatformRoute { Self::LA2 => "LAS", Self::NA1 => "NA", Self::OC1 => "OCE", + Self::PH2 => "PH", + Self::SG2 => "SG", + Self::TH2 => "TH", Self::TR1 => "TR", + Self::TW2 => "TW", + Self::VN2 => "VN", Self::PBE1 => "PBE", - other => other.into() + other => other.into(), } } } @@ -272,3 +307,38 @@ pub enum ValPlatformRoute { ESPORTS = 95, } + +/// 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 { + /// Brazil. + BR = 16, + /// Europe, Northeast. + EUNE = 17, + /// Europe, West. + EUW = 18, + /// Japan. + JP = 19, + /// Latin America, North. + LAN = 21, + /// Latin America, South. + LAS = 22, + /// North America. + NA = 23, + /// Oceana. + OCE = 24, + /// Turkey + TR = 26, + /// Public Beta Environment, special beta testing platform. Located in North America. + PBE = 31, +} diff --git a/riven/src/consts/route_ext.rs b/riven/src/consts/route_ext.rs index f9391e1..b2da7f2 100644 --- a/riven/src/consts/route_ext.rs +++ b/riven/src/consts/route_ext.rs @@ -181,4 +181,12 @@ mod tests { assert_eq!(Ok(ValPlatformRoute::ESPORTS), "ESPORTS".parse()); assert!("SEA".parse::().is_err()); } + + #[test] + fn test_tournament_region_serde() { + use crate::consts::TournamentRegion; + let json = serde_json::to_string(&TournamentRegion::EUNE); + assert!(json.is_ok()); + assert_eq!("\"EUNE\"", &*json.unwrap()); + } } diff --git a/riven/src/endpoints.rs b/riven/src/endpoints.rs index 16222a5..a4a4bc6 100644 --- a/riven/src/endpoints.rs +++ b/riven/src/endpoints.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version a9b6936baced1f181b550b7fb921ab72b216076c +// Version d9133c31439c2d38263002fad5fa824f2ea0cb8b //! Automatically generated endpoint handles. #![allow(clippy::let_and_return, clippy::too_many_arguments)] diff --git a/riven/src/meta.rs b/riven/src/meta.rs index 12fc4ba..5e084cd 100644 --- a/riven/src/meta.rs +++ b/riven/src/meta.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version a9b6936baced1f181b550b7fb921ab72b216076c +// Version d9133c31439c2d38263002fad5fa824f2ea0cb8b //! Metadata about the Riot API and Riven. //! diff --git a/riven/src/models.rs b/riven/src/models.rs index 7ce613c..411f1fe 100644 --- a/riven/src/models.rs +++ b/riven/src/models.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version a9b6936baced1f181b550b7fb921ab72b216076c +// Version d9133c31439c2d38263002fad5fa824f2ea0cb8b #![allow(missing_docs)] @@ -2819,7 +2819,7 @@ pub mod tournament_stub_v4 { /// The region in which the provider will be running tournaments.
/// (Legal values: BR, EUNE, EUW, JP, LAN, LAS, NA, OCE, PBE, RU, TR) #[serde(rename = "region")] - pub region: String, + pub region: crate::consts::TournamentRegion, /// The provider's callback URL to which tournament game results in this region should be posted. The URL must be well-formed, use the http or https protocol, and use the default port for the protocol (http URLs must use port 80, https URLs must use port 443). #[serde(rename = "url")] pub url: String, @@ -2972,7 +2972,7 @@ pub mod tournament_v4 { /// The region in which the provider will be running tournaments.
/// (Legal values: BR, EUNE, EUW, JP, LAN, LAS, NA, OCE, PBE, RU, TR) #[serde(rename = "region")] - pub region: String, + pub region: crate::consts::TournamentRegion, /// The provider's callback URL to which tournament game results in this region should be posted. The URL must be well-formed, use the http or https protocol, and use the default port for the protocol (http URLs must use port 80, https URLs must use port 443). #[serde(rename = "url")] pub url: String, diff --git a/riven/srcgen/consts/route.rs.dt b/riven/srcgen/consts/route.rs.dt index 3d1a4b8..a567b6f 100644 --- a/riven/srcgen/consts/route.rs.dt +++ b/riven/srcgen/consts/route.rs.dt @@ -97,7 +97,30 @@ impl PlatformRoute { } } - /// Used in LoL Tournament API. + /// 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 { {{ @@ -108,7 +131,7 @@ impl PlatformRoute { {{ } }} - other => other.into() + other => other.into(), } } } @@ -140,3 +163,34 @@ pub enum ValPlatformRoute { } }} } + +/// 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 }}, +{{ + } + } +}} +}