From b28b76ee2d24437df9b11b32aa7c6509d5acc534 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 30 Jun 2025 10:15:22 -0400 Subject: [PATCH] Ritual blanket now has its own internal id but I'm sort of thinking it needs to be more like inventory::Model. Closes #47. --- dinkyecs.hpp | 2 +- gui/ritual_ui.hpp | 2 +- rituals.cpp | 16 ++++++++-------- rituals.hpp | 22 +++++++++++----------- tests/rituals.cpp | 5 ++--- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/dinkyecs.hpp b/dinkyecs.hpp index 99bbb89..0b9f340 100644 --- a/dinkyecs.hpp +++ b/dinkyecs.hpp @@ -12,7 +12,7 @@ namespace DinkyECS { - typedef unsigned long Entity; + using Entity = unsigned long; using EntityMap = std::unordered_map; diff --git a/gui/ritual_ui.hpp b/gui/ritual_ui.hpp index eb3b24e..1c89eea 100644 --- a/gui/ritual_ui.hpp +++ b/gui/ritual_ui.hpp @@ -28,7 +28,7 @@ namespace gui { struct SelectedItem { guecs::Entity slot_id; - DinkyECS::Entity item_id; + ::ritual::Entity item_id; }; class UI : public DeadSimpleFSM { diff --git a/rituals.cpp b/rituals.cpp index d4a3902..62986c8 100644 --- a/rituals.cpp +++ b/rituals.cpp @@ -151,35 +151,35 @@ namespace ritual { return slot; } - DinkyECS::Entity Blanket::add(JunkItem name) { - DinkyECS::Entity id = ++entity_counter; + Entity Blanket::add(JunkItem name) { + Entity id = ++entity_counter; contents.insert_or_assign(id, name); return id; } - std::string& Blanket::get(DinkyECS::Entity ent) { + std::string& Blanket::get(Entity ent) { return contents.at(ent); } - bool Blanket::has(DinkyECS::Entity ent) { + bool Blanket::has(Entity ent) { return contents.contains(ent); } - void Blanket::remove(DinkyECS::Entity ent) { + void Blanket::remove(Entity ent) { contents.erase(ent); } - void Blanket::select(DinkyECS::Entity ent) { + void Blanket::select(Entity ent) { selected.insert_or_assign(ent, true); } - void Blanket::deselect(DinkyECS::Entity ent) { + void Blanket::deselect(Entity ent) { selected.erase(ent); } - bool Blanket::is_selected(DinkyECS::Entity ent) { + bool Blanket::is_selected(Entity ent) { return selected.contains(ent) && selected.at(ent); } diff --git a/rituals.hpp b/rituals.hpp index 204127f..6bad22c 100644 --- a/rituals.hpp +++ b/rituals.hpp @@ -2,10 +2,10 @@ #include "goap.hpp" #include "ai.hpp" #include "config.hpp" -#include "dinkyecs.hpp" namespace ritual { using JunkItem = std::string; + using Entity = unsigned long; struct JunkPile { std::vector contents; @@ -82,17 +82,17 @@ namespace ritual { struct Blanket { size_t entity_counter = 0; - std::unordered_map contents; - std::unordered_map selected; - - DinkyECS::Entity add(JunkItem name); - JunkItem& get(DinkyECS::Entity ent); - bool has(DinkyECS::Entity ent); - void remove(DinkyECS::Entity ent); - void select(DinkyECS::Entity ent); - void deselect(DinkyECS::Entity ent); + std::unordered_map contents; + std::unordered_map selected; + + Entity add(JunkItem name); + JunkItem& get(Entity ent); + bool has(Entity ent); + void remove(Entity ent); + void select(Entity ent); + void deselect(Entity ent); void reset(); - bool is_selected(DinkyECS::Entity ent); + bool is_selected(Entity ent); bool no_selections(); void consume_crafting(); }; diff --git a/tests/rituals.cpp b/tests/rituals.cpp index de38692..d1ac25b 100644 --- a/tests/rituals.cpp +++ b/tests/rituals.cpp @@ -2,7 +2,6 @@ #include #include "rituals.hpp" #include "simplefsm.hpp" -#include "dinkyecs.hpp" #include "levelmanager.hpp" #include "ai_debug.hpp" @@ -107,8 +106,8 @@ TEST_CASE("the ritual belt works", "[rituals]") { TEST_CASE("ritual blanket basic operations", "[rituals-blanket]") { ritual::Blanket blanket; - DinkyECS::Entity other = blanket.add("rusty_nails"); - DinkyECS::Entity ent = blanket.add("severed_finger"); + ritual::Entity other = blanket.add("rusty_nails"); + ritual::Entity ent = blanket.add("severed_finger"); auto& name = blanket.get(ent); REQUIRE(name == "severed_finger");