From 885bb9aaa7bb5f749f21af0c4bc6262afea9dc34 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 31 Jul 2021 19:33:42 -0500 Subject: [PATCH] Added programmatic names for modular components. --- .../crafting_ing/modular/damage/axe/axe.ron | 2 +- .../modular/damage/axe/battleaxe.ron | 2 +- .../modular/damage/axe/greataxe.ron | 2 +- .../modular/damage/axe/jagged.ron | 2 +- .../modular/damage/axe/labrys.ron | 2 +- .../modular/damage/axe/ornate.ron | 2 +- .../modular/damage/axe/poleaxe.ron | 2 +- .../modular/damage/hammer/greathammer.ron | 2 +- .../modular/damage/hammer/greatmace.ron | 2 +- .../modular/damage/hammer/hammer.ron | 2 +- .../modular/damage/hammer/maul.ron | 2 +- .../modular/damage/hammer/ornate.ron | 2 +- .../modular/damage/hammer/spikedmace.ron | 2 +- .../modular/damage/hammer/warhammer.ron | 2 +- .../modular/damage/sword/greatsword.ron | 2 +- .../modular/damage/sword/katana.ron | 2 +- .../modular/damage/sword/longsword.ron | 2 +- .../modular/damage/sword/ornate.ron | 2 +- .../modular/damage/sword/sabre.ron | 2 +- .../modular/damage/sword/sawblade.ron | 2 +- .../modular/damage/sword/zweihander.ron | 2 +- .../crafting_ing/modular/held/axe/long.ron | 2 +- .../crafting_ing/modular/held/axe/medium.ron | 2 +- .../crafting_ing/modular/held/axe/short.ron | 2 +- .../crafting_ing/modular/held/hammer/long.ron | 2 +- .../modular/held/hammer/medium.ron | 2 +- .../modular/held/hammer/short.ron | 2 +- .../modular/held/sword/hand-and-half.ron | 2 +- .../modular/held/sword/one-handed.ron | 2 +- .../modular/held/sword/two-handed.ron | 2 +- common/src/comp/inventory/item/mod.rs | 6 +- common/src/comp/inventory/item/modular.rs | 92 ++++++++++++------- 32 files changed, 94 insertions(+), 64 deletions(-) diff --git a/assets/common/items/crafting_ing/modular/damage/axe/axe.ron b/assets/common/items/crafting_ing/modular/damage/axe/axe.ron index 042ef05e08..53920fcae0 100644 --- a/assets/common/items/crafting_ing/modular/damage/axe/axe.ron +++ b/assets/common/items/crafting_ing/modular/damage/axe/axe.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Axe head"), + name: Component("Axe Head"), description: "An axe head made of metal.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/damage/axe/battleaxe.ron b/assets/common/items/crafting_ing/modular/damage/axe/battleaxe.ron index 70d04b7355..fb2ab5a3d9 100644 --- a/assets/common/items/crafting_ing/modular/damage/axe/battleaxe.ron +++ b/assets/common/items/crafting_ing/modular/damage/axe/battleaxe.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Battleaxe head"), + name: Component("Battleaxe Head"), description: "An axe head made of metal.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/damage/axe/greataxe.ron b/assets/common/items/crafting_ing/modular/damage/axe/greataxe.ron index 920d82ca20..4645c7c396 100644 --- a/assets/common/items/crafting_ing/modular/damage/axe/greataxe.ron +++ b/assets/common/items/crafting_ing/modular/damage/axe/greataxe.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Greataxe Head"), + name: Component("Greataxe Head"), description: "An axe head made of metal.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/damage/axe/jagged.ron b/assets/common/items/crafting_ing/modular/damage/axe/jagged.ron index 4a6292279f..e33a973a42 100644 --- a/assets/common/items/crafting_ing/modular/damage/axe/jagged.ron +++ b/assets/common/items/crafting_ing/modular/damage/axe/jagged.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Jagged axe head"), + name: Component("Jagged Axe Head"), description: "An axe head made of metal.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/damage/axe/labrys.ron b/assets/common/items/crafting_ing/modular/damage/axe/labrys.ron index 696384a218..a754144cdb 100644 --- a/assets/common/items/crafting_ing/modular/damage/axe/labrys.ron +++ b/assets/common/items/crafting_ing/modular/damage/axe/labrys.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Great mace head"), + name: Component("Great Mace Head"), description: "A hamemr head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/axe/ornate.ron b/assets/common/items/crafting_ing/modular/damage/axe/ornate.ron index 0d1aac043b..00464111ac 100644 --- a/assets/common/items/crafting_ing/modular/damage/axe/ornate.ron +++ b/assets/common/items/crafting_ing/modular/damage/axe/ornate.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Ornate axe head"), + name: Component("Ornate Axe Head"), description: "An axe head made of metal.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/damage/axe/poleaxe.ron b/assets/common/items/crafting_ing/modular/damage/axe/poleaxe.ron index d2568c9b66..bd9e8ca9b1 100644 --- a/assets/common/items/crafting_ing/modular/damage/axe/poleaxe.ron +++ b/assets/common/items/crafting_ing/modular/damage/axe/poleaxe.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Poleaxe head"), + name: Component("Poleaxe Head"), description: "An axe head made of metal.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/damage/hammer/greathammer.ron b/assets/common/items/crafting_ing/modular/damage/hammer/greathammer.ron index 5a8512dc1f..8e23e5f915 100644 --- a/assets/common/items/crafting_ing/modular/damage/hammer/greathammer.ron +++ b/assets/common/items/crafting_ing/modular/damage/hammer/greathammer.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Greathammer Head"), + name: Component("Greathammer Head"), description: "A hammer head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/hammer/greatmace.ron b/assets/common/items/crafting_ing/modular/damage/hammer/greatmace.ron index 696384a218..a754144cdb 100644 --- a/assets/common/items/crafting_ing/modular/damage/hammer/greatmace.ron +++ b/assets/common/items/crafting_ing/modular/damage/hammer/greatmace.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Great mace head"), + name: Component("Great Mace Head"), description: "A hamemr head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/hammer/hammer.ron b/assets/common/items/crafting_ing/modular/damage/hammer/hammer.ron index 63a0786b35..879ae1fa86 100644 --- a/assets/common/items/crafting_ing/modular/damage/hammer/hammer.ron +++ b/assets/common/items/crafting_ing/modular/damage/hammer/hammer.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Hammer head"), + name: Component("Hammer Head"), description: "A hammer head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/hammer/maul.ron b/assets/common/items/crafting_ing/modular/damage/hammer/maul.ron index e57593d4cb..465275a2bd 100644 --- a/assets/common/items/crafting_ing/modular/damage/hammer/maul.ron +++ b/assets/common/items/crafting_ing/modular/damage/hammer/maul.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Maul head"), + name: Component("Maul Head"), description: "A hammer head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/hammer/ornate.ron b/assets/common/items/crafting_ing/modular/damage/hammer/ornate.ron index 12548d7067..22e540d42a 100644 --- a/assets/common/items/crafting_ing/modular/damage/hammer/ornate.ron +++ b/assets/common/items/crafting_ing/modular/damage/hammer/ornate.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Ornate hammer head"), + name: Component("Ornate Hammer Head"), description: "A hammer head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/hammer/spikedmace.ron b/assets/common/items/crafting_ing/modular/damage/hammer/spikedmace.ron index aa7999d290..de1f016533 100644 --- a/assets/common/items/crafting_ing/modular/damage/hammer/spikedmace.ron +++ b/assets/common/items/crafting_ing/modular/damage/hammer/spikedmace.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Spiked mace head"), + name: Component("Spiked Mace Head"), description: "A hammer head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/hammer/warhammer.ron b/assets/common/items/crafting_ing/modular/damage/hammer/warhammer.ron index a81f62ae7e..96c7a266da 100644 --- a/assets/common/items/crafting_ing/modular/damage/hammer/warhammer.ron +++ b/assets/common/items/crafting_ing/modular/damage/hammer/warhammer.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Warhammer head"), + name: Component("Warhammer Head"), description: "A hammer head made of metal.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/damage/sword/greatsword.ron b/assets/common/items/crafting_ing/modular/damage/sword/greatsword.ron index 3703ac85ce..061f8b90d3 100644 --- a/assets/common/items/crafting_ing/modular/damage/sword/greatsword.ron +++ b/assets/common/items/crafting_ing/modular/damage/sword/greatsword.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Greatsword blade"), + name: Component("Greatsword Blade"), description: "A sword blade made of metal.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/damage/sword/katana.ron b/assets/common/items/crafting_ing/modular/damage/sword/katana.ron index 81a6772bf1..3c21fd9f4b 100644 --- a/assets/common/items/crafting_ing/modular/damage/sword/katana.ron +++ b/assets/common/items/crafting_ing/modular/damage/sword/katana.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Katana blade"), + name: Component("Katana Blade"), description: "A sword blade made of metal.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/damage/sword/longsword.ron b/assets/common/items/crafting_ing/modular/damage/sword/longsword.ron index 41fe0aee54..27d8fa659f 100644 --- a/assets/common/items/crafting_ing/modular/damage/sword/longsword.ron +++ b/assets/common/items/crafting_ing/modular/damage/sword/longsword.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Longsword blade"), + name: Component("Longsword Blade"), description: "A sword blade made of metal.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/damage/sword/ornate.ron b/assets/common/items/crafting_ing/modular/damage/sword/ornate.ron index e4c1b0774d..1215934428 100644 --- a/assets/common/items/crafting_ing/modular/damage/sword/ornate.ron +++ b/assets/common/items/crafting_ing/modular/damage/sword/ornate.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Ornate sword blade"), + name: Component("Ornate Sword Blade"), description: "A sword blade made of metal.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/damage/sword/sabre.ron b/assets/common/items/crafting_ing/modular/damage/sword/sabre.ron index 02a5b636bb..96405a2651 100644 --- a/assets/common/items/crafting_ing/modular/damage/sword/sabre.ron +++ b/assets/common/items/crafting_ing/modular/damage/sword/sabre.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Sabre blade"), + name: Component("Sabre Blade"), description: "A sword blade made of metal.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/damage/sword/sawblade.ron b/assets/common/items/crafting_ing/modular/damage/sword/sawblade.ron index 44580aea39..556bfacd7f 100644 --- a/assets/common/items/crafting_ing/modular/damage/sword/sawblade.ron +++ b/assets/common/items/crafting_ing/modular/damage/sword/sawblade.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Sword sawblade"), + name: Component("Sawblade"), description: "A sword blade made of metal.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/damage/sword/zweihander.ron b/assets/common/items/crafting_ing/modular/damage/sword/zweihander.ron index 18919e728e..bfdfbc238d 100644 --- a/assets/common/items/crafting_ing/modular/damage/sword/zweihander.ron +++ b/assets/common/items/crafting_ing/modular/damage/sword/zweihander.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Zweihander blade"), + name: Component("Zweihander Blade"), description: "A sword blade made of metal.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/held/axe/long.ron b/assets/common/items/crafting_ing/modular/held/axe/long.ron index 37d6ce5850..333ab46849 100644 --- a/assets/common/items/crafting_ing/modular/held/axe/long.ron +++ b/assets/common/items/crafting_ing/modular/held/axe/long.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Long axe haft"), + name: Component("Long Axe Haft"), description: "A axe haft.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/held/axe/medium.ron b/assets/common/items/crafting_ing/modular/held/axe/medium.ron index c76c39be65..dd2189b76d 100644 --- a/assets/common/items/crafting_ing/modular/held/axe/medium.ron +++ b/assets/common/items/crafting_ing/modular/held/axe/medium.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Medium axe haft"), + name: Component("Medium Axe Haft"), description: "A axe half.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/held/axe/short.ron b/assets/common/items/crafting_ing/modular/held/axe/short.ron index bf90604f3c..d695be1dd1 100644 --- a/assets/common/items/crafting_ing/modular/held/axe/short.ron +++ b/assets/common/items/crafting_ing/modular/held/axe/short.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Short axe haft"), + name: Component("Short Axe Haft"), description: "A axe haft.", kind: ModularComponent(( toolkind: Axe, diff --git a/assets/common/items/crafting_ing/modular/held/hammer/long.ron b/assets/common/items/crafting_ing/modular/held/hammer/long.ron index f4e9939ff0..6c59a4f58a 100644 --- a/assets/common/items/crafting_ing/modular/held/hammer/long.ron +++ b/assets/common/items/crafting_ing/modular/held/hammer/long.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Long hammer haft"), + name: Component("Long Hammer Haft"), description: "A hammer haft.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/held/hammer/medium.ron b/assets/common/items/crafting_ing/modular/held/hammer/medium.ron index 530c91ca55..809048ed5c 100644 --- a/assets/common/items/crafting_ing/modular/held/hammer/medium.ron +++ b/assets/common/items/crafting_ing/modular/held/hammer/medium.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Medium hammer haft"), + name: Component("Medium Hammer Haft"), description: "A hammer half.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/held/hammer/short.ron b/assets/common/items/crafting_ing/modular/held/hammer/short.ron index 7aee643049..37cd182491 100644 --- a/assets/common/items/crafting_ing/modular/held/hammer/short.ron +++ b/assets/common/items/crafting_ing/modular/held/hammer/short.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Short hammer haft"), + name: Component("Short Hammer Haft"), description: "A hammer haft.", kind: ModularComponent(( toolkind: Hammer, diff --git a/assets/common/items/crafting_ing/modular/held/sword/hand-and-half.ron b/assets/common/items/crafting_ing/modular/held/sword/hand-and-half.ron index 96c3a8816a..0c012dcbe8 100644 --- a/assets/common/items/crafting_ing/modular/held/sword/hand-and-half.ron +++ b/assets/common/items/crafting_ing/modular/held/sword/hand-and-half.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Hand-and-a-half sword hilt"), + name: Component("Hand-and-a-Half Sword Hilt"), description: "A sword hilt.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/held/sword/one-handed.ron b/assets/common/items/crafting_ing/modular/held/sword/one-handed.ron index 4e1e27a5b0..8dfbcbedff 100644 --- a/assets/common/items/crafting_ing/modular/held/sword/one-handed.ron +++ b/assets/common/items/crafting_ing/modular/held/sword/one-handed.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("One-handed sword hilt"), + name: Component("One-Handed Sword Hilt"), description: "A sword hilt.", kind: ModularComponent(( toolkind: Sword, diff --git a/assets/common/items/crafting_ing/modular/held/sword/two-handed.ron b/assets/common/items/crafting_ing/modular/held/sword/two-handed.ron index 0460833cf9..e9b9964492 100644 --- a/assets/common/items/crafting_ing/modular/held/sword/two-handed.ron +++ b/assets/common/items/crafting_ing/modular/held/sword/two-handed.ron @@ -1,5 +1,5 @@ ItemDef( - name: Direct("Two-handed sword hilt"), + name: Component("Two-Handed Sword Hilt"), description: "A sword hilt.", kind: ModularComponent(( toolkind: Sword, diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index a234be72cc..19f1fe4651 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -426,6 +426,7 @@ where pub enum ItemName { Direct(String), Modular, + Component(String), } #[derive(Debug, Serialize, Deserialize)] @@ -869,7 +870,8 @@ impl Item { pub fn name(&self) -> Cow<'_, str> { match &self.item_def.name { ItemName::Direct(name) => Cow::Borrowed(name), - ItemName::Modular => modular::modular_name(self), + ItemName::Modular => modular::modular_name(self, ""), + ItemName::Component(name) => modular::modular_name(self, name), } } @@ -970,7 +972,7 @@ impl ItemDesc for ItemDef { fn name(&self) -> Cow<'_, str> { match &self.name { - ItemName::Direct(name) => Cow::Borrowed(name), + ItemName::Direct(name) | ItemName::Component(name) => Cow::Borrowed(name), ItemName::Modular => { let toolkind = if let ItemKind::Tool(tool) = &self.kind { tool.kind.identifier_name() diff --git a/common/src/comp/inventory/item/modular.rs b/common/src/comp/inventory/item/modular.rs index ed707f8878..c503401147 100644 --- a/common/src/comp/inventory/item/modular.rs +++ b/common/src/comp/inventory/item/modular.rs @@ -265,40 +265,68 @@ pub(super) fn synthesize_modular_asset(specifier: &str) -> Option { /// Modular weapons are named as "{Material} {Weapon}" where {Weapon} is from /// the damage component used and {Material} is from the material the damage /// component is created from. -pub(super) fn modular_name(item: &Item) -> Cow<'_, str> { - let damage_components = item.components().iter().filter(|comp| { - matches!(comp.kind(), ItemKind::ModularComponent(ModularComponent { modkind, .. }) - if matches!(modkind, ModularComponentKind::Damage) - ) - }); - // Last fine as there should only ever be one damage component on a weapon - let (material_name, weapon_name) = if let Some(component) = damage_components.last() { - let materials = component - .components() - .iter() - .filter_map(|comp| match comp.kind() { - ItemKind::Ingredient { .. } => Some(comp.kind()), - _ => None, +pub(super) fn modular_name<'a>(item: &'a Item, arg1: &'a str) -> Cow<'a, str> { + match item.kind() { + ItemKind::Tool(tool) => { + let damage_components = item.components().iter().filter(|comp| { + matches!(comp.kind(), ItemKind::ModularComponent(ModularComponent { modkind, .. }) + if matches!(modkind, ModularComponentKind::Damage) + ) }); - // TODO: Better handle multiple materials - let material_name = if let Some(ItemKind::Ingredient { descriptor, .. }) = materials.last() - { - descriptor - } else { - "Modular" - }; - let weapon_name = - if let ItemKind::ModularComponent(ModularComponent { weapon_name, .. }) = - component.kind() - { - weapon_name + // Last fine as there should only ever be one damage component on a weapon + let (material_name, weapon_name) = if let Some(component) = damage_components.last() { + let materials = + component + .components() + .iter() + .filter_map(|comp| match comp.kind() { + ItemKind::Ingredient { .. } => Some(comp.kind()), + _ => None, + }); + // TODO: Better handle multiple materials + let material_name = + if let Some(ItemKind::Ingredient { descriptor, .. }) = materials.last() { + descriptor + } else { + "Modular" + }; + let weapon_name = + if let ItemKind::ModularComponent(ModularComponent { weapon_name, .. }) = + component.kind() + { + weapon_name + } else { + tool.kind.identifier_name() + }; + (material_name, weapon_name) } else { - "Weapon" + ("Modular", tool.kind.identifier_name()) }; - (material_name, weapon_name) - } else { - ("Modular", "Weapon") - }; - Cow::Owned(format!("{} {}", material_name, weapon_name)) + Cow::Owned(format!("{} {}", material_name, weapon_name)) + }, + ItemKind::ModularComponent(comp) => { + match comp.modkind { + ModularComponentKind::Damage => { + let materials = item + .components() + .iter() + .filter_map(|comp| match comp.kind() { + ItemKind::Ingredient { .. } => Some(comp.kind()), + _ => None, + }); + // TODO: Better handle multiple materials + let material_name = + if let Some(ItemKind::Ingredient { descriptor, .. }) = materials.last() { + descriptor + } else { + "Modular" + }; + Cow::Owned(format!("{} {}", material_name, arg1)) + }, + ModularComponentKind::Held => Cow::Borrowed(arg1), + } + }, + _ => Cow::Borrowed("Modular Item"), + } }