Event system now accepts any data and the GUI receives simpler events with data for them.
This commit is contained in:
parent
0e79288afc
commit
ed9d0de8e0
7 changed files with 45 additions and 57 deletions
37
gui.cpp
37
gui.cpp
|
@ -104,31 +104,30 @@ void GUI::handle_world_events() {
|
|||
auto player = $world.get_the<Player>();
|
||||
|
||||
while($world.has_event<eGUI>()) {
|
||||
auto [evt, entity] = $world.recv<eGUI>();
|
||||
switch(evt) {
|
||||
case eGUI::HIT: {
|
||||
auto combat = $world.get<Combat>(entity);
|
||||
auto [evt, entity, data] = $world.recv<eGUI>();
|
||||
|
||||
if(entity == player.entity) {
|
||||
$log.log(format("Enemy HIT YOU, you have {} HP!", combat.hp));
|
||||
switch(evt) {
|
||||
case eGUI::COMBAT: {
|
||||
auto &damage = std::any_cast<Events::Combat&>(data);
|
||||
auto enemy_combat = $world.get<Combat>(entity);
|
||||
|
||||
if(damage.enemy_did > 0) {
|
||||
$log.log(format("Enemy HIT YOU for {} damage!", damage.enemy_did));
|
||||
$log.log(format("-- Enemy has {} HP left.", enemy_combat.hp));
|
||||
$sounds.play("hit");
|
||||
} else {
|
||||
$log.log(format("You HIT enemy, they have {} HP!", combat.hp));
|
||||
$log.log("Enemy MISSED YOU.");
|
||||
}
|
||||
|
||||
if(damage.player_did > 0) {
|
||||
$log.log(format("You HIT enemy for {} damage!", damage.player_did));
|
||||
$sounds.play("hit");
|
||||
} else {
|
||||
$log.log("You MISSED the enemy.");
|
||||
}
|
||||
} break;
|
||||
case eGUI::MISS:
|
||||
if(entity == player.entity) {
|
||||
$log.log("You MISSED the enemy.");
|
||||
} else {
|
||||
$log.log("Enemy MISSED YOU.");
|
||||
}
|
||||
break;
|
||||
case eGUI::DEAD:
|
||||
$log.log("--- ENEMY DEAD!");
|
||||
break;
|
||||
case eGUI::LOOT: {
|
||||
auto loot = $world.get<Loot>(entity);
|
||||
auto &loot = std::any_cast<Loot&>(data);
|
||||
auto inventory = $world.get<Inventory>(player.entity);
|
||||
$log.log(format("You found {} gold. You have {} now.",
|
||||
loot.amount, inventory.gold));
|
||||
|
@ -182,7 +181,7 @@ void GUI::run_systems() {
|
|||
auto player = $world.get_the<Player>();
|
||||
System::enemy_pathing($world, $game_map, player);
|
||||
System::motion($world, $game_map);
|
||||
System::combat($world, player);
|
||||
System::collision($world, player);
|
||||
System::death($world);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue