diff --git a/src/components.rs b/src/components.rs index 8c56cce..522b235 100644 --- a/src/components.rs +++ b/src/components.rs @@ -427,11 +427,39 @@ pub enum Intrinsic { Speed, // 4/3x speed multiplier } +impl Intrinsic { + pub fn describe(&self) -> &str { + match self { + Intrinsic::Regeneration => "regenerates health", + Intrinsic::Speed => "is hasted", + } + } +} + #[derive(Component, Serialize, Deserialize, Debug, Clone)] pub struct Intrinsics { pub list: HashSet, } +impl Intrinsics { + pub fn describe(&self) -> String { + let mut descriptions = Vec::new(); + for intrinsic in &self.list { + descriptions.push(intrinsic.describe()); + } + match descriptions.len() { + 0 => + unreachable!("describe() should never be called on an empty Intrinsics component."), + 1 => format!("It {}.", descriptions[0]), + _ => { + let last = descriptions.pop().unwrap(); + let joined = descriptions.join(", "); + format!("It {}, and {}.", joined, last) + } + } + } +} + #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct InflictsDamage { pub damage_type: DamageType, diff --git a/src/gui/tooltip.rs b/src/gui/tooltip.rs index e11d50f..94c3f97 100644 --- a/src/gui/tooltip.rs +++ b/src/gui/tooltip.rs @@ -111,6 +111,12 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) { if position.x == mouse_pos_adjusted.0 && position.y == mouse_pos_adjusted.1 { let mut tip = Tooltip::new(); tip.add(crate::gui::obfuscate_name_ecs(ecs, entity).0, renderable.fg); + let intrinsics = ecs.read_storage::(); + if let Some(intrinsics) = intrinsics.get(entity) { + if !intrinsics.list.is_empty() { + tip.add(intrinsics.describe(), RGB::named(WHITE)); + } + } // Attributes let attr = attributes.get(entity); if let Some(a) = attr {