Started to set things up so that the boss fight UI can load enemies and configs out of the components setup.

This commit is contained in:
Zed A. Shaw 2025-03-01 00:46:40 -05:00
parent 033358749f
commit b3b8cbbeee
5 changed files with 14 additions and 15 deletions

View file

@ -116,14 +116,19 @@ namespace components {
template <typename T> struct NameOf;
// these need to be here if you're using components::convert outside of components.cpp
ENROLL_COMPONENT(Tile, display, foreground, background);
ENROLL_COMPONENT(Sprite, name);
ENROLL_COMPONENT(Curative, hp);
ENROLL_COMPONENT(LightSource, strength, radius);
ENROLL_COMPONENT(Weapon, damage);
ENROLL_COMPONENT(Loot, amount);
ENROLL_COMPONENT(Position, location.x, location.y);
ENROLL_COMPONENT(EnemyConfig, hearing_distance);
ENROLL_COMPONENT(Motion, dx, dy, random);
ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead);
ENROLL_COMPONENT(Device, config, events);
ENROLL_COMPONENT(Animation, scale, simple, frames, speed, easing, ease_rate);
ENROLL_COMPONENT(Sound, attack, death);
using ReflFuncSignature = std::function<void(DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j)>;
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
@ -140,9 +145,7 @@ namespace components {
template<typename COMPONENT> COMPONENT get(nlohmann::json &data) {
for (auto &i : data["components"]) {
if(i["_type"] == NameOf<COMPONENT>::name) {
COMPONENT result;
from_json(i, result);
return result;
return convert<COMPONENT>(i);
}
}