Using an event for the device interaction is better. If I get to where there's tons of devices then I'll rethink it but right now this is less convoluted.

This commit is contained in:
Zed A. Shaw 2025-01-16 15:15:02 -05:00
parent 8defc0bedf
commit e63a8dd920
8 changed files with 46 additions and 45 deletions

View file

@ -4,38 +4,31 @@ namespace components {
void configure(DinkyECS::World &world, DinkyECS::Entity entity, json& entity_data) {
for(auto &comp : entity_data["components"]) {
json& config = comp["config"];
const string comp_type = comp["type"];
if(comp["type"] == "Weapon") {
if(comp_type == "Weapon") {
world.set<Weapon>(entity, {config["damage"]});
} else if(comp["type"] == "LightSource") {
} else if(comp_type == "LightSource") {
world.set<LightSource>(entity, {config["strength"], config["radius"]});
} else if(comp["type"] == "Loot") {
} else if(comp_type == "Loot") {
world.set<Loot>(entity, {config["amount"]});
} else if(comp["type"] == "Tile") {
} else if(comp_type == "Tile") {
world.set<Tile>(entity, {config["chr"]});
} else if(comp["type"] == "EnemyConfig") {
} else if(comp_type == "EnemyConfig") {
world.set<EnemyConfig>(entity, {config["hearing_distance"]});
} else if(comp["type"] == "Combat") {
} else if(comp_type == "Combat") {
world.set<Combat>(entity, {config["hp"], config["damage"]});
} else if(comp["type"] == "Curative") {
} else if(comp_type == "Curative") {
world.set<Curative>(entity, {config["hp"]});
} else if(comp["type"] == "Motion") {
} else if(comp_type == "Motion") {
world.set<Motion>(entity, {config["dx"], config["dy"], config["random"]});
} else if(comp["type"] == "Device") {
Device device{.config=config, .actions={}};
for(auto name : comp["actions"]) {
if(name == "StairsUp") {
device.actions.push_back(StairsUp);
} else if(name == "StairsDown") {
device.actions.push_back(StairsUp);
}
}
} else if(comp_type == "Device") {
Device device{.config=config, .events={}};
device.configure_events(comp["events"]);
world.set<Device>(entity, device);
} else {
dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
std::string(comp["type"])));
std::string(comp_type)));
}
// json config variable dies