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
|
|
|
};
|
2021-01-08 19:12:09 +00:00
|
|
|
use std::{borrow::Cow, fmt::Write};
|
2020-07-18 00:05:28 +00:00
|
|
|
|
|
|
|
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() {
|
2021-01-08 19:12:09 +00:00
|
|
|
ItemKind::Armor(armor) => {
|
|
|
|
Cow::Owned(armor_desc(armor, item.description(), item.num_slots()))
|
|
|
|
},
|
2020-08-07 05:25:51 +00:00
|
|
|
ItemKind::Tool(tool) => Cow::Owned(tool_desc(&tool, item.description())),
|
2020-10-07 02:23:20 +00:00
|
|
|
ItemKind::Glider(_glider) => Cow::Owned(glider_desc(item.description())),
|
|
|
|
ItemKind::Consumable { .. } => Cow::Owned(consumable_desc(item.description())),
|
|
|
|
ItemKind::Throwable { .. } => Cow::Owned(throwable_desc(item.description())),
|
|
|
|
ItemKind::Utility { .. } => Cow::Owned(utility_desc(item.description())),
|
|
|
|
ItemKind::Ingredient { .. } => Cow::Owned(ingredient_desc(item.description())),
|
|
|
|
ItemKind::Lantern { .. } => Cow::Owned(lantern_desc(item.description())),
|
2021-02-16 01:05:54 +00:00
|
|
|
ItemKind::TagExamples { .. } => Cow::Borrowed(item.description()),
|
2020-10-07 02:23:20 +00:00
|
|
|
//_ => Cow::Borrowed(item.description()),
|
2020-07-18 00:05:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
(item.name(), desc)
|
|
|
|
}
|
2020-09-26 15:20:46 +00:00
|
|
|
|
2020-11-15 23:53:20 +00:00
|
|
|
// TODO: localization
|
2020-10-07 02:23:20 +00:00
|
|
|
fn glider_desc(desc: &str) -> String { format!("Glider\n\n{}\n\n<Right-Click to use>", desc) }
|
|
|
|
|
|
|
|
fn consumable_desc(desc: &str) -> String {
|
|
|
|
format!("Consumable\n\n{}\n\n<Right-Click to use>", desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn throwable_desc(desc: &str) -> String {
|
|
|
|
format!("Can be thrown\n\n{}\n\n<Right-Click to use>", desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn utility_desc(desc: &str) -> String { format!("{}\n\n<Right-Click to use>", desc) }
|
|
|
|
|
|
|
|
fn ingredient_desc(desc: &str) -> String { format!("Crafting Ingredient\n\n{}", desc) }
|
|
|
|
|
|
|
|
fn lantern_desc(desc: &str) -> String { format!("Lantern\n\n{}\n\n<Right-Click to use>", desc) }
|
|
|
|
|
2021-01-08 19:12:09 +00:00
|
|
|
fn armor_desc(armor: &Armor, desc: &str, slots: u16) -> 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",
|
2021-01-08 19:12:09 +00:00
|
|
|
ArmorKind::Bag(_) => "Bag",
|
2020-07-18 00:05:28 +00:00
|
|
|
};
|
2021-01-13 03:26:51 +00:00
|
|
|
let armor_protection = match armor.get_protection() {
|
|
|
|
Protection::Normal(a) => a.to_string(),
|
|
|
|
Protection::Invincible => "Inf".to_string(),
|
|
|
|
};
|
2021-01-27 03:05:13 +00:00
|
|
|
//let armor_poise_resilience = match armor.get_poise_resilience() {
|
2021-01-26 04:16:28 +00:00
|
|
|
// Protection::Normal(a) => a.to_string(),
|
|
|
|
// Protection::Invincible => "Inf".to_string(),
|
|
|
|
//};
|
2020-07-18 00:05:28 +00:00
|
|
|
|
2021-01-13 03:26:51 +00:00
|
|
|
let mut description = format!(
|
2021-01-26 04:16:28 +00:00
|
|
|
"{}\n\nArmor: {}",
|
2021-01-27 03:05:13 +00:00
|
|
|
//"{}\n\nArmor: {}\n\nPoise Resilience: {}",
|
2021-01-26 04:16:28 +00:00
|
|
|
kind,
|
2021-01-27 03:05:13 +00:00
|
|
|
armor_protection, /* armor_poise_resilience // Add back when we are ready for poise */
|
2021-01-13 03:26:51 +00:00
|
|
|
);
|
2021-01-08 19:12:09 +00:00
|
|
|
|
2020-07-18 00:05:28 +00:00
|
|
|
if !desc.is_empty() {
|
2021-01-08 19:12:09 +00:00
|
|
|
write!(&mut description, "\n\n{}", desc).unwrap();
|
2020-07-18 00:05:28 +00:00
|
|
|
}
|
2021-01-08 19:12:09 +00:00
|
|
|
|
|
|
|
if slots > 0 {
|
|
|
|
write!(&mut description, "\n\nSlots: {}", slots).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
write!(&mut description, "\n\n<Right-Click to use>").unwrap();
|
|
|
|
description
|
2020-07-18 00:05:28 +00:00
|
|
|
}
|
2020-11-15 23:53:20 +00:00
|
|
|
|
2020-08-07 05:25:51 +00:00
|
|
|
fn tool_desc(tool: &Tool, desc: &str) -> String {
|
2020-08-01 20:08:30 +00:00
|
|
|
let kind = match tool.kind {
|
2020-11-06 17:39:49 +00:00
|
|
|
ToolKind::Sword => "Sword",
|
|
|
|
ToolKind::Axe => "Axe",
|
|
|
|
ToolKind::Hammer => "Hammer",
|
|
|
|
ToolKind::Bow => "Bow",
|
|
|
|
ToolKind::Dagger => "Dagger",
|
|
|
|
ToolKind::Staff => "Staff",
|
|
|
|
ToolKind::Sceptre => "Sceptre",
|
|
|
|
ToolKind::Shield => "Shield",
|
|
|
|
ToolKind::Unique(_) => "Unique",
|
|
|
|
ToolKind::Debug => "Debug",
|
|
|
|
ToolKind::Farming => "Farming Tool",
|
2020-08-01 20:08:30 +00:00
|
|
|
ToolKind::Empty => "Empty",
|
|
|
|
};
|
2021-01-13 03:26:51 +00:00
|
|
|
|
|
|
|
// Get tool stats
|
2020-08-01 20:08:30 +00:00
|
|
|
let power = tool.base_power();
|
2021-01-27 03:05:13 +00:00
|
|
|
//let poise_strength = tool.base_poise_strength();
|
2020-11-06 15:51:32 +00:00
|
|
|
let speed = tool.base_speed();
|
2020-07-18 00:05:28 +00:00
|
|
|
|
2020-08-01 20:08:30 +00:00
|
|
|
if !desc.is_empty() {
|
|
|
|
format!(
|
2021-01-26 04:16:28 +00:00
|
|
|
"{}\n\nDPS: {:0.1}\n\nPower: {:0.1}\n\nSpeed: {:0.1}\n\n{}\n\n<Right-Click to use>",
|
|
|
|
// add back when ready for poise
|
2021-01-27 03:05:13 +00:00
|
|
|
//"{}\n\nDPS: {:0.1}\n\nPower: {:0.1}\n\nPoise Strength: {:0.1}\n\nSpeed: \
|
2021-01-26 04:16:28 +00:00
|
|
|
// {:0.1}\n\n{}\n\n<Right-Click to use>",
|
2020-08-01 20:08:30 +00:00
|
|
|
kind,
|
2021-01-23 22:10:15 +00:00
|
|
|
speed * power * 10.0, // Damage per second
|
2020-08-01 20:08:30 +00:00
|
|
|
power * 10.0,
|
2021-01-27 03:05:13 +00:00
|
|
|
//poise_strength * 10.0,
|
2020-11-08 13:10:27 +00:00
|
|
|
speed,
|
2020-08-01 20:08:30 +00:00
|
|
|
desc
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!(
|
2021-01-26 04:16:28 +00:00
|
|
|
"{}\n\nDPS: {:0.1}\n\nPower: {:0.1}\n\nSpeed: {:0.1}\n\n<Right-Click to use>",
|
|
|
|
// add back when ready for poise
|
2021-01-27 03:05:13 +00:00
|
|
|
//"{}\n\nDPS: {:0.1}\n\nPower: {:0.1}\n\nPoise Strength: {:0.1}\n\nSpeed: \
|
2021-01-26 04:16:28 +00:00
|
|
|
// {:0.1}\n\n<Right-Click to use>",
|
2020-08-01 20:08:30 +00:00
|
|
|
kind,
|
2021-01-23 22:10:15 +00:00
|
|
|
speed * power * 10.0, // Damage per second
|
2020-11-06 15:51:32 +00:00
|
|
|
power * 10.0,
|
2021-01-27 03:05:13 +00:00
|
|
|
//poise_strength * 10.0,
|
2020-11-08 13:10:27 +00:00
|
|
|
speed
|
2020-08-01 20:08:30 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-11-15 23:53:20 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_glider_desc() {
|
|
|
|
let item_description = "mushrooms";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
"Glider\n\nmushrooms\n\n<Right-Click to use>",
|
|
|
|
glider_desc(item_description)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_consumable_desc() {
|
|
|
|
let item_description = "mushrooms";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
"Consumable\n\nmushrooms\n\n<Right-Click to use>",
|
|
|
|
consumable_desc(item_description)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_throwable_desc() {
|
|
|
|
let item_description = "mushrooms";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
"Can be thrown\n\nmushrooms\n\n<Right-Click to use>",
|
|
|
|
throwable_desc(item_description)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_utility_desc() {
|
|
|
|
let item_description = "mushrooms";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
"mushrooms\n\n<Right-Click to use>",
|
|
|
|
utility_desc(item_description)
|
|
|
|
);
|
2020-07-18 00:05:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 23:53:20 +00:00
|
|
|
#[test]
|
|
|
|
fn test_ingredient_desc() {
|
|
|
|
let item_description = "mushrooms";
|
2020-07-18 00:05:28 +00:00
|
|
|
|
2020-11-15 23:53:20 +00:00
|
|
|
assert_eq!(
|
|
|
|
"Crafting Ingredient\n\nmushrooms",
|
|
|
|
ingredient_desc(item_description)
|
|
|
|
);
|
|
|
|
}
|
2020-07-18 00:05:28 +00:00
|
|
|
|
2020-11-15 23:53:20 +00:00
|
|
|
#[test]
|
|
|
|
fn test_lantern_desc() {
|
|
|
|
let item_description = "mushrooms";
|
2020-07-18 00:05:28 +00:00
|
|
|
|
2020-11-15 23:53:20 +00:00
|
|
|
assert_eq!(
|
|
|
|
"Lantern\n\nmushrooms\n\n<Right-Click to use>",
|
|
|
|
lantern_desc(item_description)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|