Initial idea for the interactive devices thing but I kind of hate it. Going to try another idea that will be simpler.
This commit is contained in:
parent
e30c18fbdf
commit
8defc0bedf
8 changed files with 48 additions and 26 deletions
|
@ -1,14 +1,6 @@
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
|
|
||||||
namespace components {
|
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) {
|
void configure(DinkyECS::World &world, DinkyECS::Entity entity, json& entity_data) {
|
||||||
for(auto &comp : entity_data["components"]) {
|
for(auto &comp : entity_data["components"]) {
|
||||||
json& config = comp["config"];
|
json& config = comp["config"];
|
||||||
|
@ -45,6 +37,8 @@ namespace components {
|
||||||
dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
|
dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
|
||||||
std::string(comp["type"])));
|
std::string(comp["type"])));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// json config variable dies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dinkyecs.hpp"
|
#include "dinkyecs.hpp"
|
||||||
|
#include "devices.hpp"
|
||||||
#include "combat.hpp"
|
#include "combat.hpp"
|
||||||
#include "inventory.hpp"
|
#include "inventory.hpp"
|
||||||
#include "tser.hpp"
|
#include "tser.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
|
||||||
namespace components {
|
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 {
|
struct Player {
|
||||||
DinkyECS::Entity entity;
|
DinkyECS::Entity entity;
|
||||||
|
|
19
devices.cpp
Normal file
19
devices.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
devices.hpp
Normal file
19
devices.hpp
Normal file
|
@ -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 {
|
namespace Events {
|
||||||
enum GUI {
|
enum GUI {
|
||||||
START, COMBAT, LOOT, DEATH
|
START, COMBAT, LOOT, DEATH, STAIRS
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Combat {
|
struct Combat {
|
||||||
|
|
4
gui.cpp
4
gui.cpp
|
@ -261,6 +261,10 @@ void GUI::handle_world_events() {
|
||||||
std::string(item.data["name"])));
|
std::string(item.data["name"])));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case eGUI::STAIRS: {
|
||||||
|
$status_ui.log("You can go down stairs!");
|
||||||
|
} break;
|
||||||
default:
|
default:
|
||||||
$status_ui.log(format("INVALID EVENT! {},{}", evt, entity));
|
$status_ui.log(format("INVALID EVENT! {},{}", evt, entity));
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ source=[
|
||||||
'lights.cpp',
|
'lights.cpp',
|
||||||
'worldbuilder.cpp',
|
'worldbuilder.cpp',
|
||||||
'inventory.cpp',
|
'inventory.cpp',
|
||||||
|
'devices.cpp',
|
||||||
'components.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) {
|
void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) {
|
||||||
auto& device = world.get<Device>(item);
|
auto& device = world.get<Device>(item);
|
||||||
println("entity {} INTERACTED WITH DEVICE {}", actor, item);
|
println("entity {} INTERACTED WITH DEVICE {}", actor, item);
|
||||||
device.hit(world);
|
device.hit(actor, world);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue