From 7c90eb6da1606bc8f87d805f1d5aecf76c1e5cdc Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 4 May 2025 23:40:06 -0400 Subject: [PATCH] GUECS now doesn't have the facts feature from DinkyECS and instead you refer to the whole area with gui.MAIN. This is an entity that's at 0 and represents the whole grid. Background is placed there. --- boss_fight_ui.cpp | 2 +- combat_ui.cpp | 2 +- guecs.cpp | 10 ++-------- guecs.hpp | 30 ++---------------------------- status_ui.cpp | 2 +- 5 files changed, 7 insertions(+), 39 deletions(-) diff --git a/boss_fight_ui.cpp b/boss_fight_ui.cpp index 95a4e0f..ad676ce 100644 --- a/boss_fight_ui.cpp +++ b/boss_fight_ui.cpp @@ -54,7 +54,7 @@ namespace gui { $boss_background = textures::get(boss.background); $boss_background.sprite->setPosition({BOSS_VIEW_X, BOSS_VIEW_Y}); - $status.set_the({$status.$parser}); + $status.set($status.MAIN, {$status.$parser}); if(boss.stage) { $boss_has_stage = true; diff --git a/combat_ui.cpp b/combat_ui.cpp index 5e91b75..c96bb0b 100644 --- a/combat_ui.cpp +++ b/combat_ui.cpp @@ -37,7 +37,7 @@ namespace gui { } void CombatUI::init() { - $gui.set_the({$gui.$parser, ColorValue::DARK_MID}); + $gui.set($gui.MAIN, {$gui.$parser, ColorValue::DARK_MID}); auto& the_belt = $level.world->get_the(); for(int slot = 0; slot < the_belt.max_slots; slot++) { diff --git a/guecs.cpp b/guecs.cpp index dd23518..22dba4b 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -182,11 +182,6 @@ namespace guecs { } void UI::init() { - if(has_the()) { - auto& bg = get_the(); - bg.init(); - } - query([](auto, auto& bg) { bg.init(); }); @@ -232,9 +227,8 @@ namespace guecs { } void UI::render(sf::RenderWindow& window) { - if(has_the()) { - auto& bg = get_the(); - window.draw(*bg.shape); + if(auto bg = get_if(MAIN)) { + window.draw(*(bg->shape)); } query([&](auto, auto& shader) { diff --git a/guecs.hpp b/guecs.hpp index eddb32d..cce73e8 100644 --- a/guecs.hpp +++ b/guecs.hpp @@ -150,11 +150,10 @@ namespace guecs { class UI { public: - unsigned long entity_count = 0; + Entity MAIN = 0; + unsigned long entity_count = 1; std::unordered_map $components; - std::unordered_map $facts; std::unordered_map $component_storages; - std::unordered_map $name_ents; shared_ptr $font = nullptr; lel::Parser $parser; @@ -212,31 +211,6 @@ namespace guecs { return $components[std::type_index(typeid(Comp))]; } - - template - bool has_the() { - auto comp_id = std::type_index(typeid(Comp)); - return $facts.contains(comp_id); - } - - template - void set_the(Comp val) { - $facts.insert_or_assign(std::type_index(typeid(Comp)), val); - } - - template - Comp &get_the() { - auto comp_id = std::type_index(typeid(Comp)); - dbc::check($facts.contains(comp_id), - fmt::format("!!!! ATTEMPT to access world fact that hasn't " - "been set yet: {}", - typeid(Comp).name())); - - // use .at to get std::out_of_range if fact not set - std::any &res = $facts.at(comp_id); - return std::any_cast(res); - } - template void set(Entity ent, Comp val) { EntityMap &map = entity_map_for(); diff --git a/status_ui.cpp b/status_ui.cpp index 85c1b38..eedbfed 100644 --- a/status_ui.cpp +++ b/status_ui.cpp @@ -31,7 +31,7 @@ namespace gui { } void StatusUI::init() { - $gui.set_the({$gui.$parser}); + $gui.set($gui.MAIN, {$gui.$parser}); for(auto& [name, cell] : $gui.cells()) { if(name == "log_view") {