From 5e3a1b203f9b0e9e9128ff84ecbe92e66bf056d8 Mon Sep 17 00:00:00 2001 From: Lippy13 Date: Thu, 25 Feb 2021 16:25:39 +0000 Subject: [PATCH 1/7] Add buff information to item tooltips --- voxygen/src/hud/util.rs | 61 +++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index 7a470feaff..50d48d07b4 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -1,7 +1,13 @@ -use common::comp::item::{ - armor::{Armor, ArmorKind, Protection}, - tool::{Hands, StatKind, Stats, Tool, ToolKind}, - Item, ItemDesc, ItemKind, MaterialStatManifest, ModularComponent, +use common::{ + comp::{ + item::{ + armor::{Armor, ArmorKind, Protection}, + tool::{Hands, StatKind, Stats, Tool, ToolKind}, + Item, ItemDesc, ItemKind, MaterialStatManifest, ModularComponent, + }, + BuffKind, + }, + effect::Effect, }; use std::{borrow::Cow, fmt::Write}; @@ -40,7 +46,7 @@ pub fn item_text<'a>( item.description(), )), ItemKind::Glider(_glider) => Cow::Owned(glider_desc(item.description())), - ItemKind::Consumable { .. } => Cow::Owned(consumable_desc(item.description())), + ItemKind::Consumable { effect, .. } => Cow::Owned(consumable_desc(Some(effect), item.description())), ItemKind::Throwable { .. } => Cow::Owned(throwable_desc(item.description())), ItemKind::Utility { .. } => Cow::Owned(utility_desc(item.description())), ItemKind::Ingredient { .. } => Cow::Owned(ingredient_desc( @@ -78,8 +84,47 @@ fn modular_component_desc( } fn glider_desc(desc: &str) -> String { format!("Glider\n\n{}\n\n", desc) } -fn consumable_desc(desc: &str) -> String { - format!("Consumable\n\n{}\n\n", desc) +fn consumable_desc(maybe_effects: Option<&Vec>, desc: &str) -> String { + // TODO: localization + let mut description = format!( + "Consumable" + ); + + if let Some(effects) = maybe_effects { + for effect in effects { + match effect { + Effect::Buff(buff) => { + + let dur_secs = buff.data.duration.unwrap().as_secs_f32(); + let str_total = buff.data.strength * 0.1 * dur_secs; + + let buff_desc = match buff.kind { + BuffKind::Saturation { .. } => { + format!("Restores {} Health over {} seconds", str_total, dur_secs) + }, + BuffKind::Potion { .. } => { + format!("Restores {} Health", str_total) + }, + _ => { + String::new() + }, + }; + + if !buff_desc.is_empty() { + write!(&mut description, "\n\n{}", buff_desc).unwrap(); + } + }, + _ => (), + } + } + } + + if !desc.is_empty() { + write!(&mut description, "\n\n{}", desc).unwrap(); + } + + write!(&mut description, "\n\n").unwrap(); + description } fn throwable_desc(desc: &str) -> String { @@ -224,7 +269,7 @@ mod tests { assert_eq!( "Consumable\n\nmushrooms\n\n", - consumable_desc(item_description) + consumable_desc(None, item_description) ); } From 43c35f957fddbba2a7c663d0e41ce36c3876d5ea Mon Sep 17 00:00:00 2001 From: Lippy13 Date: Thu, 25 Feb 2021 16:49:29 +0000 Subject: [PATCH 2/7] Remove buff information from item description text --- assets/common/items/boss_drops/potions.ron | 2 +- assets/common/items/consumable/potion_big.ron | 2 +- assets/common/items/consumable/potion_med.ron | 2 +- assets/common/items/consumable/potion_minor.ron | 2 +- assets/common/items/crafting_ing/bowl.ron | 2 +- assets/common/items/food/apple.ron | 2 +- assets/common/items/food/apple_mushroom_curry.ron | 2 +- assets/common/items/food/apple_stick.ron | 2 +- assets/common/items/food/carrot.ron | 2 +- assets/common/items/food/cheese.ron | 2 +- assets/common/items/food/coconut.ron | 2 +- assets/common/items/food/coltsfoot.ron | 2 +- assets/common/items/food/dandelion.ron | 2 +- assets/common/items/food/fish.ron | 2 +- assets/common/items/food/garlic.ron | 2 +- assets/common/items/food/lettuce.ron | 2 +- assets/common/items/food/meat.ron | 2 +- assets/common/items/food/mushroom.ron | 2 +- assets/common/items/food/mushroom_stick.ron | 2 +- assets/common/items/food/onion.ron | 2 +- assets/common/items/food/plainsalad.ron | 2 +- assets/common/items/food/sage.ron | 2 +- assets/common/items/food/sunflower_icetea.ron | 2 +- assets/common/items/food/tomato.ron | 2 +- assets/common/items/food/tomatosalad.ron | 2 +- assets/common/items/ore/velorite.ron | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/assets/common/items/boss_drops/potions.ron b/assets/common/items/boss_drops/potions.ron index e53b76187e..2f786e3580 100644 --- a/assets/common/items/boss_drops/potions.ron +++ b/assets/common/items/boss_drops/potions.ron @@ -1,6 +1,6 @@ ItemDef( name: "Potent Potion", - description: "A potent healing potion.\n\nRestores 100 health on use", + description: "A potent healing potion.", kind: Consumable( kind: "Potion", effect: [ diff --git a/assets/common/items/consumable/potion_big.ron b/assets/common/items/consumable/potion_big.ron index 1373e1fa39..c0cac92a9b 100644 --- a/assets/common/items/consumable/potion_big.ron +++ b/assets/common/items/consumable/potion_big.ron @@ -1,6 +1,6 @@ ItemDef( name: "Large Potion", - description: "Restores 200 Health", + description: "", kind: Consumable( kind: "PotionLarge", effect: [ diff --git a/assets/common/items/consumable/potion_med.ron b/assets/common/items/consumable/potion_med.ron index 3e0a4a7272..df55a3ecdb 100644 --- a/assets/common/items/consumable/potion_med.ron +++ b/assets/common/items/consumable/potion_med.ron @@ -1,6 +1,6 @@ ItemDef( name: "Medium Potion", - description: "Restores 100 Health", + description: "", kind: Consumable( kind: "PotionMed", effect: [ diff --git a/assets/common/items/consumable/potion_minor.ron b/assets/common/items/consumable/potion_minor.ron index 3638e8ad6c..8f79da87b0 100644 --- a/assets/common/items/consumable/potion_minor.ron +++ b/assets/common/items/consumable/potion_minor.ron @@ -1,6 +1,6 @@ ItemDef( name: "Minor Potion", - description: "Restores 50 Health", + description: "", kind: Consumable( kind: "PotionMinor", effect: [ diff --git a/assets/common/items/crafting_ing/bowl.ron b/assets/common/items/crafting_ing/bowl.ron index deb2209fa4..2470fc4391 100644 --- a/assets/common/items/crafting_ing/bowl.ron +++ b/assets/common/items/crafting_ing/bowl.ron @@ -1,6 +1,6 @@ ItemDef( name: "Bowl", - description: "a simple bowl for preparing meals.", + description: "A simple bowl for preparing meals.", kind: Ingredient( kind: "Bowl", ), diff --git a/assets/common/items/food/apple.ron b/assets/common/items/food/apple.ron index 98c4c5c22c..7325a17485 100644 --- a/assets/common/items/food/apple.ron +++ b/assets/common/items/food/apple.ron @@ -1,6 +1,6 @@ ItemDef( name: "Apple", - description: "Restores 10 Health over 10 seconds\n\nRed and juicy", + description: "Red and juicy", kind: Consumable( kind: "Apple", effect: [ diff --git a/assets/common/items/food/apple_mushroom_curry.ron b/assets/common/items/food/apple_mushroom_curry.ron index 44ef1a8809..15b823c50a 100644 --- a/assets/common/items/food/apple_mushroom_curry.ron +++ b/assets/common/items/food/apple_mushroom_curry.ron @@ -1,6 +1,6 @@ ItemDef( name: "Mushroom Curry", - description: "Restores 120 Health over 10 seconds\n\nWho could say no to that?", + description: "Who could say no to that?", kind: Consumable( kind: "AppleShroomCurry", effect: [ diff --git a/assets/common/items/food/apple_stick.ron b/assets/common/items/food/apple_stick.ron index d320091e8c..0526517431 100644 --- a/assets/common/items/food/apple_stick.ron +++ b/assets/common/items/food/apple_stick.ron @@ -1,6 +1,6 @@ ItemDef( name: "Apple Stick", - description: "Restores 25 Health over 10 seconds\n\nThe stick makes it easier to carry!", + description: "The stick makes it easier to carry!", kind: Consumable( kind: "AppleStick", effect: [ diff --git a/assets/common/items/food/carrot.ron b/assets/common/items/food/carrot.ron index b8d72e5a81..26afc60568 100644 --- a/assets/common/items/food/carrot.ron +++ b/assets/common/items/food/carrot.ron @@ -1,6 +1,6 @@ ItemDef( name: "Carrot", - description: "Restores 10 Health over 20 seconds\n\nAn orange root vegetable. They say it'll improve your vision!", + description: "An orange root vegetable. They say it'll improve your vision!", kind: Consumable( kind: "Carrot", effect: [ diff --git a/assets/common/items/food/cheese.ron b/assets/common/items/food/cheese.ron index 5a3628d3c5..c245fb296b 100644 --- a/assets/common/items/food/cheese.ron +++ b/assets/common/items/food/cheese.ron @@ -1,6 +1,6 @@ ItemDef( name: "Dwarven Cheese", - description: "Restores 15 Health over 10 seconds\n\nAromatic and nutritious", + description: "Aromatic and nutritious", kind: Consumable( kind: "Cheese", effect: [ diff --git a/assets/common/items/food/coconut.ron b/assets/common/items/food/coconut.ron index bfef86d87a..795a77f014 100644 --- a/assets/common/items/food/coconut.ron +++ b/assets/common/items/food/coconut.ron @@ -1,6 +1,6 @@ ItemDef( name: "Coconut", - description: "Restores 20 health over 10 seconds\n\nReliable source of water and fat.\n\nNaturally growing at the top of palm trees.", + description: "Reliable source of water and fat.\n\nNaturally growing at the top of palm trees.", kind: Consumable( kind: "Coconut", effect: [ diff --git a/assets/common/items/food/coltsfoot.ron b/assets/common/items/food/coltsfoot.ron index 6d3e9e58a4..3b0f743995 100644 --- a/assets/common/items/food/coltsfoot.ron +++ b/assets/common/items/food/coltsfoot.ron @@ -1,6 +1,6 @@ ItemDef( name: "Coltsfoot", - description: "Restores 10 Health over 20 seconds\n\nA daisy-like flower often used in herbal teas.", + description: "A daisy-like flower often used in herbal teas.", kind: Consumable( kind: "Coltsfoot", effect: [ diff --git a/assets/common/items/food/dandelion.ron b/assets/common/items/food/dandelion.ron index 76874283ef..f2d2cbcfde 100644 --- a/assets/common/items/food/dandelion.ron +++ b/assets/common/items/food/dandelion.ron @@ -1,6 +1,6 @@ ItemDef( name: "Dandelion", - description: "Restores 10 Health over 20 seconds\n\nA small, yellow flower. Uses the wind to spread its seeds.", + description: "A small, yellow flower. Uses the wind to spread its seeds.", kind: Consumable( kind: "Dandelion", effect: [ diff --git a/assets/common/items/food/fish.ron b/assets/common/items/food/fish.ron index 39100fd3ef..72bcdb76fa 100644 --- a/assets/common/items/food/fish.ron +++ b/assets/common/items/food/fish.ron @@ -1,6 +1,6 @@ ItemDef( name: "Fish", - description: "Restores 10 Health over 20 seconds\n\nA fresh seafood steak, chopped from a fish.", + description: "A fresh seafood steak, chopped from a fish.", kind: Consumable( kind: "Fish", effect: [ diff --git a/assets/common/items/food/garlic.ron b/assets/common/items/food/garlic.ron index 2d5764d6da..4bd454fe92 100644 --- a/assets/common/items/food/garlic.ron +++ b/assets/common/items/food/garlic.ron @@ -1,6 +1,6 @@ ItemDef( name: "Garlic", - description: "Restores 10 Health over 20 seconds\n\nMake sure to brush your teeth after eating.", + description: "Make sure to brush your teeth after eating.", kind: Consumable( kind: "Garlic", effect: [ diff --git a/assets/common/items/food/lettuce.ron b/assets/common/items/food/lettuce.ron index 64c2a73ee7..532cfa6cd4 100644 --- a/assets/common/items/food/lettuce.ron +++ b/assets/common/items/food/lettuce.ron @@ -1,6 +1,6 @@ ItemDef( name: "Lettuce", - description: "Restores 10 Health over 20 seconds\n\nA vibrant green leafy vegetable. Lettuce make some salads!", + description: "A vibrant green leafy vegetable. Lettuce make some salads!", kind: Consumable( kind: "Lettuce", effect: [ diff --git a/assets/common/items/food/meat.ron b/assets/common/items/food/meat.ron index ca1042c262..711aa62d0e 100644 --- a/assets/common/items/food/meat.ron +++ b/assets/common/items/food/meat.ron @@ -1,6 +1,6 @@ ItemDef( name: "Meat", - description: "Restores 10 Health over 20 seconds\n\nMeat. The lifeblood of mankind.", + description: "Meat. The lifeblood of mankind.", kind: Consumable( kind: "Meat", effect: [ diff --git a/assets/common/items/food/mushroom.ron b/assets/common/items/food/mushroom.ron index 83099256a2..39714d2aad 100644 --- a/assets/common/items/food/mushroom.ron +++ b/assets/common/items/food/mushroom.ron @@ -1,6 +1,6 @@ ItemDef( name: "Mushroom", - description: "Restores 5 Health over 10 seconds\n\nHopefully this one is not poisonous", + description: "Hopefully this one is not poisonous", kind: Consumable( kind: "Mushroom", effect: [ diff --git a/assets/common/items/food/mushroom_stick.ron b/assets/common/items/food/mushroom_stick.ron index c547171df1..c399532d38 100644 --- a/assets/common/items/food/mushroom_stick.ron +++ b/assets/common/items/food/mushroom_stick.ron @@ -1,6 +1,6 @@ ItemDef( name: "Mushroom Stick", - description: "Restores 20 Health over 10 seconds\n\nRoasted mushrooms on a stick for easy carrying", + description: "Roasted mushrooms on a stick for easy carrying", kind: Consumable( kind: "MushroomStick", effect: [ diff --git a/assets/common/items/food/onion.ron b/assets/common/items/food/onion.ron index ccb363a63d..80e7cd6e3d 100644 --- a/assets/common/items/food/onion.ron +++ b/assets/common/items/food/onion.ron @@ -1,6 +1,6 @@ ItemDef( name: "Onion", - description: "Restores 10 Health over 20 seconds\n\nA vegetable that's made the toughest men cry.", + description: "A vegetable that's made the toughest men cry.", kind: Consumable( kind: "Onion", effect: [ diff --git a/assets/common/items/food/plainsalad.ron b/assets/common/items/food/plainsalad.ron index 7f0ccb4a5e..f7afca3202 100644 --- a/assets/common/items/food/plainsalad.ron +++ b/assets/common/items/food/plainsalad.ron @@ -1,6 +1,6 @@ ItemDef( name: "Plain Salad", - description: "Restores 20 Health over 20 seconds\n\nLiterally just chopped lettuce. Does this even count as a salad?", + description: "Literally just chopped lettuce. Does this even count as a salad?", kind: Consumable( kind: "PlainSalad", effect: [ diff --git a/assets/common/items/food/sage.ron b/assets/common/items/food/sage.ron index fece489d54..7e6f1f56da 100644 --- a/assets/common/items/food/sage.ron +++ b/assets/common/items/food/sage.ron @@ -1,6 +1,6 @@ ItemDef( name: "Sage", - description: "Restores 10 Health over 20 seconds\n\nAn herb commonly used in tea.", + description: "A herb commonly used in tea.", kind: Consumable( kind: "Sage", effect: [ diff --git a/assets/common/items/food/sunflower_icetea.ron b/assets/common/items/food/sunflower_icetea.ron index 3dd98e1cbc..bb65f252b0 100644 --- a/assets/common/items/food/sunflower_icetea.ron +++ b/assets/common/items/food/sunflower_icetea.ron @@ -1,6 +1,6 @@ ItemDef( name: "Sunflower Ice Tea", - description: "Restores 50 Health over 10 seconds\n\nBrewed from freshly shelled sunflower seeds", + description: "Brewed from freshly shelled sunflower seeds", kind: Consumable( kind: "SunflowerTea", effect: [ diff --git a/assets/common/items/food/tomato.ron b/assets/common/items/food/tomato.ron index 09c07e9205..a4e39753a8 100644 --- a/assets/common/items/food/tomato.ron +++ b/assets/common/items/food/tomato.ron @@ -1,6 +1,6 @@ ItemDef( name: "Tomato", - description: "Restores 10 Health over 20 seconds\n\nA red fruit. Not actually a vegetable.", + description: "A red fruit. Not actually a vegetable.", kind: Consumable( kind: "Tomato", effect: [ diff --git a/assets/common/items/food/tomatosalad.ron b/assets/common/items/food/tomatosalad.ron index 0893de237c..cf8c166d77 100644 --- a/assets/common/items/food/tomatosalad.ron +++ b/assets/common/items/food/tomatosalad.ron @@ -1,6 +1,6 @@ ItemDef( name: "Tomato Salad", - description: "Restores 30 Health over 20 seconds\n\nLeafy salad with some chopped, juicy tomatoes mixed in.", + description: "Leafy salad with some chopped, juicy tomatoes mixed in.", kind: Consumable( kind: "TomatoSalad", effect: [ diff --git a/assets/common/items/ore/velorite.ron b/assets/common/items/ore/velorite.ron index a9d5fcdd79..4ca6d138c8 100644 --- a/assets/common/items/ore/velorite.ron +++ b/assets/common/items/ore/velorite.ron @@ -1,6 +1,6 @@ ItemDef( name: "Velorite", - description: "Just a slight touch makes you feel\n\the knowledge of ancient times", + description: "Just a slight touch makes you feel\nthe knowledge of ancient times", kind: Ingredient( kind: "Velorite", ), From ffd0c01bbdce4e9cb85b49b4105d9dc93c75cf57 Mon Sep 17 00:00:00 2001 From: Lippy13 Date: Thu, 25 Feb 2021 17:22:30 +0000 Subject: [PATCH 3/7] Fix Clippy errors Fix code formatting Add descriptions for other potential buffs for consumables --- voxygen/src/hud/util.rs | 57 +++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index 50d48d07b4..877b863f8e 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -46,7 +46,9 @@ pub fn item_text<'a>( item.description(), )), ItemKind::Glider(_glider) => Cow::Owned(glider_desc(item.description())), - ItemKind::Consumable { effect, .. } => Cow::Owned(consumable_desc(Some(effect), item.description())), + ItemKind::Consumable { effect, .. } => { + Cow::Owned(consumable_desc(Some(effect), item.description())) + }, ItemKind::Throwable { .. } => Cow::Owned(throwable_desc(item.description())), ItemKind::Utility { .. } => Cow::Owned(utility_desc(item.description())), ItemKind::Ingredient { .. } => Cow::Owned(ingredient_desc( @@ -86,35 +88,40 @@ fn glider_desc(desc: &str) -> String { format!("Glider\n\n{}\n\n>, desc: &str) -> String { // TODO: localization - let mut description = format!( - "Consumable" - ); + let mut description = "Consumable".to_string(); if let Some(effects) = maybe_effects { for effect in effects { - match effect { - Effect::Buff(buff) => { + if let Effect::Buff(buff) = effect { + let strength = buff.data.strength * 0.1; + let dur_secs = buff.data.duration.unwrap().as_secs_f32(); + let str_total = strength * dur_secs; - let dur_secs = buff.data.duration.unwrap().as_secs_f32(); - let str_total = buff.data.strength * 0.1 * dur_secs; + let buff_desc = match buff.kind { + BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => { + format!("Restores {} Health over {} seconds", str_total, dur_secs) + }, + BuffKind::Potion { .. } => { + format!("Restores {} Health", str_total) + }, + BuffKind::IncreaseMaxEnergy { .. } => { + format!( + "Raises Maximum Stamina by {} for {} seconds", + strength, dur_secs + ) + }, + BuffKind::IncreaseMaxHealth { .. } => { + format!( + "Raises Maximum Health by {} for {} seconds", + strength, dur_secs + ) + }, + _ => String::new(), + }; - let buff_desc = match buff.kind { - BuffKind::Saturation { .. } => { - format!("Restores {} Health over {} seconds", str_total, dur_secs) - }, - BuffKind::Potion { .. } => { - format!("Restores {} Health", str_total) - }, - _ => { - String::new() - }, - }; - - if !buff_desc.is_empty() { - write!(&mut description, "\n\n{}", buff_desc).unwrap(); - } - }, - _ => (), + if !buff_desc.is_empty() { + write!(&mut description, "\n\n{}", buff_desc).unwrap(); + } } } } From a7c30b672163ec37e177e300add744996d8d564f Mon Sep 17 00:00:00 2001 From: Lippy13 Date: Tue, 2 Mar 2021 23:31:47 +0000 Subject: [PATCH 4/7] Account for no duration being possible --- voxygen/src/hud/util.rs | 62 ++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index 877b863f8e..e3b57ae12f 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -94,33 +94,63 @@ fn consumable_desc(maybe_effects: Option<&Vec>, desc: &str) -> String { for effect in effects { if let Effect::Buff(buff) = effect { let strength = buff.data.strength * 0.1; - let dur_secs = buff.data.duration.unwrap().as_secs_f32(); - let str_total = strength * dur_secs; + let dur_secs = match buff.data.duration { + Some(dur_secs) => dur_secs.as_secs_f32(), + None => 0.0, + }; + + let str_total = { + if dur_secs > 0.0 { + strength * dur_secs + } else { + strength + } + }; let buff_desc = match buff.kind { - BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => { - format!("Restores {} Health over {} seconds", str_total, dur_secs) - }, - BuffKind::Potion { .. } => { + BuffKind::Saturation { .. } + | BuffKind::Regeneration { .. } + | BuffKind::Potion { .. } => { format!("Restores {} Health", str_total) }, BuffKind::IncreaseMaxEnergy { .. } => { - format!( - "Raises Maximum Stamina by {} for {} seconds", - strength, dur_secs - ) + format!("Raises Maximum Stamina by {}", strength) }, BuffKind::IncreaseMaxHealth { .. } => { - format!( - "Raises Maximum Health by {} for {} seconds", - strength, dur_secs - ) + format!("Raises Maximum Health by {}", strength) }, _ => String::new(), }; - if !buff_desc.is_empty() { - write!(&mut description, "\n\n{}", buff_desc).unwrap(); + if buff_desc.is_empty() { + continue; + } + + write!(&mut description, "\n\n{}", buff_desc).unwrap(); + + // The Potion buff has no real duration + if let BuffKind::Potion { .. } = buff.kind { + continue; + } + + let dur_desc = { + if dur_secs > 0.0 { + match buff.kind { + BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => { + format!("over {} seconds", dur_secs) + }, + BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxHealth { .. } => { + format!("for {} seconds", dur_secs) + }, + _ => String::new(), + } + } else { + "every second".to_string() + } + }; + + if !dur_desc.is_empty() { + write!(&mut description, " {}", dur_desc).unwrap(); } } } From 48f974bf015dd6ea4ec74cee0b16e41af02a69c4 Mon Sep 17 00:00:00 2001 From: Lippy13 Date: Tue, 2 Mar 2021 23:53:21 +0000 Subject: [PATCH 5/7] Address comments on passing effects --- voxygen/src/hud/util.rs | 120 ++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 61 deletions(-) diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index e3b57ae12f..fb564e33ae 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -47,7 +47,7 @@ pub fn item_text<'a>( )), ItemKind::Glider(_glider) => Cow::Owned(glider_desc(item.description())), ItemKind::Consumable { effect, .. } => { - Cow::Owned(consumable_desc(Some(effect), item.description())) + Cow::Owned(consumable_desc(effect, item.description())) }, ItemKind::Throwable { .. } => Cow::Owned(throwable_desc(item.description())), ItemKind::Utility { .. } => Cow::Owned(utility_desc(item.description())), @@ -86,72 +86,70 @@ fn modular_component_desc( } fn glider_desc(desc: &str) -> String { format!("Glider\n\n{}\n\n", desc) } -fn consumable_desc(maybe_effects: Option<&Vec>, desc: &str) -> String { +fn consumable_desc(effects: &[Effect], desc: &str) -> String { // TODO: localization let mut description = "Consumable".to_string(); - if let Some(effects) = maybe_effects { - for effect in effects { - if let Effect::Buff(buff) = effect { - let strength = buff.data.strength * 0.1; - let dur_secs = match buff.data.duration { - Some(dur_secs) => dur_secs.as_secs_f32(), - None => 0.0, - }; + for effect in effects { + if let Effect::Buff(buff) = effect { + let strength = buff.data.strength * 0.1; + let dur_secs = match buff.data.duration { + Some(dur_secs) => dur_secs.as_secs_f32(), + None => 0.0, + }; - let str_total = { - if dur_secs > 0.0 { - strength * dur_secs - } else { - strength + let str_total = { + if dur_secs > 0.0 { + strength * dur_secs + } else { + strength + } + }; + + let buff_desc = match buff.kind { + BuffKind::Saturation { .. } + | BuffKind::Regeneration { .. } + | BuffKind::Potion { .. } => { + format!("Restores {} Health", str_total) + }, + BuffKind::IncreaseMaxEnergy { .. } => { + format!("Raises Maximum Stamina by {}", strength) + }, + BuffKind::IncreaseMaxHealth { .. } => { + format!("Raises Maximum Health by {}", strength) + }, + _ => String::new(), + }; + + if buff_desc.is_empty() { + continue; + } + + write!(&mut description, "\n\n{}", buff_desc).unwrap(); + + // The Potion buff has no real duration + if let BuffKind::Potion { .. } = buff.kind { + continue; + } + + let dur_desc = { + if dur_secs > 0.0 { + match buff.kind { + BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => { + format!("over {} seconds", dur_secs) + }, + BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxHealth { .. } => { + format!("for {} seconds", dur_secs) + }, + _ => String::new(), } - }; - - let buff_desc = match buff.kind { - BuffKind::Saturation { .. } - | BuffKind::Regeneration { .. } - | BuffKind::Potion { .. } => { - format!("Restores {} Health", str_total) - }, - BuffKind::IncreaseMaxEnergy { .. } => { - format!("Raises Maximum Stamina by {}", strength) - }, - BuffKind::IncreaseMaxHealth { .. } => { - format!("Raises Maximum Health by {}", strength) - }, - _ => String::new(), - }; - - if buff_desc.is_empty() { - continue; + } else { + "every second".to_string() } + }; - write!(&mut description, "\n\n{}", buff_desc).unwrap(); - - // The Potion buff has no real duration - if let BuffKind::Potion { .. } = buff.kind { - continue; - } - - let dur_desc = { - if dur_secs > 0.0 { - match buff.kind { - BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => { - format!("over {} seconds", dur_secs) - }, - BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxHealth { .. } => { - format!("for {} seconds", dur_secs) - }, - _ => String::new(), - } - } else { - "every second".to_string() - } - }; - - if !dur_desc.is_empty() { - write!(&mut description, " {}", dur_desc).unwrap(); - } + if !dur_desc.is_empty() { + write!(&mut description, " {}", dur_desc).unwrap(); } } } @@ -306,7 +304,7 @@ mod tests { assert_eq!( "Consumable\n\nmushrooms\n\n", - consumable_desc(None, item_description) + consumable_desc(&[], item_description) ); } From 59594a8b60e5de643347a8f90f264860093c01c9 Mon Sep 17 00:00:00 2001 From: Lippy13 Date: Wed, 3 Mar 2021 20:31:17 +0000 Subject: [PATCH 6/7] Check if duration exists instead of defaulting to zero and clean up code --- voxygen/src/hud/util.rs | 63 +++++++++++++---------------------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index fb564e33ae..66b6eebbe1 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -93,64 +93,41 @@ fn consumable_desc(effects: &[Effect], desc: &str) -> String { for effect in effects { if let Effect::Buff(buff) = effect { let strength = buff.data.strength * 0.1; - let dur_secs = match buff.data.duration { - Some(dur_secs) => dur_secs.as_secs_f32(), - None => 0.0, - }; - - let str_total = { - if dur_secs > 0.0 { - strength * dur_secs - } else { - strength - } - }; + let dur_secs = buff.data.duration.map(|d| d.as_secs_f32()); + let str_total = dur_secs.map_or(strength, |secs| strength * secs); let buff_desc = match buff.kind { - BuffKind::Saturation { .. } - | BuffKind::Regeneration { .. } - | BuffKind::Potion { .. } => { + BuffKind::Saturation | BuffKind::Regeneration | BuffKind::Potion => { format!("Restores {} Health", str_total) }, - BuffKind::IncreaseMaxEnergy { .. } => { + BuffKind::IncreaseMaxEnergy => { format!("Raises Maximum Stamina by {}", strength) }, - BuffKind::IncreaseMaxHealth { .. } => { + BuffKind::IncreaseMaxHealth => { format!("Raises Maximum Health by {}", strength) }, - _ => String::new(), + _ => continue, }; - if buff_desc.is_empty() { - continue; - } - write!(&mut description, "\n\n{}", buff_desc).unwrap(); - // The Potion buff has no real duration - if let BuffKind::Potion { .. } = buff.kind { - continue; - } - - let dur_desc = { - if dur_secs > 0.0 { - match buff.kind { - BuffKind::Saturation { .. } | BuffKind::Regeneration { .. } => { - format!("over {} seconds", dur_secs) - }, - BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxHealth { .. } => { - format!("for {} seconds", dur_secs) - }, - _ => String::new(), - } - } else { - "every second".to_string() + let dur_desc = if dur_secs.is_some() { + match buff.kind { + BuffKind::Saturation | BuffKind::Regeneration => { + format!("over {} seconds", dur_secs.unwrap()) + }, + BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxHealth => { + format!("for {} seconds", dur_secs.unwrap()) + }, + _ => continue, } + } else if let BuffKind::Saturation | BuffKind::Regeneration = buff.kind { + "every second".to_string() + } else { + continue; }; - if !dur_desc.is_empty() { - write!(&mut description, " {}", dur_desc).unwrap(); - } + write!(&mut description, " {}", dur_desc).unwrap(); } } From d9d3c1f55be83732f569da547a00424479a7a112 Mon Sep 17 00:00:00 2001 From: Lippy13 Date: Wed, 3 Mar 2021 21:10:41 +0000 Subject: [PATCH 7/7] Make the BuffKind match expression exhaustive --- voxygen/src/hud/util.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index 66b6eebbe1..e7740815f8 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -106,7 +106,8 @@ fn consumable_desc(effects: &[Effect], desc: &str) -> String { BuffKind::IncreaseMaxHealth => { format!("Raises Maximum Health by {}", strength) }, - _ => continue, + BuffKind::Invulnerability => "Grants invulnerability".to_string(), + BuffKind::Bleeding | BuffKind::CampfireHeal | BuffKind::Cursed => continue, }; write!(&mut description, "\n\n{}", buff_desc).unwrap(); @@ -116,10 +117,15 @@ fn consumable_desc(effects: &[Effect], desc: &str) -> String { BuffKind::Saturation | BuffKind::Regeneration => { format!("over {} seconds", dur_secs.unwrap()) }, - BuffKind::IncreaseMaxEnergy | BuffKind::IncreaseMaxHealth => { + BuffKind::IncreaseMaxEnergy + | BuffKind::IncreaseMaxHealth + | BuffKind::Invulnerability => { format!("for {} seconds", dur_secs.unwrap()) }, - _ => continue, + BuffKind::Bleeding + | BuffKind::Potion + | BuffKind::CampfireHeal + | BuffKind::Cursed => continue, } } else if let BuffKind::Saturation | BuffKind::Regeneration = buff.kind { "every second".to_string()