Game now builds and is using the new dynamic component loading but enemies do not spawn in and device events are really working. Also inventory is a giant bag of fail and needs a rewrite.
parent
9e91c71125
commit
a69be90464
@ -1,13 +0,0 @@ |
||||
#pragma once |
||||
|
||||
namespace components { |
||||
struct Combat { |
||||
int hp; |
||||
int damage; |
||||
|
||||
/* NOTE: This is used to _mark_ entities as dead, to detect ones that have just died. Don't make attack automatically set it.*/ |
||||
bool dead = false; |
||||
|
||||
int attack(Combat &target); |
||||
}; |
||||
} |
@ -0,0 +1,36 @@ |
||||
#include "components.hpp" |
||||
#include "point.hpp" |
||||
|
||||
namespace components { |
||||
ENROLL_COMPONENT(Loot, amount); |
||||
ENROLL_COMPONENT(Position, location.x, location.y); |
||||
ENROLL_COMPONENT(Weapon, damage); |
||||
ENROLL_COMPONENT(Curative, hp); |
||||
ENROLL_COMPONENT(EnemyConfig, hearing_distance); |
||||
ENROLL_COMPONENT(Tile, chr, foreground, background); |
||||
ENROLL_COMPONENT(Motion, dx, dy, random); |
||||
ENROLL_COMPONENT(Combat, hp, damage, dead); |
||||
ENROLL_COMPONENT(LightSource, strength, radius); |
||||
ENROLL_COMPONENT(Device, config, events); |
||||
|
||||
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data) { |
||||
for (auto &i : data) { |
||||
dbc::check(i.contains("_type") && i["_type"].is_string(), fmt::format("component has no _type: {}", data.dump())); |
||||
dbc::check(component_map.contains(i["_type"]), fmt::format("component_map doesn't have type {}", std::string(i["_type"]))); |
||||
component_map.at(i["_type"])(world, ent, i); |
||||
} |
||||
} |
||||
|
||||
void configure(ComponentMap& component_map) { |
||||
components::enroll<Combat>(component_map); |
||||
components::enroll<Loot>(component_map); |
||||
components::enroll<Position>(component_map); |
||||
components::enroll<Weapon>(component_map); |
||||
components::enroll<Curative>(component_map); |
||||
components::enroll<EnemyConfig>(component_map); |
||||
components::enroll<Tile>(component_map); |
||||
components::enroll<Motion>(component_map); |
||||
components::enroll<LightSource>(component_map); |
||||
components::enroll<Device>(component_map); |
||||
} |
||||
} |
@ -1,15 +0,0 @@ |
||||
#pragma once |
||||
#include "dinkyecs.hpp" |
||||
#include <nlohmann/json.hpp> |
||||
#include <vector> |
||||
|
||||
namespace components { |
||||
using namespace nlohmann; |
||||
|
||||
struct Device { |
||||
json config; |
||||
std::vector<int> events; |
||||
|
||||
void configure_events(json &event_names); |
||||
}; |
||||
} |
@ -0,0 +1,31 @@ |
||||
#pragma once |
||||
#include <functional> |
||||
#include <nlohmann/json.hpp> |
||||
#include <nlohmann/json_fwd.hpp> |
||||
#include "dinkyecs.hpp" |
||||
|
||||
|
||||
#define ENROLL_COMPONENT(COMPONENT, ...) \ |
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(COMPONENT, __VA_ARGS__); \
|
||||
template <> struct NameOf<COMPONENT> { \
|
||||
static constexpr const char *name = #COMPONENT; \
|
||||
}; |
||||
|
||||
namespace components { |
||||
using namespace nlohmann; |
||||
|
||||
template <typename T> struct NameOf; |
||||
|
||||
using ReflFuncSignature = std::function<void(DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j)>; |
||||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>; |
||||
|
||||
template <typename COMPONENT> void enroll(ComponentMap &m) { |
||||
m[NameOf<COMPONENT>::name] = [](DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j) { |
||||
COMPONENT c; |
||||
from_json(j, c); |
||||
world.set<COMPONENT>(ent, c); |
||||
}; |
||||
} |
||||
|
||||
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data); |
||||
} |
Loading…
Reference in new issue