Fixed up building enemies and items using componentsin the JSON.
This commit is contained in:
parent
9ce4fbd552
commit
222b39c403
13 changed files with 76 additions and 60 deletions
|
@ -168,28 +168,6 @@ void WorldBuilder::generate_map() {
|
|||
}
|
||||
}
|
||||
|
||||
void configure_components(DinkyECS::World &world, DinkyECS::Entity entity, json& entity_data) {
|
||||
for(auto &comp : entity_data["components"]) {
|
||||
json& config = comp["config"];
|
||||
|
||||
if(comp["type"] == "Weapon") {
|
||||
world.set<Weapon>(entity, {config["damage"]});
|
||||
} else if(comp["type"] == "LightSource") {
|
||||
world.set<LightSource>(entity, {config["strength"], config["radius"]});
|
||||
} else if(comp["type"] == "Loot") {
|
||||
world.set<Loot>(entity, {config["amount"]});
|
||||
} else if(comp["type"] == "Tile") {
|
||||
world.set<Tile>(entity, {config["chr"]});
|
||||
} else if(comp["type"] == "EnemyConfig") {
|
||||
world.set<EnemyConfig>(entity, {config["hearing_distance"]});
|
||||
} else if(comp["type"] == "Combat") {
|
||||
world.set<Combat>(entity, {config["hp"], config["damage"]});
|
||||
} else {
|
||||
dbc::sentinel(format("ITEM COMPONENT TYPE MISSING: {}",
|
||||
std::string(comp["type"])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DinkyECS::Entity place_item(DinkyECS::World &world, Map &game_map, std::string name, int in_room) {
|
||||
auto &config = world.get_the<GameConfig>();
|
||||
|
@ -203,7 +181,7 @@ DinkyECS::Entity place_item(DinkyECS::World &world, Map &game_map, std::string n
|
|||
}
|
||||
|
||||
if(item_data.contains("components")) {
|
||||
configure_components(world, item, item_data);
|
||||
components::configure(world, item, item_data);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
@ -217,7 +195,7 @@ DinkyECS::Entity place_combatant(DinkyECS::World &world, Map &game_map, std::str
|
|||
world.set<Motion>(enemy, {0,0});
|
||||
|
||||
if(enemy_data.contains("components")) {
|
||||
configure_components(world, enemy, enemy_data);
|
||||
components::configure(world, enemy, enemy_data);
|
||||
}
|
||||
return enemy;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue