mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added programmatic names for modular components.
This commit is contained in:
parent
405b9b2448
commit
885bb9aaa7
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Axe head"),
|
||||
name: Component("Axe Head"),
|
||||
description: "An axe head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Axe,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Battleaxe head"),
|
||||
name: Component("Battleaxe Head"),
|
||||
description: "An axe head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Axe,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Greataxe Head"),
|
||||
name: Component("Greataxe Head"),
|
||||
description: "An axe head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Axe,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Poleaxe head"),
|
||||
name: Component("Poleaxe Head"),
|
||||
description: "An axe head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Axe,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Greathammer Head"),
|
||||
name: Component("Greathammer Head"),
|
||||
description: "A hammer head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Hammer,
|
||||
|
@ -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,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Hammer head"),
|
||||
name: Component("Hammer Head"),
|
||||
description: "A hammer head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Hammer,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Maul head"),
|
||||
name: Component("Maul Head"),
|
||||
description: "A hammer head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Hammer,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Warhammer head"),
|
||||
name: Component("Warhammer Head"),
|
||||
description: "A hammer head made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Hammer,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Greatsword blade"),
|
||||
name: Component("Greatsword Blade"),
|
||||
description: "A sword blade made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Sword,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Katana blade"),
|
||||
name: Component("Katana Blade"),
|
||||
description: "A sword blade made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Sword,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Longsword blade"),
|
||||
name: Component("Longsword Blade"),
|
||||
description: "A sword blade made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Sword,
|
||||
|
@ -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,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Sabre blade"),
|
||||
name: Component("Sabre Blade"),
|
||||
description: "A sword blade made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Sword,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Sword sawblade"),
|
||||
name: Component("Sawblade"),
|
||||
description: "A sword blade made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Sword,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Zweihander blade"),
|
||||
name: Component("Zweihander Blade"),
|
||||
description: "A sword blade made of metal.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Sword,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Long axe haft"),
|
||||
name: Component("Long Axe Haft"),
|
||||
description: "A axe haft.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Axe,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Medium axe haft"),
|
||||
name: Component("Medium Axe Haft"),
|
||||
description: "A axe half.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Axe,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Short axe haft"),
|
||||
name: Component("Short Axe Haft"),
|
||||
description: "A axe haft.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Axe,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Long hammer haft"),
|
||||
name: Component("Long Hammer Haft"),
|
||||
description: "A hammer haft.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Hammer,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Medium hammer haft"),
|
||||
name: Component("Medium Hammer Haft"),
|
||||
description: "A hammer half.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Hammer,
|
||||
|
@ -1,5 +1,5 @@
|
||||
ItemDef(
|
||||
name: Direct("Short hammer haft"),
|
||||
name: Component("Short Hammer Haft"),
|
||||
description: "A hammer haft.",
|
||||
kind: ModularComponent((
|
||||
toolkind: Hammer,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -265,40 +265,68 @@ pub(super) fn synthesize_modular_asset(specifier: &str) -> Option<RawItemDef> {
|
||||
/// 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"),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user