From 11bf16e3d7e4405b5a26360827df4a07db28e322 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Thu, 7 Apr 2022 18:07:43 +0300 Subject: [PATCH] Make ItemSpec and Hands untagged --- .../test/loadout/ok/example_royal_guard.ron | 32 ++++++------ assets/test/loadout/ok/inherit_rings.ron | 16 +++--- assets/test/loadout/ok/just_all_entries.ron | 50 +++++++++---------- .../loadout/ok/just_butterfly_gliders.ron | 10 ++-- assets/test/loadout/ok/just_choice_hands.ron | 26 +++++----- assets/test/loadout/ok/just_crafted_rings.ron | 36 ++++++------- assets/test/loadout/ok/just_dragonscale.ron | 14 +++--- assets/test/loadout/ok/just_lanterns.ron | 16 +++--- assets/test/loadout/ok/just_ori_armor.ron | 14 +++--- assets/test/loadout/ok/just_rings.ron | 4 +- common/src/bin/asset_migrate.rs | 2 + common/src/comp/inventory/loadout_builder.rs | 10 +--- 12 files changed, 113 insertions(+), 117 deletions(-) diff --git a/assets/test/loadout/ok/example_royal_guard.ron b/assets/test/loadout/ok/example_royal_guard.ron index 40bcaa3239..ac9f94eae3 100644 --- a/assets/test/loadout/ok/example_royal_guard.ron +++ b/assets/test/loadout/ok/example_royal_guard.ron @@ -9,22 +9,22 @@ Asset("test.loadout.ok.just_butterfly_gliders"), Asset("test.loadout.ok.just_lanterns"), ]), - active_hands: Choice([ - (1, InHands(( - Item("common.items.weapons.sword.caladbolg"), + active_hands: [ + (1, ( + "common.items.weapons.sword.caladbolg", None, - ))), - (1, InHands(( - Item("common.items.weapons.bow.sagitta"), + )), + (1, ( + "common.items.weapons.bow.sagitta", None, - ))), - (1, InHands(( - Item("common.items.weapons.hammer_1h.orichalcum-0"), - Item("common.items.weapons.hammer_1h.orichalcum-0"), - ))), - (1, InHands(( - Item("common.items.weapons.axe_1h.orichalcum-0"), - Item("common.items.weapons.shield.shield_1"), - ))), - ]), + )), + (1, ( + "common.items.weapons.hammer_1h.orichalcum-0", + "common.items.weapons.hammer_1h.orichalcum-0", + )), + (1, ( + "common.items.weapons.axe_1h.orichalcum-0", + "common.items.weapons.shield.shield_1", + )), + ], ) diff --git a/assets/test/loadout/ok/inherit_rings.ron b/assets/test/loadout/ok/inherit_rings.ron index 46e8dd39d8..81b2507eb0 100644 --- a/assets/test/loadout/ok/inherit_rings.ron +++ b/assets/test/loadout/ok/inherit_rings.ron @@ -1,12 +1,12 @@ #![enable(implicit_some)] ( inherit: Asset("test.loadout.ok.just_rings"), - head: Item("common.items.armor.cultist.bandana"), - active_hands: InHands(( - Item("common.items.weapons.axe_1h.orichalcum-0"), - Choice([ - (1, Item("common.items.weapons.hammer_1h.orichalcum-0")), - (1, Item("common.items.weapons.axe_1h.orichalcum-0")), - ]), - )), + head: "common.items.armor.cultist.bandana", + active_hands: ( + "common.items.weapons.axe_1h.orichalcum-0", + [ + (1, "common.items.weapons.hammer_1h.orichalcum-0"), + (1, "common.items.weapons.axe_1h.orichalcum-0"), + ], + ), ) diff --git a/assets/test/loadout/ok/just_all_entries.ron b/assets/test/loadout/ok/just_all_entries.ron index a84bd7ac65..581a625eed 100644 --- a/assets/test/loadout/ok/just_all_entries.ron +++ b/assets/test/loadout/ok/just_all_entries.ron @@ -3,32 +3,32 @@ #![enable(implicit_some)] ( // Gear - head: Item("common.items.npc_armor.biped_small.myrmidon.head.hoplite"), - neck: Item("common.items.armor.misc.neck.gem_of_resilience"), - shoulders: Item("common.items.armor.twigsflowers.shoulder"), - chest: Item("common.items.armor.twigsflowers.chest"), - gloves: Item("common.items.armor.twigsflowers.hand"), - ring1: Item("common.items.armor.misc.ring.gold"), - ring2: Item("common.items.armor.misc.ring.gold"), - back: Item("common.items.armor.misc.back.dungeon_purple"), - belt: Item("common.items.armor.twigsflowers.belt"), - legs: Item("common.items.armor.twigsflowers.pants"), - feet: Item("common.items.armor.twigsflowers.foot"), - tabard: Item("common.items.debug.admin"), + head: "common.items.npc_armor.biped_small.myrmidon.head.hoplite", + neck: "common.items.armor.misc.neck.gem_of_resilience", + shoulders: "common.items.armor.twigsflowers.shoulder", + chest: "common.items.armor.twigsflowers.chest", + gloves: "common.items.armor.twigsflowers.hand", + ring1: "common.items.armor.misc.ring.gold", + ring2: "common.items.armor.misc.ring.gold", + back: "common.items.armor.misc.back.dungeon_purple", + belt: "common.items.armor.twigsflowers.belt", + legs: "common.items.armor.twigsflowers.pants", + feet: "common.items.armor.twigsflowers.foot", + tabard: "common.items.debug.admin", // Misc - bag1: Item("common.items.armor.misc.bag.tiny_leather_pouch"), - bag2: Item("common.items.armor.misc.bag.tiny_leather_pouch"), - bag3: Item("common.items.armor.misc.bag.tiny_leather_pouch"), - bag4: Item("common.items.armor.misc.bag.tiny_leather_pouch"), - lantern: Item("common.items.lantern.black_0"), - glider: Item("common.items.glider.basic_red"), + bag1: "common.items.armor.misc.bag.tiny_leather_pouch", + bag2: "common.items.armor.misc.bag.tiny_leather_pouch", + bag3: "common.items.armor.misc.bag.tiny_leather_pouch", + bag4: "common.items.armor.misc.bag.tiny_leather_pouch", + lantern: "common.items.lantern.black_0", + glider: "common.items.glider.basic_red", // Weapons - active_hands: InHands(( - Item("common.items.weapons.sword_1h.bloodsteel-0"), - Item("common.items.weapons.sword_1h.bloodsteel-0"), - )), - inactive_hands: InHands(( - Item("common.items.weapons.sceptre.sceptre_velorite_0"), + active_hands: ( + "common.items.weapons.sword_1h.bloodsteel-0", + "common.items.weapons.sword_1h.bloodsteel-0", + ), + inactive_hands: ( + "common.items.weapons.sceptre.sceptre_velorite_0", None, - )), + ), ) diff --git a/assets/test/loadout/ok/just_butterfly_gliders.ron b/assets/test/loadout/ok/just_butterfly_gliders.ron index e681886b98..75ca907493 100644 --- a/assets/test/loadout/ok/just_butterfly_gliders.ron +++ b/assets/test/loadout/ok/just_butterfly_gliders.ron @@ -1,8 +1,8 @@ #![enable(implicit_some)] ( - glider: Choice([ - (1, Item("common.items.glider.moth")), - (1, Item("common.items.glider.morpho")), - (1, Item("common.items.glider.monarch")), - ]), + glider: [ + (1, "common.items.glider.moth"), + (1, "common.items.glider.morpho"), + (1, "common.items.glider.monarch"), + ], ) diff --git a/assets/test/loadout/ok/just_choice_hands.ron b/assets/test/loadout/ok/just_choice_hands.ron index 298dc6f503..88301cb552 100644 --- a/assets/test/loadout/ok/just_choice_hands.ron +++ b/assets/test/loadout/ok/just_choice_hands.ron @@ -1,17 +1,17 @@ #![enable(implicit_some)] ( - active_hands: Choice([ - (1, InHands(( - Item("common.items.weapons.axe_1h.orichalcum-0"), - Item("common.items.weapons.axe_1h.orichalcum-0"), - ))), - (1, InHands(( - Item("common.items.weapons.hammer_1h.orichalcum-0"), - Item("common.items.weapons.axe_1h.orichalcum-0"), - ))), - (1, InHands(( - Item("common.items.weapons.sword.cultist"), + active_hands: [ + (1, ( + "common.items.weapons.axe_1h.orichalcum-0", + "common.items.weapons.axe_1h.orichalcum-0", + )), + (1, ( + "common.items.weapons.hammer_1h.orichalcum-0", + "common.items.weapons.axe_1h.orichalcum-0", + )), + (1, ( + "common.items.weapons.sword.cultist", None, - ))), - ]), + )), + ], ) diff --git a/assets/test/loadout/ok/just_crafted_rings.ron b/assets/test/loadout/ok/just_crafted_rings.ron index 1e487fbfa5..add0c24a57 100644 --- a/assets/test/loadout/ok/just_crafted_rings.ron +++ b/assets/test/loadout/ok/just_crafted_rings.ron @@ -1,21 +1,21 @@ #![enable(implicit_some)] ( - ring1: Choice([ - (1, Item("common.items.armor.misc.ring.amethyst")), - (1, Item("common.items.armor.misc.ring.diamond")), - (1, Item("common.items.armor.misc.ring.emerald")), - (1, Item("common.items.armor.misc.ring.gold")), - (1, Item("common.items.armor.misc.ring.ruby")), - (1, Item("common.items.armor.misc.ring.sapphire")), - (1, Item("common.items.armor.misc.ring.topaz")), - ]), - ring2: Choice([ - (1, Item("common.items.armor.misc.ring.amethyst")), - (1, Item("common.items.armor.misc.ring.diamond")), - (1, Item("common.items.armor.misc.ring.emerald")), - (1, Item("common.items.armor.misc.ring.gold")), - (1, Item("common.items.armor.misc.ring.ruby")), - (1, Item("common.items.armor.misc.ring.sapphire")), - (1, Item("common.items.armor.misc.ring.topaz")), - ]), + ring1: [ + (1, "common.items.armor.misc.ring.amethyst"), + (1, "common.items.armor.misc.ring.diamond"), + (1, "common.items.armor.misc.ring.emerald"), + (1, "common.items.armor.misc.ring.gold"), + (1, "common.items.armor.misc.ring.ruby"), + (1, "common.items.armor.misc.ring.sapphire"), + (1, "common.items.armor.misc.ring.topaz"), + ], + ring2: [ + (1, "common.items.armor.misc.ring.amethyst"), + (1, "common.items.armor.misc.ring.diamond"), + (1, "common.items.armor.misc.ring.emerald"), + (1, "common.items.armor.misc.ring.gold"), + (1, "common.items.armor.misc.ring.ruby"), + (1, "common.items.armor.misc.ring.sapphire"), + (1, "common.items.armor.misc.ring.topaz"), + ], ) diff --git a/assets/test/loadout/ok/just_dragonscale.ron b/assets/test/loadout/ok/just_dragonscale.ron index 112aa79bb6..d622f6cce4 100644 --- a/assets/test/loadout/ok/just_dragonscale.ron +++ b/assets/test/loadout/ok/just_dragonscale.ron @@ -1,10 +1,10 @@ #![enable(implicit_some)] ( - shoulders: Item("common.items.armor.hide.dragonscale.shoulder"), - chest: Item("common.items.armor.hide.dragonscale.chest"), - gloves: Item("common.items.armor.hide.dragonscale.hand"), - back: Item("common.items.armor.hide.dragonscale.back"), - belt: Item("common.items.armor.hide.dragonscale.belt"), - legs: Item("common.items.armor.hide.dragonscale.pants"), - feet: Item("common.items.armor.hide.dragonscale.foot"), + shoulders: "common.items.armor.hide.dragonscale.shoulder", + chest: "common.items.armor.hide.dragonscale.chest", + gloves: "common.items.armor.hide.dragonscale.hand", + back: "common.items.armor.hide.dragonscale.back", + belt: "common.items.armor.hide.dragonscale.belt", + legs: "common.items.armor.hide.dragonscale.pants", + feet: "common.items.armor.hide.dragonscale.foot", ) diff --git a/assets/test/loadout/ok/just_lanterns.ron b/assets/test/loadout/ok/just_lanterns.ron index 178c9fa164..83284ba47e 100644 --- a/assets/test/loadout/ok/just_lanterns.ron +++ b/assets/test/loadout/ok/just_lanterns.ron @@ -1,11 +1,11 @@ #![enable(implicit_some)] ( - lantern: Choice([ - (1, Item("common.items.lantern.black_0")), - (1, Item("common.items.lantern.blue_0")), - (1, Item("common.items.lantern.green_0")), - (1, Item("common.items.lantern.red_0")), - (1, Item("common.items.lantern.geode_purp")), - (1, Item("common.items.boss_drops.lantern")), - ]), + lantern: [ + (1, "common.items.lantern.black_0"), + (1, "common.items.lantern.blue_0"), + (1, "common.items.lantern.green_0"), + (1, "common.items.lantern.red_0"), + (1, "common.items.lantern.geode_purp"), + (1, "common.items.boss_drops.lantern"), + ], ) diff --git a/assets/test/loadout/ok/just_ori_armor.ron b/assets/test/loadout/ok/just_ori_armor.ron index 8e86ac4939..71e88350ec 100644 --- a/assets/test/loadout/ok/just_ori_armor.ron +++ b/assets/test/loadout/ok/just_ori_armor.ron @@ -1,10 +1,10 @@ #![enable(implicit_some)] ( - shoulders: Item("common.items.armor.mail.orichalcum.shoulder"), - chest: Item("common.items.armor.mail.orichalcum.chest"), - gloves: Item("common.items.armor.mail.orichalcum.hand"), - back: Item("common.items.armor.mail.orichalcum.back"), - belt: Item("common.items.armor.mail.orichalcum.belt"), - legs: Item("common.items.armor.mail.orichalcum.pants"), - feet: Item("common.items.armor.mail.orichalcum.foot"), + shoulders: "common.items.armor.mail.orichalcum.shoulder", + chest: "common.items.armor.mail.orichalcum.chest", + gloves: "common.items.armor.mail.orichalcum.hand", + back: "common.items.armor.mail.orichalcum.back", + belt: "common.items.armor.mail.orichalcum.belt", + legs: "common.items.armor.mail.orichalcum.pants", + feet: "common.items.armor.mail.orichalcum.foot", ) diff --git a/assets/test/loadout/ok/just_rings.ron b/assets/test/loadout/ok/just_rings.ron index 701d83d9e2..9b09a2d10c 100644 --- a/assets/test/loadout/ok/just_rings.ron +++ b/assets/test/loadout/ok/just_rings.ron @@ -1,5 +1,5 @@ #![enable(implicit_some)] ( - ring1: Item("common.items.armor.cultist.ring"), - ring2: Item("common.items.armor.cultist.ring"), + ring1: "common.items.armor.cultist.ring", + ring2: "common.items.armor.cultist.ring", ) diff --git a/common/src/bin/asset_migrate.rs b/common/src/bin/asset_migrate.rs index c3635198aa..d77febb90b 100644 --- a/common/src/bin/asset_migrate.rs +++ b/common/src/bin/asset_migrate.rs @@ -56,12 +56,14 @@ mod loadout_v2 { } #[derive(Debug, Deserialize, Serialize, Clone)] + #[serde(untagged)] pub enum ItemSpecNew { Item(String), Choice(Vec<(Weight, Option)>), } #[derive(Debug, Deserialize, Serialize, Clone)] + #[serde(untagged)] pub enum Hands { /// Allows to specify one pair // TODO: add link to tests with example diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index 9885b5de8b..7738712863 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -36,15 +36,8 @@ pub enum ValidationError { Loop(Vec), } -// TODO: serde un-tag? -// -// -// Pros: -// + less noise -// -// Cons: -// - limits us to using different types for each variant #[derive(Debug, Deserialize, Clone)] +#[serde(untagged)] enum ItemSpec { Item(String), Choice(Vec<(Weight, Option)>), @@ -93,6 +86,7 @@ impl ItemSpec { } #[derive(Debug, Deserialize, Clone)] +#[serde(untagged)] enum Hands { /// Allows to specify one pair // TODO: add link to tests with example