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 equipped; + std::unordered_map 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)); + } }