Initial idea for the interactive devices thing but I kind of hate it. Going to try another idea that will be simpler.

main
Zed A. Shaw 11 months ago
parent e30c18fbdf
commit 8defc0bedf
  1. 10
      components.cpp
  2. 17
      components.hpp
  3. 19
      devices.cpp
  4. 19
      devices.hpp
  5. 2
      events.hpp
  6. 4
      gui.cpp
  7. 1
      meson.build
  8. 2
      systems.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
}
}
}

@ -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<void(json &config, DinkyECS::World &world)> Action;
struct Device {
json config;
std::vector<Action> 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;

@ -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>(Events::GUI::STAIRS, player_ent, {});
}
void StairsUp(DinkyECS::Entity player_ent, json &, DinkyECS::World &world) {
world.send<Events::GUI>(Events::GUI::STAIRS, player_ent, {});
}
void Device::hit(DinkyECS::Entity ent, DinkyECS::World &world) {
for(auto& action : actions) {
action(ent, config, world);
}
}
}

@ -0,0 +1,19 @@
#pragma once
#include "dinkyecs.hpp"
#include <nlohmann/json.hpp>
#include <vector>
namespace components {
using namespace nlohmann;
typedef std::function<void(DinkyECS::Entity ent, json &config, DinkyECS::World &world)> 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<Action> actions;
void hit(DinkyECS::Entity ent, DinkyECS::World &world);
};
}

@ -2,7 +2,7 @@
namespace Events {
enum GUI {
START, COMBAT, LOOT, DEATH
START, COMBAT, LOOT, DEATH, STAIRS
};
struct Combat {

@ -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));
}

@ -37,6 +37,7 @@ source=[
'lights.cpp',
'worldbuilder.cpp',
'inventory.cpp',
'devices.cpp',
'components.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<Device>(item);
println("entity {} INTERACTED WITH DEVICE {}", actor, item);
device.hit(world);
device.hit(actor, world);
}