2020-07-18 00:05:28 +00:00
|
|
|
use common::comp::item::{
|
|
|
|
armor::{Armor, ArmorKind, Protection},
|
2020-08-01 20:08:30 +00:00
|
|
|
tool::{Tool, ToolKind},
|
2020-09-26 15:20:46 +00:00
|
|
|
ItemDesc, ItemKind,
|
2020-07-18 00:05:28 +00:00
|
|
|
};
|
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
pub fn loadout_slot_text<'a>(
|
2020-09-26 15:20:46 +00:00
|
|
|
item: Option<&'a impl ItemDesc>,
|
2020-07-18 00:05:28 +00:00
|
|
|
mut empty: impl FnMut() -> (&'a str, &'a str),
|
|
|
|
) -> (&'a str, Cow<'a, str>) {
|
|
|
|
item.map_or_else(
|
|
|
|
|| {
|
|
|
|
let (title, desc) = empty();
|
|
|
|
(title, Cow::Borrowed(desc))
|
|
|
|
},
|
|
|
|
item_text,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-09-26 15:20:46 +00:00
|
|
|
pub fn item_text<'a>(item: &'a impl ItemDesc) -> (&'_ str, Cow<'a, str>) {
|
2020-09-17 23:02:14 +00:00
|
|
|
let desc: Cow<str> = match item.kind() {
|
2020-08-07 05:25:51 +00:00
|
|
|
ItemKind::Armor(armor) => Cow::Owned(armor_desc(&armor, item.description())),
|
|
|
|
ItemKind::Tool(tool) => Cow::Owned(tool_desc(&tool, item.description())),
|
2020-07-18 00:05:28 +00:00
|
|
|
/*ItemKind::Consumable(kind, effect, ..) => {
|
|
|
|
Cow::Owned(consumable_desc(consumable, item.description()))
|
|
|
|
},*/
|
|
|
|
// ItemKind::Throwable => {},
|
|
|
|
// ItemKind::Utility => {},
|
|
|
|
// ItemKind::Ingredient => {},
|
|
|
|
// ItemKind::Lantern => {},
|
|
|
|
_ => Cow::Borrowed(item.description()),
|
|
|
|
};
|
|
|
|
|
|
|
|
(item.name(), desc)
|
|
|
|
}
|
2020-09-26 15:20:46 +00:00
|
|
|
|
2020-07-18 00:05:28 +00:00
|
|
|
// Armor Description
|
2020-08-07 05:25:51 +00:00
|
|
|
fn armor_desc(armor: &Armor, desc: &str) -> String {
|
2020-07-18 00:05:28 +00:00
|
|
|
// TODO: localization
|
|
|
|
let kind = match armor.kind {
|
|
|
|
ArmorKind::Shoulder(_) => "Shoulders",
|
|
|
|
ArmorKind::Chest(_) => "Chest",
|
|
|
|
ArmorKind::Belt(_) => "Belt",
|
|
|
|
ArmorKind::Hand(_) => "Hands",
|
|
|
|
ArmorKind::Pants(_) => "Legs",
|
|
|
|
ArmorKind::Foot(_) => "Feet",
|
|
|
|
ArmorKind::Back(_) => "Back",
|
|
|
|
ArmorKind::Ring(_) => "Ring",
|
|
|
|
ArmorKind::Neck(_) => "Neck",
|
|
|
|
ArmorKind::Head(_) => "Head",
|
|
|
|
ArmorKind::Tabard(_) => "Tabard",
|
|
|
|
};
|
|
|
|
let armor = match armor.get_protection() {
|
|
|
|
Protection::Normal(a) => a.to_string(),
|
|
|
|
Protection::Invincible => "Inf".to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if !desc.is_empty() {
|
|
|
|
format!(
|
|
|
|
"{}\n\nArmor: {}\n\n{}\n\n<Right-Click to use>",
|
|
|
|
kind, armor, desc
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!("{}\n\nArmor: {}\n\n<Right-Click to use>", kind, armor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Weapon/Tool Description
|
2020-08-07 05:25:51 +00:00
|
|
|
fn tool_desc(tool: &Tool, desc: &str) -> String {
|
2020-08-01 20:08:30 +00:00
|
|
|
// TODO: localization
|
|
|
|
let kind = match tool.kind {
|
|
|
|
ToolKind::Sword(_) => "Sword",
|
|
|
|
ToolKind::Axe(_) => "Axe",
|
|
|
|
ToolKind::Hammer(_) => "Hammer",
|
|
|
|
ToolKind::Bow(_) => "Bow",
|
|
|
|
ToolKind::Dagger(_) => "Dagger",
|
|
|
|
ToolKind::Staff(_) => "Staff",
|
2020-09-18 16:43:26 +00:00
|
|
|
ToolKind::Sceptre(_) => "Sceptre",
|
2020-08-01 20:08:30 +00:00
|
|
|
ToolKind::Shield(_) => "Shield",
|
2020-08-05 22:49:04 +00:00
|
|
|
ToolKind::NpcWeapon(_) => "Npc Weapon",
|
2020-08-01 20:08:30 +00:00
|
|
|
ToolKind::Debug(_) => "Debug",
|
|
|
|
ToolKind::Farming(_) => "Farming Tool",
|
|
|
|
ToolKind::Empty => "Empty",
|
|
|
|
};
|
|
|
|
let power = tool.base_power();
|
2020-07-18 00:05:28 +00:00
|
|
|
|
2020-08-01 20:08:30 +00:00
|
|
|
if !desc.is_empty() {
|
|
|
|
format!(
|
|
|
|
"{}\n\nPower: {:0.1}\n\n{}\n\n<Right-Click to use>",
|
|
|
|
kind,
|
|
|
|
power * 10.0,
|
|
|
|
desc
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"{}\n\nPower: {:0.1}\n\n<Right-Click to use>",
|
|
|
|
kind,
|
|
|
|
power * 10.0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 00:05:28 +00:00
|
|
|
// Consumable Description
|
|
|
|
/*fn consumable_desc(consumable: Consumable, desc: &str) -> String {
|
|
|
|
// TODO: localization
|
|
|
|
let kind = "Consumable";
|
|
|
|
if !desc.is_empty() {
|
|
|
|
format!("{}\n\n{}\n\n<Right-Click to use>", kind, desc)
|
|
|
|
} else {
|
|
|
|
format!("{}\n\n<Right-Click to use>", kind)
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// Throwable Description
|
|
|
|
|
|
|
|
// Utility Description
|
|
|
|
|
|
|
|
// Ingredient Description
|
|
|
|
|
|
|
|
// Lantern Description
|