Slightly simplify adding entries to game log
This commit is contained in:
parent
81f64b07a6
commit
69194a2dd6
@ -47,7 +47,7 @@ pub fn delete_the_dead(ecs: &mut World) {
|
|||||||
None => {
|
None => {
|
||||||
let victim_name = names.get(entity);
|
let victim_name = names.get(entity);
|
||||||
if let Some(victim_name) = victim_name {
|
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)
|
dead.push(entity)
|
||||||
|
@ -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());
|
self.entries.push(s.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ impl<'a> System<'a> for HungerSystem {
|
|||||||
clock.duration = 200;
|
clock.duration = 200;
|
||||||
|
|
||||||
if entity == *player_entity {
|
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 => {
|
HungerState::Normal => {
|
||||||
@ -54,7 +54,7 @@ impl<'a> System<'a> for HungerSystem {
|
|||||||
clock.duration = 200;
|
clock.duration = 200;
|
||||||
|
|
||||||
if entity == *player_entity {
|
if entity == *player_entity {
|
||||||
log.entries.push("You are hungry.".to_string());
|
log.append("You are hungry.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HungerState::Hungry => {
|
HungerState::Hungry => {
|
||||||
@ -62,14 +62,13 @@ impl<'a> System<'a> for HungerSystem {
|
|||||||
clock.duration = 200;
|
clock.duration = 200;
|
||||||
|
|
||||||
if entity == *player_entity {
|
if entity == *player_entity {
|
||||||
log.entries.push("You are starving!".to_string());
|
log.append("You are starving!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HungerState::Starving => {
|
HungerState::Starving => {
|
||||||
// Inflict damage from hunger
|
// Inflict damage from hunger
|
||||||
if entity == *player_entity {
|
if entity == *player_entity {
|
||||||
log.entries
|
log.append("Your hunger pangs are getting painful!");
|
||||||
.push("Your hunger pangs are getting painful!".to_string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SufferDamage::new_damage(&mut inflict_damage, entity, 1);
|
SufferDamage::new_damage(&mut inflict_damage, entity, 1);
|
||||||
|
@ -32,7 +32,7 @@ impl<'a> System<'a> for ItemCollectionSystem {
|
|||||||
.expect("Failed to add item to backpack");
|
.expect("Failed to add item to backpack");
|
||||||
|
|
||||||
if pickup.collected_by == *player_entity {
|
if pickup.collected_by == *player_entity {
|
||||||
gamelog.entries.push(format!(
|
gamelog.append(format!(
|
||||||
"You pick up the {}.",
|
"You pick up the {}.",
|
||||||
names.get(pickup.item).unwrap().name
|
names.get(pickup.item).unwrap().name
|
||||||
));
|
));
|
||||||
@ -157,7 +157,7 @@ impl<'a> System<'a> for ItemUseSystem {
|
|||||||
{
|
{
|
||||||
to_unequip.push(item_entity);
|
to_unequip.push(item_entity);
|
||||||
if target == *player_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");
|
.expect("Failed to equip item");
|
||||||
backpack.remove(useitem.item);
|
backpack.remove(useitem.item);
|
||||||
if target == *player_entity {
|
if target == *player_entity {
|
||||||
gamelog.entries.push(format!(
|
gamelog.append(format!(
|
||||||
"You equip {}.",
|
"You equip {}.",
|
||||||
names.get(useitem.item).unwrap().name
|
names.get(useitem.item).unwrap().name
|
||||||
));
|
));
|
||||||
@ -199,7 +199,7 @@ impl<'a> System<'a> for ItemUseSystem {
|
|||||||
hc.state = HungerState::WellFed;
|
hc.state = HungerState::WellFed;
|
||||||
hc.duration = 20;
|
hc.duration = 20;
|
||||||
|
|
||||||
gamelog.entries.push(format!(
|
gamelog.append(format!(
|
||||||
"You eat the {}.",
|
"You eat the {}.",
|
||||||
names.get(useitem.item).unwrap().name
|
names.get(useitem.item).unwrap().name
|
||||||
));
|
));
|
||||||
@ -218,7 +218,7 @@ impl<'a> System<'a> for ItemUseSystem {
|
|||||||
if let Some(stats) = stats {
|
if let Some(stats) = stats {
|
||||||
stats.hp = i32::min(stats.max_hp, stats.hp + healer.heal_amount);
|
stats.hp = i32::min(stats.max_hp, stats.hp + healer.heal_amount);
|
||||||
if entity == *player_entity {
|
if entity == *player_entity {
|
||||||
gamelog.entries.push(format!(
|
gamelog.append(format!(
|
||||||
"You drink the {}, healing {} hp.",
|
"You drink the {}, healing {} hp.",
|
||||||
names.get(useitem.item).unwrap().name,
|
names.get(useitem.item).unwrap().name,
|
||||||
healer.heal_amount
|
healer.heal_amount
|
||||||
@ -255,7 +255,7 @@ impl<'a> System<'a> for ItemUseSystem {
|
|||||||
let mob_name = names.get(*mob).unwrap();
|
let mob_name = names.get(*mob).unwrap();
|
||||||
let item_name = names.get(useitem.item).unwrap();
|
let item_name = names.get(useitem.item).unwrap();
|
||||||
|
|
||||||
gamelog.entries.push(format!(
|
gamelog.append(format!(
|
||||||
"You use {} on {}, inflicting {} hp.",
|
"You use {} on {}, inflicting {} hp.",
|
||||||
item_name.name, mob_name.name, damage.damage
|
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 mob_name = names.get(*mob).unwrap();
|
||||||
let item_name = names.get(useitem.item).unwrap();
|
let item_name = names.get(useitem.item).unwrap();
|
||||||
|
|
||||||
gamelog.entries.push(format!(
|
gamelog.append(format!(
|
||||||
"You use {} on {}, confusing them.",
|
"You use {} on {}, confusing them.",
|
||||||
item_name.name, mob_name.name
|
item_name.name, mob_name.name
|
||||||
));
|
));
|
||||||
@ -382,7 +382,7 @@ impl<'a> System<'a> for ItemDropSystem {
|
|||||||
backpack.remove(to_drop.item);
|
backpack.remove(to_drop.item);
|
||||||
|
|
||||||
if entity == *player_entity {
|
if entity == *player_entity {
|
||||||
gamelog.entries.push(format!(
|
gamelog.append(format!(
|
||||||
"You drop the {}.",
|
"You drop the {}.",
|
||||||
names.get(to_drop.item).unwrap().name
|
names.get(to_drop.item).unwrap().name
|
||||||
));
|
));
|
||||||
|
@ -81,12 +81,12 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if damage == 0 {
|
if damage == 0 {
|
||||||
log.entries.push(format!(
|
log.append(format!(
|
||||||
"{} is unable to hurt {}",
|
"{} is unable to hurt {}",
|
||||||
&name.name, &target_name.name
|
&name.name, &target_name.name
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
log.entries.push(format!(
|
log.append(format!(
|
||||||
"{} hits {}, for {} hp",
|
"{} hits {}, for {} hp",
|
||||||
&name.name, &target_name.name, damage
|
&name.name, &target_name.name, damage
|
||||||
));
|
));
|
||||||
|
Loading…
Reference in New Issue
Block a user