From 6adaac810605f42c2cbf2c91828fc349e5f0cb70 Mon Sep 17 00:00:00 2001 From: Snowram Date: Sun, 28 Mar 2021 14:27:59 +0200 Subject: [PATCH] Addresses comments --- assets/voxygen/i18n/en/buff.ron | 2 +- assets/voxygen/i18n/fr_FR/buff.ron | 2 +- common/src/comp/inventory/item/armor.rs | 10 ++-- voxygen/src/hud/util.rs | 62 +++++++++++++------------ 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/assets/voxygen/i18n/en/buff.ron b/assets/voxygen/i18n/en/buff.ron index a8308df657..9fa2439d4a 100644 --- a/assets/voxygen/i18n/en/buff.ron +++ b/assets/voxygen/i18n/en/buff.ron @@ -28,7 +28,7 @@ "buff.stat.health": "Restores {str_total} Health", "buff.stat.increase_max_stamina": "Raises Maximum Stamina by {strength}", "buff.stat.increase_max_health": "Raises Maximum Health by {strength}", - "buff.stat.invulenrability": "Grants invulnerability", + "buff.stat.invulnerability": "Grants invulnerability", // Text "buff.text.over_seconds": "over {dur_secs} seconds", "buff.text.for_seconds": "for {dur_secs} seconds", diff --git a/assets/voxygen/i18n/fr_FR/buff.ron b/assets/voxygen/i18n/fr_FR/buff.ron index 2e90f0158f..3b3d22a034 100644 --- a/assets/voxygen/i18n/fr_FR/buff.ron +++ b/assets/voxygen/i18n/fr_FR/buff.ron @@ -28,7 +28,7 @@ "buff.stat.health": "Restaure {str_total} points de vie", "buff.stat.increase_max_stamina": "Augmente la vigueur maximale de {strength}", "buff.stat.increase_max_health": "Augmente la santé maximale de {strength}", - "buff.stat.invulenrability": "Rend invincible", + "buff.stat.invulnerability": "Rend invincible", // Text "buff.text.over_seconds": "pendant {dur_secs} secondes", "buff.text.for_seconds": "pour {dur_secs} secondes", diff --git a/common/src/comp/inventory/item/armor.rs b/common/src/comp/inventory/item/armor.rs index 71ed15d9f1..19b0f42fd4 100644 --- a/common/src/comp/inventory/item/armor.rs +++ b/common/src/comp/inventory/item/armor.rs @@ -27,12 +27,12 @@ impl Armor { } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] -pub struct Stats { +pub struct Stats { protection: Protection, poise_resilience: Protection, } -impl Stats { +impl Stats { // DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING // Added for csv import of stats pub fn new(protection: Protection, poise_resilience: Protection) -> Self { @@ -47,7 +47,7 @@ impl Stats { pub fn get_poise_resilience(&self) -> Protection { self.poise_resilience } } -impl Sub> for Stats { +impl Sub for Stats { type Output = Self; fn sub(self, other: Self) -> Self::Output { @@ -64,7 +64,7 @@ pub enum Protection { Normal(f32), } -impl Sub for Protection { +impl Sub for Protection { type Output = Self; fn sub(self, other: Self) -> Self::Output { @@ -92,7 +92,7 @@ impl PartialOrd for Protection { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Armor { pub kind: ArmorKind, - pub stats: Stats, + pub stats: Stats, } impl Armor { diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index a928c52cb3..60f08fa105 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -11,7 +11,7 @@ use common::{ effect::Effect, trade::{Good, SitePrices}, }; -use std::fmt::Write; +use std::{borrow::Cow, fmt::Write}; use crate::i18n::Localization; @@ -27,36 +27,38 @@ pub fn price_desc( let sellprice = buyprice * material.trade_margin(); Some(format!( "{} : {:0.1} {}\n{} : {:0.1} {}", - i18n.get("hud.trade.buy_price").to_string(), + i18n.get("hud.trade.buy_price"), buyprice / coinprice, - i18n.get("hud.trade.coin").to_string(), - i18n.get("hud.trade.sell_price").to_string(), + i18n.get("hud.trade.coin"), + i18n.get("hud.trade.sell_price"), sellprice / coinprice, - i18n.get("hud.trade.coin").to_string(), + i18n.get("hud.trade.coin"), )) } else { None } } -pub fn kind_text(kind: &ItemKind, i18n: &Localization) -> String { +pub fn kind_text<'a>(kind: &ItemKind, i18n: &'a Localization) -> Cow<'a, str> { match kind { - ItemKind::Armor(armor) => armor_kind(&armor, &i18n), - ItemKind::Tool(tool) => { - format!("{} ({})", tool_kind(&tool, &i18n), tool_hands(&tool, i18n)) - }, - ItemKind::ModularComponent(_mc) => i18n.get("common.bag.shoulders").to_string(), - ItemKind::Glider(_glider) => i18n.get("common.kind.glider").to_string(), - ItemKind::Consumable { .. } => i18n.get("common.kind.consumable").to_string(), - ItemKind::Throwable { .. } => i18n.get("common.kind.throwable").to_string(), - ItemKind::Utility { .. } => i18n.get("common.kind.utility").to_string(), - ItemKind::Ingredient { .. } => i18n.get("common.kind.ingredient").to_string(), - ItemKind::Lantern { .. } => i18n.get("common.kind.lantern").to_string(), - ItemKind::TagExamples { .. } => "".to_string(), + ItemKind::Armor(armor) => Cow::Borrowed(armor_kind(&armor, &i18n)), + ItemKind::Tool(tool) => Cow::Owned(format!( + "{} ({})", + tool_kind(&tool, i18n), + tool_hands(&tool, i18n) + )), + ItemKind::ModularComponent(_mc) => Cow::Borrowed(i18n.get("common.bag.shoulders")), + ItemKind::Glider(_glider) => Cow::Borrowed(i18n.get("common.kind.glider")), + ItemKind::Consumable { .. } => Cow::Borrowed(i18n.get("common.kind.consumable")), + ItemKind::Throwable { .. } => Cow::Borrowed(i18n.get("common.kind.throwable")), + ItemKind::Utility { .. } => Cow::Borrowed(i18n.get("common.kind.utility")), + ItemKind::Ingredient { .. } => Cow::Borrowed(i18n.get("common.kind.ingredient")), + ItemKind::Lantern { .. } => Cow::Borrowed(i18n.get("common.kind.lantern")), + ItemKind::TagExamples { .. } => Cow::Borrowed(""), } } -// TODO: localization +// TODO: localization, refactor when mc are player facing pub fn modular_component_desc( mc: &ModularComponent, components: &[Item], @@ -78,7 +80,7 @@ pub fn modular_component_desc( } pub fn consumable_desc(effects: &[Effect], i18n: &Localization) -> String { - let mut description = "".to_string(); + let mut description = String::new(); for effect in effects { if let Effect::Buff(buff) = effect { @@ -135,7 +137,7 @@ pub fn consumable_desc(effects: &[Effect], i18n: &Localization) -> String { } // Armor -fn armor_kind(armor: &Armor, i18n: &Localization) -> String { +fn armor_kind<'a>(armor: &Armor, i18n: &'a Localization) -> &'a str { let kind = match armor.kind { ArmorKind::Shoulder(_) => i18n.get("hud.bag.shoulders"), ArmorKind::Chest(_) => i18n.get("hud.bag.chest"), @@ -150,12 +152,12 @@ fn armor_kind(armor: &Armor, i18n: &Localization) -> String { ArmorKind::Tabard(_) => i18n.get("hud.bag.tabard"), ArmorKind::Bag(_) => i18n.get("hud.bag.bag"), }; - kind.to_string() + kind } //Tool -fn tool_kind(tool: &Tool, i18n: &Localization) -> String { +fn tool_kind<'a>(tool: &Tool, i18n: &'a Localization) -> &'a str { let kind = match tool.kind { ToolKind::Sword => i18n.get("common.weapons.sword"), ToolKind::Axe => i18n.get("common.weapons.axe"), @@ -177,15 +179,15 @@ fn tool_kind(tool: &Tool, i18n: &Localization) -> String { ToolKind::Pick => i18n.get("common.tool.pick"), ToolKind::Empty => i18n.get("common.empty"), }; - kind.to_string() + kind } -pub fn tool_hands(tool: &Tool, i18n: &Localization) -> String { +pub fn tool_hands<'a>(tool: &Tool, i18n: &'a Localization) -> &'a str { let hands = match tool.hands { Hands::One => i18n.get("common.hands.one"), Hands::Two => i18n.get("common.hands.two"), }; - hands.to_string() + hands } fn statblock_desc(stats: &Stats) -> String { @@ -202,13 +204,13 @@ fn statblock_desc(stats: &Stats) -> String { } // Compare two type, output a colored character to show comparison -pub fn comparison(first: T, other: T) -> (String, conrod_core::color::Color) { +pub fn comparison(first: T, other: T) -> (&'static str, conrod_core::Color) { if first == other { - ("•".to_string(), conrod_core::color::GREY) + ("•", conrod_core::color::GREY) } else if other < first { - ("▲".to_string(), conrod_core::color::GREEN) + ("▲", conrod_core::color::GREEN) } else { - ("▼".to_string(), conrod_core::color::RED) + ("▼", conrod_core::color::RED) } }