forked from mirror/Riven
1
0
Fork 0

Convert Map from enum into newtype_enum

users/mingwei/unknown-variant-messy
Mingwei Samuel 2021-06-30 19:40:48 -07:00
parent 88124ecb3a
commit 2d80f97170
3 changed files with 62 additions and 68 deletions

View File

@ -64,7 +64,7 @@ macro_rules! newtype_enum {
} => { } => {
$( #[$attr] )* $( #[$attr] )*
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(Hash, PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)] #[repr(transparent)]
$v struct $name($v $repr); $v struct $name($v $repr);
impl $name { impl $name {

View File

@ -6,60 +6,57 @@
// // // //
/////////////////////////////////////////////// ///////////////////////////////////////////////
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde::{ Serialize, Deserialize };
use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends maps. newtype_enum! {
#[non_exhaustive] /// A League of Legends map.
#[derive(Debug, Copy, Clone)] #[derive(Serialize, Deserialize)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[serde(transparent)]
#[derive(Serialize_repr, Deserialize_repr)] pub newtype_enum Map(u8) {
#[derive(IntoPrimitive, TryFromPrimitive)] /// Summoner's Rift
#[repr(u8)] /// Original Summer variant
pub enum Map { SUMMONERS_RIFT_ORIGINAL_SUMMER_VARIANT = 1,
/// Summoner's Rift /// Summoner's Rift
/// Original Summer variant /// Original Autumn variant
SUMMONERS_RIFT_ORIGINAL_SUMMER_VARIANT = 1, SUMMONERS_RIFT_ORIGINAL_AUTUMN_VARIANT = 2,
/// Summoner's Rift /// The Proving Grounds
/// Original Autumn variant /// Tutorial Map
SUMMONERS_RIFT_ORIGINAL_AUTUMN_VARIANT = 2, THE_PROVING_GROUNDS = 3,
/// The Proving Grounds /// Twisted Treeline
/// Tutorial Map /// Original Version
THE_PROVING_GROUNDS = 3, TWISTED_TREELINE_ORIGINAL_VERSION = 4,
/// Twisted Treeline /// The Crystal Scar
/// Original Version /// Dominion map
TWISTED_TREELINE_ORIGINAL_VERSION = 4, THE_CRYSTAL_SCAR = 8,
/// The Crystal Scar /// Twisted Treeline
/// Dominion map /// Last TT map
THE_CRYSTAL_SCAR = 8, TWISTED_TREELINE = 10,
/// Twisted Treeline /// Summoner's Rift
/// Last TT map /// Current Version
TWISTED_TREELINE = 10, SUMMONERS_RIFT = 11,
/// Summoner's Rift /// Howling Abyss
/// Current Version /// ARAM map
SUMMONERS_RIFT = 11, HOWLING_ABYSS = 12,
/// Howling Abyss /// Butcher's Bridge
/// ARAM map /// Alternate ARAM map
HOWLING_ABYSS = 12, BUTCHERS_BRIDGE = 14,
/// Butcher's Bridge /// Cosmic Ruins
/// Alternate ARAM map /// Dark Star: Singularity map
BUTCHERS_BRIDGE = 14, COSMIC_RUINS = 16,
/// Cosmic Ruins /// Valoran City Park
/// Dark Star: Singularity map /// Star Guardian Invasion map
COSMIC_RUINS = 16, VALORAN_CITY_PARK = 18,
/// Valoran City Park /// Substructure 43
/// Star Guardian Invasion map /// PROJECT: Hunters map
VALORAN_CITY_PARK = 18, SUBSTRUCTURE_43 = 19,
/// Substructure 43 /// Crash Site
/// PROJECT: Hunters map /// Odyssey: Extraction map
SUBSTRUCTURE_43 = 19, CRASH_SITE = 20,
/// Crash Site /// Nexus Blitz
/// Odyssey: Extraction map /// Nexus Blitz map
CRASH_SITE = 20, NEXUS_BLITZ = 21,
/// Nexus Blitz /// Convergence
/// Nexus Blitz map /// Teamfight Tactics map
NEXUS_BLITZ = 21, CONVERGENCE = 22,
/// Convergence }
/// Teamfight Tactics map
CONVERGENCE = 22,
} }

View File

@ -3,26 +3,23 @@
const maps = require('./.maps.json'); const maps = require('./.maps.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde::{ Serialize, Deserialize };
use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// League of Legends maps. newtype_enum! {
#[non_exhaustive] /// A League of Legends map.
#[derive(Debug, Copy, Clone)] #[derive(Serialize, Deserialize)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[serde(transparent)]
#[derive(Serialize_repr, Deserialize_repr)] pub newtype_enum Map(u8) {
#[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)]
pub enum Map {
{{ {{
for (const e of maps) { for (const e of maps) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}} }}
{{~ desc :line }} {{~ desc :line }}
/// {{= line }} /// {{= line }}
{{~}} {{~}}
{{= e['x-name'] }} = {{= e['x-value'] }}, {{= e['x-name'] }} = {{= e['x-value'] }},
{{ {{
} }
}} }}
}
} }