From a70f11646a5ceec2514fee4e7d9b33a956720385 Mon Sep 17 00:00:00 2001
From: "Zed A. Shaw" <zed.shaw@gmail.com>
Date: Thu, 24 Apr 2025 03:32:20 -0400
Subject: [PATCH] RitualBelt now has an API.

---
 rituals.cpp       | 16 ++++++++++++++++
 rituals.hpp       |  7 ++++++-
 tests/rituals.cpp | 10 ++++++++--
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/rituals.cpp b/rituals.cpp
index c182a47..0676e7b 100644
--- a/rituals.cpp
+++ b/rituals.cpp
@@ -102,4 +102,20 @@ namespace combat {
 
     fmt::println("\n");
   }
+
+  RitualAction& RitualBelt::get(int index) {
+    return equipped.at(index);
+  }
+
+  void RitualBelt::equip(int index, RitualAction& action) {
+    equipped.insert_or_assign(index, action);
+  }
+
+  bool RitualBelt::has(int index) {
+    return equipped.contains(index);
+  }
+
+  void RitualBelt::unequip(int index) {
+    equipped.erase(index);
+  }
 }
diff --git a/rituals.hpp b/rituals.hpp
index 6ec3e33..220e0e5 100644
--- a/rituals.hpp
+++ b/rituals.hpp
@@ -62,6 +62,11 @@ namespace combat {
   };
 
   struct RitualBelt {
-    std::vector<RitualAction> equipped;
+    std::unordered_map<int, RitualAction> equipped;
+
+    RitualAction& get(int index);
+    void equip(int index, RitualAction& action);
+    bool has(int index);
+    void unequip(int index);
   };
 }
diff --git a/tests/rituals.cpp b/tests/rituals.cpp
index 64dc887..0a4dd0a 100644
--- a/tests/rituals.cpp
+++ b/tests/rituals.cpp
@@ -76,11 +76,17 @@ TEST_CASE("the ritual belt works", "[rituals-belt]") {
 
   {
     auto action = re.finalize(plan);
-    the_belt.equipped.push_back(action);
+    the_belt.equip(0, action);
+    REQUIRE(the_belt.has(0));
   }
 
   {
-    auto action = the_belt.equipped.at(0);
+    auto action = the_belt.get(0);
     action.dump();
   }
+
+  {
+    the_belt.unequip(0);
+    REQUIRE(!the_belt.has(0));
+  }
 }