GUI is now decoupled from the ECS using the new DinkyECS event queues. That makes it easier to update and change the GUI without having to constantly alter the systems.

This commit is contained in:
Zed A. Shaw 2024-10-29 18:33:11 -04:00
parent da8011cb14
commit 04350cb51e
4 changed files with 58 additions and 16 deletions

View file

@ -4,7 +4,7 @@
#include <cmath>
#include "rand.hpp"
#include "collider.hpp"
#include "sound.hpp"
#include "events.hpp"
using std::string;
using namespace fmt;
@ -84,13 +84,10 @@ void System::death(DinkyECS::World &world) {
});
}
void System::combat(DinkyECS::World &world, Player &player) {
auto& collider = world.get_the<spatial_map>();
const auto& player_position = world.get<Position>(player.entity);
auto& player_combat = world.get<Combat>(player.entity);
auto& log = world.get_the<ActionLog>();
auto& sounds = world.get_the<SoundManager>();
// this is guaranteed to not return the given position
auto [found, nearby] = collider.neighbors(player_position.location);
@ -101,23 +98,21 @@ void System::combat(DinkyECS::World &world, Player &player) {
int player_dmg = player_combat.attack(enemy_combat);
if(player_dmg > 0) {
log.log(format("You HIT for {} damage, HP left {}.", player_dmg, enemy_combat.hp));
sounds.play("hit");
world.send<GUIEvent>(GUIEvent::HIT, entity);
} else {
log.log("You missed! They're quick!");
world.send<GUIEvent>(GUIEvent::MISS, entity);
}
if(enemy_combat.hp > 0) {
int enemy_dmg = enemy_combat.attack(player_combat);
if(enemy_dmg > 0) {
sounds.play("hit");
log.log(format("Enemy HIT YOU for {} damage.", enemy_dmg));
world.send<GUIEvent>(GUIEvent::HIT, player.entity);
} else {
log.log("Enemy MISSED, you dodged it.");
world.send<GUIEvent>(GUIEvent::MISS, player.entity);
}
} else {
log.log("ENEMY DEAD! YOU WIN!");
world.send<GUIEvent>(GUIEvent::DEAD, entity);
}
}
}