diff --git a/.gitignore b/.gitignore index 1c82088..ca37570 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ backup *.dll *.world coverage +coverage/* .venv diff --git a/autowalker.cpp b/autowalker.cpp index 5ef81b8..7fb1c86 100644 --- a/autowalker.cpp +++ b/autowalker.cpp @@ -61,11 +61,6 @@ Pathing Autowalker::path_to_items() { return compute_paths(fsm); } -Pathing Autowalker::path_to_devices() { - return compute_paths(fsm); -} - - void Autowalker::handle_window_events() { fsm.$window.handleEvents( [&](const sf::Event::KeyPressed &) { @@ -315,6 +310,8 @@ void Autowalker::autowalk() { handle_boss_fight(); handle_player_walk(start, goal); + if(map_opened_once && move_attempts > 20) send_event(gui::Event::MAP_OPEN); + move_attempts++; } while(move_attempts < 100 && fsm.autowalking); } diff --git a/autowalker.hpp b/autowalker.hpp index 88dea04..b9e851f 100644 --- a/autowalker.hpp +++ b/autowalker.hpp @@ -42,5 +42,4 @@ struct Autowalker { Pathing path_to_enemies(); Pathing path_to_items(); - Pathing path_to_devices(); }; diff --git a/dinkyecs.hpp b/dinkyecs.hpp index 1434558..f1bea64 100644 --- a/dinkyecs.hpp +++ b/dinkyecs.hpp @@ -203,11 +203,14 @@ namespace DinkyECS * return pointers (assuming optional can handle pointers) */ template - std::optional get_if(DinkyECS::Entity entity) { - if(has(entity)) { - return std::make_optional(get(entity)); + Comp* get_if(DinkyECS::Entity entity) { + EntityMap &map = entity_map_for(); + auto &storage = component_storage_for(); + if(map.contains(entity)) { + auto index = map.at(entity); + return &storage.data[index]; } else { - return std::nullopt; + return nullptr; } } }; diff --git a/guecs.cpp b/guecs.cpp index ed792f9..e348cbe 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -22,12 +22,12 @@ namespace guecs { text->setCharacterSize(size); } - void Textual::update(std::wstring& new_content) { + void Textual::update(const wstring& new_content) { content = new_content; text->setString(content); } - void Sprite::update(const std::string& new_name) { + void Sprite::update(const string& new_name) { if(new_name != name) { name = new_name; auto sprite_texture = textures::get(name); @@ -142,7 +142,7 @@ namespace guecs { return {float($parser.grid_w), float($parser.grid_h)}; } - void UI::layout(std::string grid) { + void UI::layout(const string& grid) { $grid = grid; bool good = $parser.parse($grid); dbc::check(good, "LEL parsing failed."); @@ -153,7 +153,7 @@ namespace guecs { } } - DinkyECS::Entity UI::init_entity(std::string name) { + DinkyECS::Entity UI::init_entity(const string& name) { auto entity = $world.entity(); // this lets you look up an entity by name $name_ents.insert_or_assign(name, entity); @@ -162,13 +162,13 @@ namespace guecs { return entity; } - DinkyECS::Entity UI::entity(std::string name) { + DinkyECS::Entity UI::entity(const string& name) { dbc::check($name_ents.contains(name), fmt::format("GUECS entity {} does not exist. Mispelled cell name?", name)); return $name_ents.at(name); } - DinkyECS::Entity UI::entity(std::string name, int id) { + DinkyECS::Entity UI::entity(const string& name, int id) { return entity(fmt::format("{}{}", name, id)); } @@ -293,27 +293,31 @@ namespace guecs { return action_count > 0; } - void UI::show_sprite(string region, string sprite_name) { + void UI::show_sprite(const string& region, const string& sprite_name) { auto ent = entity(region); - // BUG: this should have two branches that just update the sprite - set_init(ent, {sprite_name}); + + if(auto sprite = get_if(ent)) { + sprite->update(sprite_name); + } else { + set_init(ent, {sprite_name}); + } } - void UI::show_text(string region, wstring content) { + void UI::show_text(const string& region, const wstring& content) { auto ent = entity(region); - if(auto text = get_if(ent)) { - text->text->setString(content); + if(has(ent)) { + auto& text = get(ent); + text.text->setString(content); } else { auto &cell = cell_for(ent); Textual to_set{content, 20}; to_set.init(cell, $font); - to_set.text->setFillColor(ColorValue::LIGHT_MID); set(ent, to_set); } } - void UI::click_on(const std::string& name, bool required) { + void UI::click_on(const string& name, bool required) { auto ent = entity(name); if(required) { @@ -334,7 +338,7 @@ namespace guecs { } } - void UI::show_label(string region, wstring content) { + void UI::show_label(const string& region, const wstring& content) { auto ent = entity(region); if(auto text = get_if