.describe() for Intrinsics, for use in tooltips later
This commit is contained in:
parent
190543a361
commit
b5743819ec
2 changed files with 34 additions and 0 deletions
|
|
@ -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<Intrinsic>,
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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::<crate::components::Intrinsics>();
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue