Made the components module work like textures and sound so that there's just one constant map of components.
This commit is contained in:
parent
ab391aaa97
commit
f208ca946e
10 changed files with 42 additions and 41 deletions
|
@ -3,28 +3,34 @@
|
|||
#include "easings.hpp"
|
||||
|
||||
namespace components {
|
||||
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data) {
|
||||
static ComponentMap MAP;
|
||||
static bool MAP_configured = false;
|
||||
|
||||
void configure_entity(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);
|
||||
dbc::check(MAP.contains(i["_type"]), fmt::format("MAP doesn't have type {}", std::string(i["_type"])));
|
||||
MAP.at(i["_type"])(world, ent, i);
|
||||
}
|
||||
}
|
||||
|
||||
void configure(ComponentMap& component_map) {
|
||||
components::enroll<BossFight>(component_map);
|
||||
components::enroll<Combat>(component_map);
|
||||
components::enroll<Position>(component_map);
|
||||
components::enroll<Weapon>(component_map);
|
||||
components::enroll<Curative>(component_map);
|
||||
components::enroll<EnemyConfig>(component_map);
|
||||
components::enroll<Personality>(component_map);
|
||||
components::enroll<Tile>(component_map);
|
||||
components::enroll<Motion>(component_map);
|
||||
components::enroll<LightSource>(component_map);
|
||||
components::enroll<Device>(component_map);
|
||||
components::enroll<Sprite>(component_map);
|
||||
components::enroll<Animation>(component_map);
|
||||
components::enroll<Sound>(component_map);
|
||||
void init() {
|
||||
if(!MAP_configured) {
|
||||
components::enroll<BossFight>(MAP);
|
||||
components::enroll<Combat>(MAP);
|
||||
components::enroll<Position>(MAP);
|
||||
components::enroll<Weapon>(MAP);
|
||||
components::enroll<Curative>(MAP);
|
||||
components::enroll<EnemyConfig>(MAP);
|
||||
components::enroll<Personality>(MAP);
|
||||
components::enroll<Tile>(MAP);
|
||||
components::enroll<Motion>(MAP);
|
||||
components::enroll<LightSource>(MAP);
|
||||
components::enroll<Device>(MAP);
|
||||
components::enroll<Sprite>(MAP);
|
||||
components::enroll<Animation>(MAP);
|
||||
components::enroll<Sound>(MAP);
|
||||
MAP_configured = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue