Avoid cloning armor/tool in tooltip generation, add temporary case for legacy item descriptions

This commit is contained in:
Imbris 2020-08-07 01:25:51 -04:00
parent 44febaabdf
commit d74a1d371e

View File

@ -20,8 +20,8 @@ pub fn loadout_slot_text<'a>(
pub fn item_text<'a>(item: &'a Item) -> (&'_ str, Cow<'a, str>) {
let desc = match &item.kind {
ItemKind::Armor(armor) => Cow::Owned(armor_desc(armor.clone(), item.description())),
ItemKind::Tool(tool) => Cow::Owned(tool_desc(tool.clone(), item.description())),
ItemKind::Armor(armor) => Cow::Owned(armor_desc(&armor, item.description())),
ItemKind::Tool(tool) => Cow::Owned(tool_desc(&tool, item.description())),
/*ItemKind::Consumable(kind, effect, ..) => {
Cow::Owned(consumable_desc(consumable, item.description()))
},*/
@ -35,7 +35,7 @@ pub fn item_text<'a>(item: &'a Item) -> (&'_ str, Cow<'a, str>) {
(item.name(), desc)
}
// Armor Description
fn armor_desc(armor: Armor, desc: &str) -> String {
fn armor_desc(armor: &Armor, desc: &str) -> String {
// TODO: localization
let kind = match armor.kind {
ArmorKind::Shoulder(_) => "Shoulders",
@ -55,6 +55,13 @@ fn armor_desc(armor: Armor, desc: &str) -> String {
Protection::Invincible => "Inf".to_string(),
};
// TODO: remove when legacy descriptions are fixed by persistence overhaul
let desc = if desc.contains("<Right-Click to use>") {
"Legacy item."
} else {
desc
};
if !desc.is_empty() {
format!(
"{}\n\nArmor: {}\n\n{}\n\n<Right-Click to use>",
@ -65,7 +72,7 @@ fn armor_desc(armor: Armor, desc: &str) -> String {
}
}
// Weapon/Tool Description
fn tool_desc(tool: Tool, desc: &str) -> String {
fn tool_desc(tool: &Tool, desc: &str) -> String {
// TODO: localization
let kind = match tool.kind {
ToolKind::Sword(_) => "Sword",
@ -81,6 +88,13 @@ fn tool_desc(tool: Tool, desc: &str) -> String {
};
let power = tool.base_power();
// TODO: remove when legacy descriptions are fixed by persistence overhaul
let desc = if desc.contains("<Right-Click to use>") {
"Legacy item."
} else {
desc
};
if !desc.is_empty() {
format!(
"{}\n\nPower: {:0.1}\n\n{}\n\n<Right-Click to use>",