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
|
@ -1,10 +1,9 @@
|
|||
#pragma once
|
||||
#include "dinkyecs.hpp"
|
||||
#include "map.hpp"
|
||||
#include "combat.hpp"
|
||||
#include "inventory.hpp"
|
||||
#include <deque>
|
||||
#include "tser.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
namespace components {
|
||||
struct Player {
|
||||
|
@ -41,7 +40,7 @@ namespace components {
|
|||
};
|
||||
|
||||
struct EnemyConfig {
|
||||
int HEARING_DISTANCE;
|
||||
int hearing_distance = 10;
|
||||
};
|
||||
|
||||
struct Debug {
|
||||
|
@ -52,4 +51,27 @@ namespace components {
|
|||
struct Weapon {
|
||||
int damage = 0;
|
||||
};
|
||||
|
||||
inline void configure(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(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
|
||||
std::string(comp["type"])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue