First step in refactoring to allow for multiple levels. Next is to clean up the APIs and sort out how things will be notified that they have to switch levels.
This commit is contained in:
parent
3344181a47
commit
c14efee9ea
9 changed files with 100 additions and 96 deletions
52
gui.cpp
52
gui.cpp
|
@ -193,13 +193,11 @@ void MapViewUI::resize_canvas() {
|
|||
$canvas = Canvas(width * 2, height * 4);
|
||||
}
|
||||
|
||||
GUI::GUI(DinkyECS::World &world, Map& game_map) :
|
||||
$world(world),
|
||||
$game_map(game_map),
|
||||
$status_ui(world),
|
||||
$lights(game_map.width(), game_map.height()),
|
||||
$map_view($world, $lights, $game_map),
|
||||
$inventory_ui(world),
|
||||
GUI::GUI() :
|
||||
$level($level_manager.current()),
|
||||
$status_ui(*$level.world),
|
||||
$map_view(*$level.world, *$level.lights, *$level.map),
|
||||
$inventory_ui(*$level.world),
|
||||
$sounds("./assets")
|
||||
{
|
||||
// this needs a config file soon
|
||||
|
@ -219,8 +217,7 @@ void GUI::resize_map(int new_size) {
|
|||
}
|
||||
|
||||
void GUI::save_world() {
|
||||
$status_ui.log("Game saved!");
|
||||
save::to_file("./savefile.world", $world, $game_map);
|
||||
$status_ui.log("SAVING BUSTED!");
|
||||
}
|
||||
|
||||
void GUI::create_renderer() {
|
||||
|
@ -236,14 +233,16 @@ void GUI::create_renderer() {
|
|||
}
|
||||
|
||||
void GUI::handle_world_events() {
|
||||
auto& world = *$level.world;
|
||||
using eGUI = Events::GUI;
|
||||
while($world.has_event<eGUI>()) {
|
||||
auto [evt, entity, data] = $world.recv<eGUI>();
|
||||
|
||||
while(world.has_event<eGUI>()) {
|
||||
auto [evt, entity, data] = world.recv<eGUI>();
|
||||
|
||||
switch(evt) {
|
||||
case eGUI::COMBAT: {
|
||||
auto &damage = std::any_cast<Events::Combat&>(data);
|
||||
auto enemy_combat = $world.get<Combat>(entity);
|
||||
auto enemy_combat = world.get<Combat>(entity);
|
||||
|
||||
if(damage.enemy_did > 0) {
|
||||
$status_ui.log(format("Enemy HIT YOU for {} damage!", damage.enemy_did));
|
||||
|
@ -265,10 +264,10 @@ void GUI::handle_world_events() {
|
|||
break;
|
||||
case eGUI::DEATH: {
|
||||
// auto &dead_data = std::any_cast<Events::Death&>(data);
|
||||
auto player = $world.get_the<Player>();
|
||||
auto player = world.get_the<Player>();
|
||||
dbc::check(player.entity == entity, "received death event for something not the player");
|
||||
|
||||
auto player_combat = $world.get<Combat>(entity);
|
||||
auto player_combat = world.get<Combat>(entity);
|
||||
if(player_combat.dead) {
|
||||
toggle_modal(&$death_ui, $player_died);
|
||||
}
|
||||
|
@ -305,10 +304,12 @@ void GUI::shutdown() {
|
|||
}
|
||||
|
||||
bool GUI::game_ui_events() {
|
||||
auto& world = *$level.world;
|
||||
using KB = sf::Keyboard;
|
||||
auto player = $world.get_the<Player>();
|
||||
|
||||
auto player = world.get_the<Player>();
|
||||
int map_font_size = $renderer.font_size();
|
||||
auto& player_motion = $world.get<Motion>(player.entity);
|
||||
auto& player_motion = world.get<Motion>(player.entity);
|
||||
bool event_happened = false;
|
||||
|
||||
if(KB::isKeyPressed(KB::Left)) {
|
||||
|
@ -328,12 +329,12 @@ bool GUI::game_ui_events() {
|
|||
} else if(KB::isKeyPressed(KB::Hyphen)) {
|
||||
resize_map(map_font_size - 10);
|
||||
} else if(KB::isKeyPressed(KB::L)) {
|
||||
auto &debug = $world.get_the<Debug>();
|
||||
auto &debug = world.get_the<Debug>();
|
||||
debug.LIGHT = !debug.LIGHT;
|
||||
} else if(KB::isKeyPressed(KB::I)) {
|
||||
toggle_modal(&$inventory_ui, $inventory_open);
|
||||
} else if(KB::isKeyPressed(KB::P)) {
|
||||
auto &debug = $world.get_the<Debug>();
|
||||
auto &debug = world.get_the<Debug>();
|
||||
debug.PATHS = !debug.PATHS;
|
||||
} else if(KB::isKeyPressed(KB::S)) {
|
||||
save_world();
|
||||
|
@ -422,12 +423,11 @@ void GUI::draw_paused() {
|
|||
}
|
||||
|
||||
void GUI::run_systems() {
|
||||
auto player = $world.get_the<Player>();
|
||||
System::motion($world, $game_map);
|
||||
System::enemy_pathing($world, $game_map, player);
|
||||
System::lighting($world, $game_map, $lights);
|
||||
System::collision($world, player);
|
||||
System::death($world);
|
||||
System::motion($level);
|
||||
System::enemy_pathing($level);
|
||||
System::lighting($level);
|
||||
System::collision($level);
|
||||
System::death($level);
|
||||
}
|
||||
|
||||
void GUI::shake() {
|
||||
|
@ -481,7 +481,9 @@ void GUI::render_scene() {
|
|||
}
|
||||
|
||||
int GUI::main(bool run_once) {
|
||||
$world.set_the<Debug>({});
|
||||
auto &world = *$level.world;
|
||||
|
||||
world.set_the<Debug>({});
|
||||
create_renderer();
|
||||
run_systems();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue