From 517de91a5bcfd23cb4b7df4be05d61ee7dd733fd Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 9 Oct 2025 01:23:01 -0400 Subject: [PATCH] Quick code review to refresh my memory. --- assets/{styles.json => room_themes.json} | 0 boss/fight.cpp | 11 ++++++++--- boss/fight.hpp | 5 +---- boss/ui.cpp | 17 +++++++++++++---- boss/ui.hpp | 4 +++- pathing.cpp | 4 ---- systems.cpp | 2 +- worldbuilder.cpp | 2 +- 8 files changed, 27 insertions(+), 18 deletions(-) rename assets/{styles.json => room_themes.json} (100%) diff --git a/assets/styles.json b/assets/room_themes.json similarity index 100% rename from assets/styles.json rename to assets/room_themes.json diff --git a/boss/fight.cpp b/boss/fight.cpp index a2043f4..39a7543 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -21,6 +21,8 @@ namespace boss { FSM_STATE(State, END, ev, data); } + run_systems(); + return in_state(State::END); } @@ -61,9 +63,6 @@ namespace boss { case BOSS_START: state(State::END); break; - case TICK: - run_systems(); - break; case ATTACK: $ui.status(L"PLAYER TURN"); state(State::PLAYER_TURN); @@ -83,6 +82,7 @@ namespace boss { break; case ATTACK: { $ui.status(L"PLAYER TURN"); + $ui.move_player(run % 10 < 5 ? "player1" : "player2"); int attack_id = std::any_cast(data); boss::System::combat(attack_id); state(State::PLAYER_TURN); @@ -103,6 +103,7 @@ namespace boss { break; case ATTACK: { $ui.status(L"BOSS TURN"); + $ui.move_boss(run % 10 < 5 ? "boss1" : "boss3"); int attack_id = std::any_cast(data); boss::System::combat(attack_id); state(State::BOSS_TURN); @@ -120,6 +121,10 @@ namespace boss { } void Fight::run_systems() { + run++; + } + void Fight::render(sf::RenderWindow& window) { + $ui.render(window); } } diff --git a/boss/fight.hpp b/boss/fight.hpp index f02558c..92ee4ca 100644 --- a/boss/fight.hpp +++ b/boss/fight.hpp @@ -34,10 +34,7 @@ namespace boss { void BOSS_TURN(gui::Event ev, std::any data); void PLAYER_TURN(gui::Event ev, std::any data); void END(gui::Event ev, std::any data); - - void render(sf::RenderWindow& window) { - $ui.render(window); - } + void render(sf::RenderWindow& window); void run_systems(); }; diff --git a/boss/ui.cpp b/boss/ui.cpp index be9ddab..faa75d9 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -35,8 +35,8 @@ namespace boss { "[floor4|player5|player6|player7|player8|_]" ); - position_sprite($boss_sprite, $scene.boss["start_pos"], $scene.boss["scale"], $scene.boss["mid_cell"]); - position_sprite($player_sprite, $scene.player["start_pos"], $scene.player["scale"], $scene.player["mid_cell"]); + move_boss($scene.boss["start_pos"]); + move_player($scene.player["start_pos"]); position_sprite($floor_sprite, $scene.floor_pos, 1.0, false); $arena.init(); @@ -60,8 +60,8 @@ namespace boss { $combat_ui.init(cell.x, cell.y, cell.w, cell.h); } - void UI::position_sprite(textures::SpriteTexture& st, const std::string& name, float scale, bool at_mid) { - auto& cell = $arena.cell_for(name); + void UI::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale, bool at_mid) { + auto& cell = $arena.cell_for(cell_name); float x = float(at_mid ? cell.mid_x : cell.x); float y = float(at_mid ? cell.mid_y : cell.y); @@ -91,4 +91,13 @@ namespace boss { $arena.show_text("status", msg); } + void UI::move_boss(const std::string& cell_name) { + dbc::log(cell_name); + position_sprite($boss_sprite, cell_name, $scene.boss["scale"], $scene.boss["mid_cell"]); + } + + void UI::move_player(const std::string& cell_name) { + dbc::log(cell_name); + position_sprite($player_sprite, cell_name, $scene.player["scale"], $scene.player["mid_cell"]); + } } diff --git a/boss/ui.hpp b/boss/ui.hpp index 6f3a749..9e264b6 100644 --- a/boss/ui.hpp +++ b/boss/ui.hpp @@ -31,7 +31,9 @@ namespace boss { void init(); void render(sf::RenderWindow& window); bool mouse(float x, float y, guecs::Modifiers mods); - void position_sprite(SpriteTexture& st, const std::string& name, float scale, bool at_mid=false); + void position_sprite(SpriteTexture& st, const std::string& cell_name, float scale, bool at_mid=false); void status(const std::wstring& msg); + void move_boss(const std::string& cell_name); + void move_player(const std::string& cell_name); }; } diff --git a/pathing.cpp b/pathing.cpp index 5cb5a4c..b21c4cb 100644 --- a/pathing.cpp +++ b/pathing.cpp @@ -14,9 +14,6 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t } } -/* - * Used https://github.com/HenrYxZ/dijkstra-map as a reference. - */ void Pathing::compute_paths(Matrix &walls) { INVARIANT(); dbc::check(walls[0].size() == $width, @@ -66,7 +63,6 @@ void Pathing::compute_paths(Matrix &walls) { } void Pathing::set_target(const Point &at, int value) { - // FUTURE: I'll eventually allow setting this to negatives for priority $input[at.y][at.x] = value; } diff --git a/systems.cpp b/systems.cpp index 8e2ea3b..d8295fa 100644 --- a/systems.cpp +++ b/systems.cpp @@ -360,7 +360,7 @@ void System::pickup() { } else if(world.has(entity)) { System::device(world, level.player, entity); } else { - // Bug #81 is related to this + dbc::log("BUG: is this a bug in pickup?!"); } } diff --git a/worldbuilder.cpp b/worldbuilder.cpp index bdbc3a5..1bf9bb5 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -15,7 +15,7 @@ using namespace components; void WorldBuilder::stylize_rooms() { auto& tiles = $map.tiles(); - auto style_config = settings::get("styles"); + auto style_config = settings::get("room_themes"); json& styles = style_config.json(); for(auto& room : $map.rooms()) {