From 1748b5e76f175ed9cdc11eff94b3d6bb0b197ef9 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Sat, 13 Jan 2024 20:16:45 +0200 Subject: [PATCH] Final(?) step to deprecating item names --- common/src/comp/inventory/item/mod.rs | 66 ++++++++++++++++------- common/src/comp/inventory/item/modular.rs | 3 ++ voxygen/src/hud/crafting.rs | 20 ++++++- 3 files changed, 67 insertions(+), 22 deletions(-) diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 20211bec97..6e39046367 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -354,7 +354,8 @@ pub enum ItemKind { }, Ingredient { /// Used to generate names for modular items composed of this ingredient - #[deprecated] + // I think we can actually remove it now? + #[deprecated = "part of non-localized name generation"] descriptor: String, }, TagExamples { @@ -685,8 +686,10 @@ pub struct ItemDef { /// assets folder, which the ItemDef is loaded from. The name space /// prepended with `veloren.core` is reserved for veloren functions. item_definition_id: String, - pub name: String, - pub description: String, + #[deprecated = "since item i18n"] + name: String, + #[deprecated = "since item i18n"] + description: String, pub kind: ItemKind, pub quality: Quality, pub tags: Vec, @@ -835,8 +838,8 @@ impl assets::Compound for ItemDef { } let RawItemDef { - name, - description, + legacy_name, + legacy_description, kind, quality, tags, @@ -850,10 +853,11 @@ impl assets::Compound for ItemDef { // TODO: This probably does not belong here let item_definition_id = specifier.replace('\\', "."); + #[allow(deprecated)] Ok(ItemDef { item_definition_id, - name, - description, + name: legacy_name, + description: legacy_description, kind, quality, tags, @@ -866,8 +870,8 @@ impl assets::Compound for ItemDef { #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename = "ItemDef")] struct RawItemDef { - name: String, - description: String, + legacy_name: String, + legacy_description: String, kind: ItemKind, quality: Quality, tags: Vec, @@ -1207,13 +1211,15 @@ impl Item { }) } - #[deprecated] + #[deprecated = "since item i18n"] pub fn name(&self) -> Cow { match &self.item_base { ItemBase::Simple(item_def) => { if self.components.is_empty() { + #[allow(deprecated)] Cow::Borrowed(&item_def.name) } else { + #[allow(deprecated)] modular::modify_name(&item_def.name, self) } }, @@ -1221,9 +1227,10 @@ impl Item { } } - #[deprecated] + #[deprecated = "since item i18n"] pub fn description(&self) -> &str { match &self.item_base { + #[allow(deprecated)] ItemBase::Simple(item_def) => &item_def.description, // TODO: See if James wanted to make description, else leave with none ItemBase::Modular(_) => "", @@ -1448,9 +1455,9 @@ pub fn flatten_counted_items<'a>( /// Provides common methods providing details about an item definition /// for either an `Item` containing the definition, or the actual `ItemDef` pub trait ItemDesc { - #[deprecated] + #[deprecated = "since item i18n"] fn description(&self) -> &str; - #[deprecated] + #[deprecated = "since item i18n"] fn name(&self) -> Cow; fn kind(&self) -> Cow; fn amount(&self) -> NonZeroU32; @@ -1476,19 +1483,26 @@ pub trait ItemDesc { fn l10n(&self, l10n: &ItemL10n) -> (Content, Content) { let item_key: ItemKey = self.into(); + #[allow(deprecated)] l10n.item_text_opt(item_key).unwrap_or_else(|| { ( Content::Plain(self.name().to_string()), - Content::Plain(self.name().to_string()), + Content::Plain(self.description().to_string()), ) }) } } impl ItemDesc for Item { - fn description(&self) -> &str { self.description() } + fn description(&self) -> &str { + #[allow(deprecated)] + self.description() + } - fn name(&self) -> Cow { self.name() } + fn name(&self) -> Cow { + #[allow(deprecated)] + self.name() + } fn kind(&self) -> Cow { self.kind() } @@ -1516,9 +1530,15 @@ impl ItemDesc for Item { } impl ItemDesc for ItemDef { - fn description(&self) -> &str { &self.description } + fn description(&self) -> &str { + #[allow(deprecated)] + &self.description + } - fn name(&self) -> Cow { Cow::Borrowed(&self.name) } + fn name(&self) -> Cow { + #[allow(deprecated)] + Cow::Borrowed(&self.name) + } fn kind(&self) -> Cow { Cow::Borrowed(&self.kind) } @@ -1562,9 +1582,15 @@ impl Component for ItemDrops { pub struct DurabilityMultiplier(pub f32); impl<'a, T: ItemDesc + ?Sized> ItemDesc for &'a T { - fn description(&self) -> &str { (*self).description() } + fn description(&self) -> &str { + #[allow(deprecated)] + (*self).description() + } - fn name(&self) -> Cow { (*self).name() } + fn name(&self) -> Cow { + #[allow(deprecated)] + (*self).name() + } fn kind(&self) -> Cow { (*self).kind() } diff --git a/common/src/comp/inventory/item/modular.rs b/common/src/comp/inventory/item/modular.rs index 99d81d70c4..29be4079f3 100644 --- a/common/src/comp/inventory/item/modular.rs +++ b/common/src/comp/inventory/item/modular.rs @@ -155,9 +155,11 @@ impl ModularBase { .components() .iter() .find_map(|mat| match mat.kind() { + #[allow(deprecated)] Cow::Owned(ItemKind::Ingredient { descriptor, .. }) => { Some(Cow::Owned(descriptor)) }, + #[allow(deprecated)] Cow::Borrowed(ItemKind::Ingredient { descriptor, .. }) => { Some(Cow::Borrowed(descriptor.as_str())) }, @@ -583,6 +585,7 @@ pub fn modify_name<'a>(item_name: &'a str, item: &'a Item) -> Cow<'a, str> { .components() .iter() .find_map(|comp| match &*comp.kind() { + #[allow(deprecated)] ItemKind::Ingredient { descriptor, .. } => Some(descriptor.to_owned()), _ => None, }) diff --git a/voxygen/src/hud/crafting.rs b/voxygen/src/hud/crafting.rs index b28a085389..338b100146 100644 --- a/voxygen/src/hud/crafting.rs +++ b/voxygen/src/hud/crafting.rs @@ -548,6 +548,8 @@ impl<'a> Widget for Crafting<'a> { let metal_comp_recipe = make_pseudo_recipe(SpriteKind::Anvil); let wood_comp_recipe = make_pseudo_recipe(SpriteKind::CraftingBench); let repair_recipe = make_pseudo_recipe(SpriteKind::RepairBench); + + // TODO: localize let pseudo_entries = { // A BTreeMap is used over a HashMap as when a HashMap is used, the UI shuffles // the positions of these every tick, so a BTreeMap is necessary to keep it @@ -735,11 +737,18 @@ impl<'a> Widget for Crafting<'a> { .press_image(self.imgs.selection_press) .image_color(color::rgba(1.0, 0.82, 0.27, 1.0)); + let borrow_check; let recipe_name = if let Some((_recipe, pseudo_name, _filter_tab)) = pseudo_entries.get(name) { *pseudo_name } else { - &recipe.output.0.name + let (title, _) = util::item_text( + recipe.output.0.as_ref(), + self.localized_strings, + self.item_l10n, + ); + borrow_check = title; + &borrow_check }; let text = Text::new(recipe_name) @@ -856,12 +865,19 @@ impl<'a> Widget for Crafting<'a> { None => None, } { let recipe_name = String::from(recipe_name); + let borrow_check; let title = if let Some((_recipe, pseudo_name, _filter_tab)) = pseudo_entries.get(&recipe_name) { *pseudo_name } else { - &recipe.output.0.name + let (title, _) = util::item_text( + recipe.output.0.as_ref(), + self.localized_strings, + self.item_l10n, + ); + borrow_check = title; + &borrow_check }; // Title Text::new(title)