Refactor before working on animations sending events.

This commit is contained in:
Zed A. Shaw 2026-01-06 23:50:03 -05:00
parent 8b1f288fce
commit 63260f01b9
7 changed files with 10 additions and 42 deletions

View file

@ -89,7 +89,7 @@ namespace boss {
break; break;
case COMBAT_START: case COMBAT_START:
$ui.status(L"X TURN", L"STEP"); $ui.status(L"X TURN", L"STEP");
next_combat_dumb_name(); next_combat();
break; break;
case COMBAT: case COMBAT:
do_combat(data); do_combat(data);
@ -99,7 +99,11 @@ namespace boss {
} }
} }
void Fight::next_combat_dumb_name() { void Fight::END(game::Event ev, std::any) {
fmt::println("BOSS_FIGHT:END event {}", (int)ev);
}
void Fight::next_combat() {
if(auto action = $battle.next()) { if(auto action = $battle.next()) {
System::combat(*action, $world, $boss_id, 0); System::combat(*action, $world, $boss_id, 0);
} else if(player_dead()) { } else if(player_dead()) {
@ -143,10 +147,6 @@ namespace boss {
} }
void Fight::END(game::Event ev, std::any) {
fmt::println("BOSS_FIGHT:END event {}", (int)ev);
}
void Fight::run_systems() { void Fight::run_systems() {
$ui.update_stats(); $ui.update_stats();
$battle.set($host, "tough_personality", false); $battle.set($host, "tough_personality", false);
@ -155,7 +155,6 @@ namespace boss {
} }
void Fight::render(sf::RenderWindow& window) { void Fight::render(sf::RenderWindow& window) {
$ui.play_animations();
$ui.render(); $ui.render();
} }

View file

@ -51,7 +51,7 @@ namespace boss {
void init_fight(); void init_fight();
void do_combat(std::any data); void do_combat(std::any data);
void next_combat_dumb_name(); void next_combat();
sf::Vector2f mouse_position(); sf::Vector2f mouse_position();
bool handle_keyboard_mouse(); bool handle_keyboard_mouse();
}; };

View file

@ -87,7 +87,7 @@ namespace boss {
} }
void System::plan_battle(BattleEngine& battle, std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id) { void System::plan_battle(BattleEngine& battle, std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id) {
// REFACTOR: make this loop the list of entities in the battle then // BUG: make this loop the list of entities in the battle then
// use their world state to configure the plan // use their world state to configure the plan
battle.plan(); battle.plan();
} }

View file

@ -78,7 +78,9 @@ namespace boss {
$actions.render(*$window); $actions.render(*$window);
$combat_ui.render(*$window); $combat_ui.render(*$window);
$arena.play_animations();
$arena.render($view_texture); $arena.render($view_texture);
$view_texture.display(); $view_texture.display();
$window->draw($view_sprite); $window->draw($view_sprite);
} }
@ -102,10 +104,6 @@ namespace boss {
$arena.animate_actor(actor); $arena.animate_actor(actor);
} }
void UI::play_animations() {
$arena.play_animations();
}
void UI::damage(const string& actor, const std::string& target, int amount) { void UI::damage(const string& actor, const std::string& target, int amount) {
if(amount > 0) { if(amount > 0) {
$arena.attach_text(target, fmt::format("{}", amount)); $arena.attach_text(target, fmt::format("{}", amount));

View file

@ -37,7 +37,6 @@ namespace boss {
void move_actor(const std::string& actor, const std::string& cell_name); void move_actor(const std::string& actor, const std::string& cell_name);
void animate_actor(const std::string& actor); void animate_actor(const std::string& actor);
void update_stats(); void update_stats();
void play_animations();
void damage(const std::string& actor, const std::string& target, int amount); void damage(const std::string& actor, const std::string& target, int amount);
void reset_camera(); void reset_camera();
}; };

View file

@ -101,10 +101,6 @@ namespace scene {
} }
for(auto& actor : $actors) { for(auto& actor : $actors) {
if(actor.effect != nullptr) {
dbc::log(fmt::format("ACTOR {} SHADER {}", actor.name, (void*)actor.effect.get()));
}
view.draw(*actor.st.sprite, actor.effect.get()); view.draw(*actor.st.sprite, actor.effect.get());
if(actor.anim.playing) view.draw(actor.text); if(actor.anim.playing) view.draw(actor.text);
} }
@ -172,29 +168,6 @@ namespace scene {
$camera.play(); $camera.play();
} }
std::pair<Element&, Element&> Engine::left_right(const std::string &actor, const std::string &target) {
auto& first = actor_config(actor);
auto& second = actor_config(target);
if(first.pos.x < second.pos.x) {
// first is left
return {first, second};
} else if(first.pos.x == second.pos.x) {
auto fb = first.st.sprite->getGlobalBounds();
auto sb = second.st.sprite->getGlobalBounds();
// use the widest one as right
if(fb.size.x >= sb.size.x) {
return {first, second};
} else {
return {second, first};
}
} else {
// second is left
return {second, first};
}
}
void Engine::zoom(const std::string &actor, const std::string& style, float scale) { void Engine::zoom(const std::string &actor, const std::string& style, float scale) {
auto& config = actor_config(actor); auto& config = actor_config(actor);
auto bounds = config.st.sprite->getGlobalBounds(); auto bounds = config.st.sprite->getGlobalBounds();

View file

@ -56,6 +56,5 @@ namespace scene {
void zoom(const std::string& actor, const std::string& style, float scale=0.9f); void zoom(const std::string& actor, const std::string& style, float scale=0.9f);
void zoom(float mid_x, float mid_y, const std::string& style, float scale); void zoom(float mid_x, float mid_y, const std::string& style, float scale);
void reset(sf::RenderTexture& view); void reset(sf::RenderTexture& view);
std::pair<Element&, Element&> left_right(const std::string &actor, const std::string &target);
}; };
} }