diff --git a/components.cpp b/components.cpp index 60efbc3..8514ac4 100644 --- a/components.cpp +++ b/components.cpp @@ -1,14 +1,6 @@ #include "components.hpp" namespace components { - void StairsDown(json &, DinkyECS::World &) { - fmt::println("GOING DOWN!"); - } - - void StairsUp(json &, DinkyECS::World &) { - fmt::println("GOING UP!"); - } - void configure(DinkyECS::World &world, DinkyECS::Entity entity, json& entity_data) { for(auto &comp : entity_data["components"]) { json& config = comp["config"]; @@ -45,6 +37,8 @@ namespace components { dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}", std::string(comp["type"]))); } + + // json config variable dies } } } diff --git a/components.hpp b/components.hpp index 9d766bd..ee0ffae 100644 --- a/components.hpp +++ b/components.hpp @@ -1,27 +1,12 @@ #pragma once #include "dinkyecs.hpp" +#include "devices.hpp" #include "combat.hpp" #include "inventory.hpp" #include "tser.hpp" #include "config.hpp" namespace components { - typedef std::function Action; - - struct Device { - json config; - std::vector actions; - - void hit(DinkyECS::World &world) { - for(auto& action : actions) { - action(config, world); - } - } - }; - - void StairsDown(json &data, DinkyECS::World &world); - void StairsUp(json &data, DinkyECS::World &world); - void DummyDeviceAction(json &data, DinkyECS::World &world); struct Player { DinkyECS::Entity entity; diff --git a/devices.cpp b/devices.cpp new file mode 100644 index 0000000..ea4442f --- /dev/null +++ b/devices.cpp @@ -0,0 +1,19 @@ +#include "devices.hpp" +#include "events.hpp" + +namespace components { + void StairsDown(DinkyECS::Entity player_ent, json &, DinkyECS::World &world) { + world.send(Events::GUI::STAIRS, player_ent, {}); + } + + void StairsUp(DinkyECS::Entity player_ent, json &, DinkyECS::World &world) { + + world.send(Events::GUI::STAIRS, player_ent, {}); + } + + void Device::hit(DinkyECS::Entity ent, DinkyECS::World &world) { + for(auto& action : actions) { + action(ent, config, world); + } + } +} diff --git a/devices.hpp b/devices.hpp new file mode 100644 index 0000000..8ab6088 --- /dev/null +++ b/devices.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "dinkyecs.hpp" +#include +#include + +namespace components { + using namespace nlohmann; + + typedef std::function Action; + + void StairsDown(DinkyECS::Entity player_ent, json &data, DinkyECS::World &world); + void StairsUp(DinkyECS::Entity player_ent, json &data, DinkyECS::World &world); + + struct Device { + json config; + std::vector actions; + void hit(DinkyECS::Entity ent, DinkyECS::World &world); + }; +} diff --git a/events.hpp b/events.hpp index 0c022ea..dccd7eb 100644 --- a/events.hpp +++ b/events.hpp @@ -2,7 +2,7 @@ namespace Events { enum GUI { - START, COMBAT, LOOT, DEATH + START, COMBAT, LOOT, DEATH, STAIRS }; struct Combat { diff --git a/gui.cpp b/gui.cpp index 78220fe..c995f8a 100644 --- a/gui.cpp +++ b/gui.cpp @@ -261,6 +261,10 @@ void GUI::handle_world_events() { std::string(item.data["name"]))); } break; + + case eGUI::STAIRS: { + $status_ui.log("You can go down stairs!"); + } break; default: $status_ui.log(format("INVALID EVENT! {},{}", evt, entity)); } diff --git a/meson.build b/meson.build index ec495e7..44b7ab6 100644 --- a/meson.build +++ b/meson.build @@ -37,6 +37,7 @@ source=[ 'lights.cpp', 'worldbuilder.cpp', 'inventory.cpp', + 'devices.cpp', 'components.cpp', ] diff --git a/systems.cpp b/systems.cpp index ea1f93a..c98435b 100644 --- a/systems.cpp +++ b/systems.cpp @@ -218,5 +218,5 @@ void System::pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::En void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) { auto& device = world.get(item); println("entity {} INTERACTED WITH DEVICE {}", actor, item); - device.hit(world); + device.hit(actor, world); }