From c8a8d2b1af8eb495961e93fd0a9b944cd628c63e Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 26 Apr 2025 02:51:13 -0400 Subject: [PATCH] You can now craft a single ritual from the blanket. --- events.hpp | 2 +- gui_fsm.cpp | 7 +++++-- ritual_ui.cpp | 18 ++++++++++++++++-- ritual_ui.hpp | 3 +++ rituals.hpp | 2 +- tests/rituals.cpp | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/events.hpp b/events.hpp index 1a725aa..b7e8e8b 100644 --- a/events.hpp +++ b/events.hpp @@ -4,7 +4,7 @@ namespace Events { enum GUI { START, COMBAT, LOOT, DEATH, STAIRS_UP, STAIRS_DOWN, TRAP, COMBAT_START, NO_NEIGHBORS, HP_STATUS, - ATTACK, BLOCK, EVADE, + ATTACK, BLOCK, EVADE, NEW_RITUAL, UPDATE_SPRITE, ENEMY_SPAWN, NOOP }; diff --git a/gui_fsm.cpp b/gui_fsm.cpp index 19277d3..55f2030 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -395,9 +395,12 @@ namespace gui { // std::string(item.data["name"]))); $status_ui.log(L"You picked up an item."); } break; - case eGUI::HP_STATUS: { + case eGUI::HP_STATUS: System::player_status($level); - } break; + break; + case eGUI::NEW_RITUAL: + $combat_ui.init(); + break; case eGUI::EVADE: case eGUI::BLOCK: dbc::log("YOU NEED TO IMPLEMENT THIS!!!!!"); diff --git a/ritual_ui.cpp b/ritual_ui.cpp index fbdd783..6fa33e2 100644 --- a/ritual_ui.cpp +++ b/ritual_ui.cpp @@ -4,6 +4,7 @@ #include "rand.hpp" #include "animation.hpp" #include "rand.hpp" +#include "sound.hpp" namespace gui { using namespace guecs; @@ -90,7 +91,7 @@ namespace gui { bs.sprite->setPosition({float(x), float(y)}); } - // this is where we add the junk to the engine + $engine.set_state($blanket, "has_magick", true); } void RitualUI::reset_inv_positions() { @@ -115,7 +116,19 @@ namespace gui { animation::rotate(*bs.sprite, 20.0); // finalize here ritual here - // add it to the belt + $engine.plan($blanket); + + if($blanket.is_combined()) { + // add it to the belt + auto ritual = $engine.finalize($blanket); + auto& the_belt = $level.world->get($level.player); + the_belt.equip(0, ritual); + $level.world->send(Events::GUI::NEW_RITUAL, $level.player, {}); + reset_inv_positions(); + } else { + fmt::println("Failed to combine!"); + sound::play("ui_click"); + } } bool RitualUI::mouse(float x, float y, bool hover) { @@ -128,6 +141,7 @@ namespace gui { if($ritual_state == OPEN) { $ritual_state = CLOSING; } else if($ritual_state == CLOSED) { + $blanket = $engine.start(); $ritual_state = OPENING; $ritual_anim.play(); } diff --git a/ritual_ui.hpp b/ritual_ui.hpp index 9be3011..09e971d 100644 --- a/ritual_ui.hpp +++ b/ritual_ui.hpp @@ -4,6 +4,7 @@ #include #include "textures.hpp" #include "guecs.hpp" +#include "rituals.hpp" namespace gui { enum class RitualUIState { @@ -17,6 +18,8 @@ namespace gui { public: sf::IntRect $ritual_closed_rect{{0,0},{380,720}}; sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}}; + combat::RitualEngine $engine; + combat::RitualBlanket $blanket; RitualUIState $ritual_state = RitualUIState::CLOSED; textures::SpriteTexture $ritual_ui; components::Animation $ritual_anim; diff --git a/rituals.hpp b/rituals.hpp index 4abd18a..5836ce1 100644 --- a/rituals.hpp +++ b/rituals.hpp @@ -51,7 +51,7 @@ namespace combat { std::unordered_map $states; std::unordered_map> $scripts; - RitualEngine(std::string config_path); + RitualEngine(std::string config_path="assets/rituals.json"); ai::State load_state(std::string name); ai::Action load_action(std::string name); diff --git a/tests/rituals.cpp b/tests/rituals.cpp index f3e3b70..0424fb3 100644 --- a/tests/rituals.cpp +++ b/tests/rituals.cpp @@ -72,7 +72,7 @@ TEST_CASE("blanket can be finalized for the end result", "[rituals]") { TEST_CASE("the ritual belt works", "[rituals-belt]") { RitualBelt the_belt; - RitualEngine re("assets/rituals.json"); + RitualEngine re; auto blanket = re.start(); re.set_state(blanket, "has_magick", true);