Slightly simplify adding entries to game log

This commit is contained in:
Timothy Warren 2021-11-19 11:30:25 -05:00
parent 81f64b07a6
commit 69194a2dd6
5 changed files with 16 additions and 17 deletions

View File

@ -47,7 +47,7 @@ pub fn delete_the_dead(ecs: &mut World) {
None => {
let victim_name = names.get(entity);
if let Some(victim_name) = victim_name {
log.entries.push(format!("{} is dead", &victim_name.name));
log.append(format!("{} is dead", &victim_name.name));
}
dead.push(entity)

View File

@ -9,7 +9,7 @@ impl GameLog {
}
}
pub fn log<S: ToString>(&mut self, s: S) {
pub fn append<S: ToString>(&mut self, s: S) {
self.entries.push(s.to_string());
}
}

View File

@ -46,7 +46,7 @@ impl<'a> System<'a> for HungerSystem {
clock.duration = 200;
if entity == *player_entity {
log.entries.push("You are no longer well fed.".to_string());
log.append("You are no longer well fed.");
}
}
HungerState::Normal => {
@ -54,7 +54,7 @@ impl<'a> System<'a> for HungerSystem {
clock.duration = 200;
if entity == *player_entity {
log.entries.push("You are hungry.".to_string());
log.append("You are hungry.");
}
}
HungerState::Hungry => {
@ -62,14 +62,13 @@ impl<'a> System<'a> for HungerSystem {
clock.duration = 200;
if entity == *player_entity {
log.entries.push("You are starving!".to_string());
log.append("You are starving!");
}
}
HungerState::Starving => {
// Inflict damage from hunger
if entity == *player_entity {
log.entries
.push("Your hunger pangs are getting painful!".to_string());
log.append("Your hunger pangs are getting painful!");
}
SufferDamage::new_damage(&mut inflict_damage, entity, 1);

View File

@ -32,7 +32,7 @@ impl<'a> System<'a> for ItemCollectionSystem {
.expect("Failed to add item to backpack");
if pickup.collected_by == *player_entity {
gamelog.entries.push(format!(
gamelog.append(format!(
"You pick up the {}.",
names.get(pickup.item).unwrap().name
));
@ -157,7 +157,7 @@ impl<'a> System<'a> for ItemUseSystem {
{
to_unequip.push(item_entity);
if target == *player_entity {
gamelog.entries.push(format!("You unequip {}.", name.name));
gamelog.append(format!("You unequip {}.", name.name));
}
}
}
@ -180,7 +180,7 @@ impl<'a> System<'a> for ItemUseSystem {
.expect("Failed to equip item");
backpack.remove(useitem.item);
if target == *player_entity {
gamelog.entries.push(format!(
gamelog.append(format!(
"You equip {}.",
names.get(useitem.item).unwrap().name
));
@ -199,7 +199,7 @@ impl<'a> System<'a> for ItemUseSystem {
hc.state = HungerState::WellFed;
hc.duration = 20;
gamelog.entries.push(format!(
gamelog.append(format!(
"You eat the {}.",
names.get(useitem.item).unwrap().name
));
@ -218,7 +218,7 @@ impl<'a> System<'a> for ItemUseSystem {
if let Some(stats) = stats {
stats.hp = i32::min(stats.max_hp, stats.hp + healer.heal_amount);
if entity == *player_entity {
gamelog.entries.push(format!(
gamelog.append(format!(
"You drink the {}, healing {} hp.",
names.get(useitem.item).unwrap().name,
healer.heal_amount
@ -255,7 +255,7 @@ impl<'a> System<'a> for ItemUseSystem {
let mob_name = names.get(*mob).unwrap();
let item_name = names.get(useitem.item).unwrap();
gamelog.entries.push(format!(
gamelog.append(format!(
"You use {} on {}, inflicting {} hp.",
item_name.name, mob_name.name, damage.damage
));
@ -292,7 +292,7 @@ impl<'a> System<'a> for ItemUseSystem {
let mob_name = names.get(*mob).unwrap();
let item_name = names.get(useitem.item).unwrap();
gamelog.entries.push(format!(
gamelog.append(format!(
"You use {} on {}, confusing them.",
item_name.name, mob_name.name
));
@ -382,7 +382,7 @@ impl<'a> System<'a> for ItemDropSystem {
backpack.remove(to_drop.item);
if entity == *player_entity {
gamelog.entries.push(format!(
gamelog.append(format!(
"You drop the {}.",
names.get(to_drop.item).unwrap().name
));

View File

@ -81,12 +81,12 @@ impl<'a> System<'a> for MeleeCombatSystem {
);
if damage == 0 {
log.entries.push(format!(
log.append(format!(
"{} is unable to hurt {}",
&name.name, &target_name.name
));
} else {
log.entries.push(format!(
log.append(format!(
"{} hits {}, for {} hp",
&name.name, &target_name.name, damage
));