mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Modular weapons can now be properly displayed in the inventory.
This commit is contained in:
parent
105bb24631
commit
0a38567e8d
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Lifecloth",
|
||||
),
|
||||
quality: Direct(High),
|
||||
tags: [MaterialKind(Cloth)],
|
||||
tags: [MaterialKind(Cloth), Material(Lifecloth)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Linen",
|
||||
),
|
||||
quality: Direct(Low),
|
||||
tags: [MaterialKind(Cloth)],
|
||||
tags: [MaterialKind(Cloth), Material(Linen)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Moonwoven",
|
||||
),
|
||||
quality: Direct(Epic),
|
||||
tags: [MaterialKind(Cloth)],
|
||||
tags: [MaterialKind(Cloth), Material(Moonweave)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Silken",
|
||||
),
|
||||
quality: Direct(Moderate),
|
||||
tags: [MaterialKind(Cloth)],
|
||||
tags: [MaterialKind(Cloth), Material(Silk)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Sunsilken",
|
||||
),
|
||||
quality: Direct(Legendary),
|
||||
tags: [MaterialKind(Cloth)],
|
||||
tags: [MaterialKind(Cloth), Material(Sunsilk)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Woolen",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [MaterialKind(Cloth)],
|
||||
tags: [MaterialKind(Cloth), Material(Wool)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Carapace",
|
||||
),
|
||||
quality: Direct(High),
|
||||
tags: [MaterialKind(Hide)],
|
||||
tags: [MaterialKind(Hide), Material(Carapace)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Dragonscale",
|
||||
),
|
||||
quality: Direct(Legendary),
|
||||
tags: [MaterialKind(Hide)],
|
||||
tags: [MaterialKind(Hide), Material(Dragonscale)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Plate",
|
||||
),
|
||||
quality: Direct(Epic),
|
||||
tags: [MaterialKind(Hide)],
|
||||
tags: [MaterialKind(Hide), Material(Plate)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Scale",
|
||||
),
|
||||
quality: Direct(Moderate),
|
||||
tags: [MaterialKind(Hide)],
|
||||
tags: [MaterialKind(Hide), Material(Scale)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Raw Hide",
|
||||
),
|
||||
quality: Direct(Low),
|
||||
tags: [BaseMaterial, Leather, MaterialKind(Hide)],
|
||||
tags: [BaseMaterial, Leather, MaterialKind(Hide), Material(Rawhide)],
|
||||
)
|
||||
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Leather",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [BaseMaterial, Leather, MaterialKind(Hide)],
|
||||
tags: [BaseMaterial, Leather, MaterialKind(Hide), Material(Leather)],
|
||||
)
|
||||
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Bamboo",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [MaterialKind(Wood)],
|
||||
tags: [MaterialKind(Wood), Material(Bamboo)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Eldwood",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [MaterialKind(Wood)],
|
||||
tags: [MaterialKind(Wood), Material(Eldwood)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Frostwood",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [MaterialKind(Wood)],
|
||||
tags: [MaterialKind(Wood), Material(Frostwood)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Hardwood",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [MaterialKind(Wood)],
|
||||
tags: [MaterialKind(Wood), Material(Hardwood)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Ironwood",
|
||||
),
|
||||
quality: Direct(High),
|
||||
tags: [MaterialKind(Wood)],
|
||||
tags: [MaterialKind(Wood), Material(Ironwood)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Wooden",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [MaterialKind(Wood)],
|
||||
tags: [MaterialKind(Wood), Material(Wood)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Bloodsteel",
|
||||
),
|
||||
quality: Direct(Epic),
|
||||
tags: [MaterialKind(Metal)],
|
||||
tags: [MaterialKind(Metal), Material(Bloodsteel)],
|
||||
)
|
||||
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Bronze",
|
||||
),
|
||||
quality: Direct(Low),
|
||||
tags: [MaterialKind(Metal)],
|
||||
tags: [MaterialKind(Metal), Material(Bronze)],
|
||||
)
|
||||
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Cobalt",
|
||||
),
|
||||
quality: Direct(High),
|
||||
tags: [MaterialKind(Metal)],
|
||||
tags: [MaterialKind(Metal), Material(Cobalt)],
|
||||
)
|
||||
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Iron",
|
||||
),
|
||||
quality: Direct(Common),
|
||||
tags: [MaterialKind(Metal)],
|
||||
tags: [MaterialKind(Metal), Material(Iron)],
|
||||
)
|
||||
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Orichalcum",
|
||||
),
|
||||
quality: Direct(Legendary),
|
||||
tags: [MaterialKind(Metal)],
|
||||
tags: [MaterialKind(Metal), Material(Orichalcum)],
|
||||
)
|
@ -6,5 +6,5 @@ ItemDef(
|
||||
descriptor: "Steel",
|
||||
),
|
||||
quality: Direct(Moderate),
|
||||
tags: [MaterialKind(Metal)],
|
||||
tags: [MaterialKind(Metal), Material(Steel)],
|
||||
)
|
||||
|
@ -316,6 +316,10 @@
|
||||
"voxel.weapon.sword.iron-5",
|
||||
(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(
|
||||
"voxel.weapon.sword.iron-6",
|
||||
(0.0, 0.0, -4.0), (-135.0, 90.0, 0.0), 1.1,
|
||||
|
@ -2,7 +2,7 @@ use crate::{
|
||||
assets::AssetExt,
|
||||
comp::inventory::item::{
|
||||
armor::{Armor, ArmorKind},
|
||||
Glider, ItemDef, ItemDesc, ItemKind, Lantern, Throwable, Utility,
|
||||
modular, tool, Glider, ItemDef, ItemDesc, ItemKind, Lantern, Throwable, Utility,
|
||||
},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -11,6 +11,7 @@ use std::sync::Arc;
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
|
||||
pub enum ItemKey {
|
||||
Tool(String),
|
||||
ModularWeapon(modular::ModularWeaponKey),
|
||||
ModularComponent(String),
|
||||
Lantern(String),
|
||||
Glider(String),
|
||||
@ -29,7 +30,13 @@ impl<T: ItemDesc> From<&T> for ItemKey {
|
||||
let item_definition_id = item_desc.item_definition_id();
|
||||
|
||||
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(_) => {
|
||||
ItemKey::ModularComponent(item_definition_id.to_owned())
|
||||
},
|
||||
|
@ -212,28 +212,18 @@ impl Material {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
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()) }
|
||||
impl TagExampleInfo for Material {
|
||||
fn name(&self) -> Cow<'static, str> { Cow::Borrowed(self.into()) }
|
||||
|
||||
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)]
|
||||
pub enum ItemTag {
|
||||
Leather,
|
||||
Material(MaterialTag),
|
||||
Material(Material),
|
||||
MaterialKind(MaterialKind),
|
||||
ModularComponent(ModularComponentTag),
|
||||
Cultist,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
tool::{self, Hands},
|
||||
Item, ItemKind, ItemName, ItemTag, RawItemDef, TagExampleInfo, ToolKind,
|
||||
Item, ItemDesc, ItemKind, ItemName, ItemTag, RawItemDef, TagExampleInfo, ToolKind,
|
||||
};
|
||||
use crate::{
|
||||
assets::AssetExt,
|
||||
@ -435,7 +435,9 @@ pub fn random_weapon(tool: ToolKind, material: super::Material, hands: Option<Ha
|
||||
.map_or(hands, Some);
|
||||
let held_comp_dir = make_mod_comp_dir_def(tool, ModularComponentKind::Held);
|
||||
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
|
||||
match material_comp {
|
||||
@ -454,3 +456,36 @@ pub fn random_weapon(tool: ToolKind, material: super::Material, hands: Option<Ha
|
||||
// Returns fully created 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)
|
||||
}
|
||||
|
@ -139,7 +139,11 @@ impl<T: AsRef<str>> LootSpec<T> {
|
||||
.choose()
|
||||
.to_item(),
|
||||
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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,14 +198,12 @@ impl CraftingTab {
|
||||
},
|
||||
CraftingTab::Glider => matches!(item.kind(), ItemKind::Glider(_)),
|
||||
CraftingTab::Potion => item.tags().contains(&ItemTag::Potion),
|
||||
CraftingTab::ProcessedMaterial => {
|
||||
item.tags().iter().any(|tag| {
|
||||
matches!(
|
||||
tag,
|
||||
&ItemTag::MaterialKind(_) | &ItemTag::Leather | &ItemTag::BaseMaterial
|
||||
)
|
||||
})
|
||||
},
|
||||
CraftingTab::ProcessedMaterial => item.tags().iter().any(|tag| {
|
||||
matches!(
|
||||
tag,
|
||||
&ItemTag::MaterialKind(_) | &ItemTag::Leather | &ItemTag::BaseMaterial
|
||||
)
|
||||
}),
|
||||
CraftingTab::Bag => item.tags().contains(&ItemTag::Bag),
|
||||
CraftingTab::Tool => item.tags().contains(&ItemTag::CraftingTool),
|
||||
CraftingTab::Utility => item.tags().contains(&ItemTag::Utility),
|
||||
|
@ -613,7 +613,10 @@ impl<'a> Skillbar<'a> {
|
||||
.get(i)
|
||||
.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)
|
||||
}),
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -472,16 +472,16 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
|
||||
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),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let subtitle = if let Some(material_tag) = material_tag {
|
||||
let subtitle = if let Some(material) = material {
|
||||
format!(
|
||||
"{} ({})",
|
||||
item_kind,
|
||||
util::material_kind_text(&material_tag.material().material_kind(), i18n)
|
||||
util::material_kind_text(&material.material_kind(), i18n)
|
||||
)
|
||||
} else {
|
||||
item_kind
|
||||
|
Loading…
Reference in New Issue
Block a user