Modular weapons can now be properly displayed in the inventory.

This commit is contained in:
Sam 2021-08-07 16:11:27 -04:00
parent 105bb24631
commit 0a38567e8d
32 changed files with 96 additions and 55 deletions

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Lifecloth", descriptor: "Lifecloth",
), ),
quality: Direct(High), quality: Direct(High),
tags: [MaterialKind(Cloth)], tags: [MaterialKind(Cloth), Material(Lifecloth)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Linen", descriptor: "Linen",
), ),
quality: Direct(Low), quality: Direct(Low),
tags: [MaterialKind(Cloth)], tags: [MaterialKind(Cloth), Material(Linen)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Moonwoven", descriptor: "Moonwoven",
), ),
quality: Direct(Epic), quality: Direct(Epic),
tags: [MaterialKind(Cloth)], tags: [MaterialKind(Cloth), Material(Moonweave)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Silken", descriptor: "Silken",
), ),
quality: Direct(Moderate), quality: Direct(Moderate),
tags: [MaterialKind(Cloth)], tags: [MaterialKind(Cloth), Material(Silk)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Sunsilken", descriptor: "Sunsilken",
), ),
quality: Direct(Legendary), quality: Direct(Legendary),
tags: [MaterialKind(Cloth)], tags: [MaterialKind(Cloth), Material(Sunsilk)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Woolen", descriptor: "Woolen",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [MaterialKind(Cloth)], tags: [MaterialKind(Cloth), Material(Wool)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Carapace", descriptor: "Carapace",
), ),
quality: Direct(High), quality: Direct(High),
tags: [MaterialKind(Hide)], tags: [MaterialKind(Hide), Material(Carapace)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Dragonscale", descriptor: "Dragonscale",
), ),
quality: Direct(Legendary), quality: Direct(Legendary),
tags: [MaterialKind(Hide)], tags: [MaterialKind(Hide), Material(Dragonscale)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Plate", descriptor: "Plate",
), ),
quality: Direct(Epic), quality: Direct(Epic),
tags: [MaterialKind(Hide)], tags: [MaterialKind(Hide), Material(Plate)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Scale", descriptor: "Scale",
), ),
quality: Direct(Moderate), quality: Direct(Moderate),
tags: [MaterialKind(Hide)], tags: [MaterialKind(Hide), Material(Scale)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Raw Hide", descriptor: "Raw Hide",
), ),
quality: Direct(Low), quality: Direct(Low),
tags: [BaseMaterial, Leather, MaterialKind(Hide)], tags: [BaseMaterial, Leather, MaterialKind(Hide), Material(Rawhide)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Leather", descriptor: "Leather",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [BaseMaterial, Leather, MaterialKind(Hide)], tags: [BaseMaterial, Leather, MaterialKind(Hide), Material(Leather)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Bamboo", descriptor: "Bamboo",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [MaterialKind(Wood)], tags: [MaterialKind(Wood), Material(Bamboo)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Eldwood", descriptor: "Eldwood",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [MaterialKind(Wood)], tags: [MaterialKind(Wood), Material(Eldwood)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Frostwood", descriptor: "Frostwood",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [MaterialKind(Wood)], tags: [MaterialKind(Wood), Material(Frostwood)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Hardwood", descriptor: "Hardwood",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [MaterialKind(Wood)], tags: [MaterialKind(Wood), Material(Hardwood)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Ironwood", descriptor: "Ironwood",
), ),
quality: Direct(High), quality: Direct(High),
tags: [MaterialKind(Wood)], tags: [MaterialKind(Wood), Material(Ironwood)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Wooden", descriptor: "Wooden",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [MaterialKind(Wood)], tags: [MaterialKind(Wood), Material(Wood)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Bloodsteel", descriptor: "Bloodsteel",
), ),
quality: Direct(Epic), quality: Direct(Epic),
tags: [MaterialKind(Metal)], tags: [MaterialKind(Metal), Material(Bloodsteel)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Bronze", descriptor: "Bronze",
), ),
quality: Direct(Low), quality: Direct(Low),
tags: [MaterialKind(Metal)], tags: [MaterialKind(Metal), Material(Bronze)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Cobalt", descriptor: "Cobalt",
), ),
quality: Direct(High), quality: Direct(High),
tags: [MaterialKind(Metal)], tags: [MaterialKind(Metal), Material(Cobalt)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Iron", descriptor: "Iron",
), ),
quality: Direct(Common), quality: Direct(Common),
tags: [MaterialKind(Metal)], tags: [MaterialKind(Metal), Material(Iron)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Orichalcum", descriptor: "Orichalcum",
), ),
quality: Direct(Legendary), quality: Direct(Legendary),
tags: [MaterialKind(Metal)], tags: [MaterialKind(Metal), Material(Orichalcum)],
) )

View File

@ -6,5 +6,5 @@ ItemDef(
descriptor: "Steel", descriptor: "Steel",
), ),
quality: Direct(Moderate), quality: Direct(Moderate),
tags: [MaterialKind(Metal)], tags: [MaterialKind(Metal), Material(Steel)],
) )

View File

@ -316,6 +316,10 @@
"voxel.weapon.sword.iron-5", "voxel.weapon.sword.iron-5",
(0.0, 0.0, -4.0), (-135.0, 90.0, 0.0), 1.1, (0.0, 0.0, -4.0), (-135.0, 90.0, 0.0), 1.1,
), ),
ModularWeapon(("common.items.crafting_ing.modular.damage.sword.longsword", "iron", One)): VoxTrans(
"voxel.weapon.sword.iron-5",
(0.0, 0.0, -4.0), (-135.0, 90.0, 0.0), 1.1,
),
Tool("common.items.weapons.sword.iron-6"): VoxTrans( Tool("common.items.weapons.sword.iron-6"): VoxTrans(
"voxel.weapon.sword.iron-6", "voxel.weapon.sword.iron-6",
(0.0, 0.0, -4.0), (-135.0, 90.0, 0.0), 1.1, (0.0, 0.0, -4.0), (-135.0, 90.0, 0.0), 1.1,

View File

@ -2,7 +2,7 @@ use crate::{
assets::AssetExt, assets::AssetExt,
comp::inventory::item::{ comp::inventory::item::{
armor::{Armor, ArmorKind}, armor::{Armor, ArmorKind},
Glider, ItemDef, ItemDesc, ItemKind, Lantern, Throwable, Utility, modular, tool, Glider, ItemDef, ItemDesc, ItemKind, Lantern, Throwable, Utility,
}, },
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -11,6 +11,7 @@ use std::sync::Arc;
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)] #[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
pub enum ItemKey { pub enum ItemKey {
Tool(String), Tool(String),
ModularWeapon(modular::ModularWeaponKey),
ModularComponent(String), ModularComponent(String),
Lantern(String), Lantern(String),
Glider(String), Glider(String),
@ -29,7 +30,13 @@ impl<T: ItemDesc> From<&T> for ItemKey {
let item_definition_id = item_desc.item_definition_id(); let item_definition_id = item_desc.item_definition_id();
match item_kind { match item_kind {
ItemKind::Tool(_) => ItemKey::Tool(item_definition_id.to_owned()), ItemKind::Tool(tool) => {
use tool::StatKind;
match tool.stats {
StatKind::Direct(_) => ItemKey::Tool(item_definition_id.to_owned()),
StatKind::Modular => ItemKey::ModularWeapon(modular::weapon_to_key(item_desc)),
}
},
ItemKind::ModularComponent(_) => { ItemKind::ModularComponent(_) => {
ItemKey::ModularComponent(item_definition_id.to_owned()) ItemKey::ModularComponent(item_definition_id.to_owned())
}, },

View File

@ -212,28 +212,18 @@ impl Material {
} }
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] impl TagExampleInfo for Material {
#[serde(transparent)] fn name(&self) -> Cow<'static, str> { Cow::Borrowed(self.into()) }
pub struct MaterialTag {
material: Material,
}
impl MaterialTag {
pub fn material(&self) -> &Material { &self.material }
}
impl TagExampleInfo for MaterialTag {
fn name(&self) -> Cow<'static, str> { Cow::Borrowed(self.material.into()) }
fn exemplar_identifier(&self) -> Cow<'static, str> { fn exemplar_identifier(&self) -> Cow<'static, str> {
Cow::Borrowed("common.items.tag_examples.placeholder") Cow::Borrowed(self.asset_identifier().unwrap_or(""))
} }
} }
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum ItemTag { pub enum ItemTag {
Leather, Leather,
Material(MaterialTag), Material(Material),
MaterialKind(MaterialKind), MaterialKind(MaterialKind),
ModularComponent(ModularComponentTag), ModularComponent(ModularComponentTag),
Cultist, Cultist,

View File

@ -1,6 +1,6 @@
use super::{ use super::{
tool::{self, Hands}, tool::{self, Hands},
Item, ItemKind, ItemName, ItemTag, RawItemDef, TagExampleInfo, ToolKind, Item, ItemDesc, ItemKind, ItemName, ItemTag, RawItemDef, TagExampleInfo, ToolKind,
}; };
use crate::{ use crate::{
assets::AssetExt, assets::AssetExt,
@ -435,7 +435,9 @@ pub fn random_weapon(tool: ToolKind, material: super::Material, hands: Option<Ha
.map_or(hands, Some); .map_or(hands, Some);
let held_comp_dir = make_mod_comp_dir_def(tool, ModularComponentKind::Held); let held_comp_dir = make_mod_comp_dir_def(tool, ModularComponentKind::Held);
let mut held_component = create_component(&held_comp_dir, damage_hands); let mut held_component = create_component(&held_comp_dir, damage_hands);
let material_component = Item::new_from_asset_expect(material.asset_identifier().expect("Code reviewers: open comment here if I forget about this, I got lazy during a rebase")); let material_component = Item::new_from_asset_expect(material.asset_identifier().expect(
"Code reviewers: open comment here if I forget about this, I got lazy during a rebase",
));
// Insert material item into modular component of appropriate kind // Insert material item into modular component of appropriate kind
match material_comp { match material_comp {
@ -454,3 +456,36 @@ pub fn random_weapon(tool: ToolKind, material: super::Material, hands: Option<Ha
// Returns fully created modular weapon // Returns fully created modular weapon
modular_weapon modular_weapon
} }
// (Main component, material, hands)
pub type ModularWeaponKey = (String, String, Hands);
pub fn weapon_to_key(mod_weap: &dyn ItemDesc) -> ModularWeaponKey {
let hands = if let ItemKind::Tool(tool) = mod_weap.kind() {
tool.hands.resolve_hands(mod_weap.components())
} else {
Hands::One
};
let (main_comp, material) = if let Some(main_comp) = mod_weap.components().iter().find(|comp| {
matches!(comp.kind(), ItemKind::ModularComponent(mod_comp) if ModularComponentKind::main_component(mod_comp.toolkind) == mod_comp.modkind)
}) {
let material = if let Some(material) = main_comp.components().iter().filter_map(|mat| {
if let Some(super::ItemTag::Material(material)) = mat.tags().iter().find(|tag| matches!(tag, super::ItemTag::Material(_))) {
Some(material)
} else {
None
}
}).next() {
material.into()
} else {
""
};
(main_comp.item_definition_id(), material)
} else {
("", "")
};
(main_comp.to_owned(), material.to_owned(), hands)
}

View File

@ -139,7 +139,11 @@ impl<T: AsRef<str>> LootSpec<T> {
.choose() .choose()
.to_item(), .to_item(),
Self::Nothing => None, Self::Nothing => None,
Self::ModularWeapon { tool, material, hands } => Some(item::modular::random_weapon(*tool, *material, *hands)), Self::ModularWeapon {
tool,
material,
hands,
} => Some(item::modular::random_weapon(*tool, *material, *hands)),
} }
} }
} }

View File

@ -198,14 +198,12 @@ impl CraftingTab {
}, },
CraftingTab::Glider => matches!(item.kind(), ItemKind::Glider(_)), CraftingTab::Glider => matches!(item.kind(), ItemKind::Glider(_)),
CraftingTab::Potion => item.tags().contains(&ItemTag::Potion), CraftingTab::Potion => item.tags().contains(&ItemTag::Potion),
CraftingTab::ProcessedMaterial => { CraftingTab::ProcessedMaterial => item.tags().iter().any(|tag| {
item.tags().iter().any(|tag| { matches!(
matches!( tag,
tag, &ItemTag::MaterialKind(_) | &ItemTag::Leather | &ItemTag::BaseMaterial
&ItemTag::MaterialKind(_) | &ItemTag::Leather | &ItemTag::BaseMaterial )
) }),
})
},
CraftingTab::Bag => item.tags().contains(&ItemTag::Bag), CraftingTab::Bag => item.tags().contains(&ItemTag::Bag),
CraftingTab::Tool => item.tags().contains(&ItemTag::CraftingTool), CraftingTab::Tool => item.tags().contains(&ItemTag::CraftingTool),
CraftingTab::Utility => item.tags().contains(&ItemTag::Utility), CraftingTab::Utility => item.tags().contains(&ItemTag::Utility),

View File

@ -613,7 +613,10 @@ impl<'a> Skillbar<'a> {
.get(i) .get(i)
.and_then(|a| Ability::from(*a).ability_id(Some(inventory))) .and_then(|a| Ability::from(*a).ability_id(Some(inventory)))
}) })
.map(util::ability_description), .map(|a| {
let (title, desc) = util::ability_description(a);
(Cow::Borrowed(title), desc)
}),
}) })
}; };

View File

@ -472,16 +472,16 @@ impl<'a> Widget for ItemTooltip<'a> {
let item_kind = util::kind_text(item, i18n).to_string(); let item_kind = util::kind_text(item, i18n).to_string();
let material_tag = item.tags().iter().find_map(|t| match t { let material = item.tags().iter().find_map(|t| match t {
ItemTag::Material(material) => Some(material), ItemTag::Material(material) => Some(material),
_ => None, _ => None,
}); });
let subtitle = if let Some(material_tag) = material_tag { let subtitle = if let Some(material) = material {
format!( format!(
"{} ({})", "{} ({})",
item_kind, item_kind,
util::material_kind_text(&material_tag.material().material_kind(), i18n) util::material_kind_text(&material.material_kind(), i18n)
) )
} else { } else {
item_kind item_kind