Reworked the way that entities are loaded so they're more dynamic and can be configured without modifying C++code.
This commit is contained in:
parent
1f7214fcd4
commit
9ce4fbd552
6 changed files with 94 additions and 42 deletions
|
@ -2,36 +2,42 @@
|
||||||
"PLAYER_TILE": {
|
"PLAYER_TILE": {
|
||||||
"foreground": [255, 200, 125],
|
"foreground": [255, 200, 125],
|
||||||
"background": [30, 20, 75],
|
"background": [30, 20, 75],
|
||||||
"hp": 100,
|
"components": [
|
||||||
"damage": 10,
|
{"type": "Tile", "config": {"chr": "\ua66b"}},
|
||||||
"display":"\ua66b"
|
{"type": "Combat", "config": {"hp": 200, "damage": 15}}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"SNAKE": {
|
"SNAKE": {
|
||||||
"foreground": [90, 172, 74],
|
"foreground": [90, 172, 74],
|
||||||
"background": [30, 20, 75],
|
"background": [30, 20, 75],
|
||||||
"hp": 15,
|
"components": [
|
||||||
"damage": 5,
|
{"type": "Tile", "config": {"chr": "\u06b1"}},
|
||||||
"display":"\u06b1"
|
{"type": "Combat", "config": {"hp": 20, "damage": 15}}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"GOBLIN": {
|
"GOBLIN": {
|
||||||
"foreground": [50, 200, 125],
|
"foreground": [50, 200, 125],
|
||||||
"background": [30, 20, 75],
|
"background": [30, 20, 75],
|
||||||
"hp": 75,
|
"components": [
|
||||||
"damage": 30,
|
{"type": "LightSource", "config": {"strength": 70, "radius": 1.8}},
|
||||||
"display":"\u06bf"
|
{"type": "Tile", "config": {"chr": "\u06bf"}},
|
||||||
|
{"type": "Combat", "config": {"hp": 50, "damage": 35}}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"UNICORN": {
|
"UNICORN": {
|
||||||
"foreground": [25, 200, 125],
|
"foreground": [25, 200, 125],
|
||||||
"background": [30, 20, 75],
|
"background": [30, 20, 75],
|
||||||
"hp": 50,
|
"components": [
|
||||||
"damage": 20,
|
{"type": "Tile", "config": {"chr": "\u17a5"}},
|
||||||
"display":"\u17a5"
|
{"type": "Combat", "config": {"hp": 2000, "damage": 5}}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"RAT": {
|
"RAT": {
|
||||||
"foreground": [75, 200, 125],
|
"foreground": [75, 200, 125],
|
||||||
"background": [30, 20, 75],
|
"background": [30, 20, 75],
|
||||||
"hp": 5,
|
"components": [
|
||||||
"damage": 1,
|
{"type": "Tile", "config": {"chr": "\u08ac"}},
|
||||||
"display":"\u08ac"
|
{"type": "Combat", "config": {"hp": 10, "damage": 5}}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,12 @@
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [230, 20, 120],
|
"background": [230, 20, 120],
|
||||||
"description": "A torch that barely lights the way. You wonder if it'd be better to not see the person who murders you.",
|
"description": "A torch that barely lights the way. You wonder if it'd be better to not see the person who murders you.",
|
||||||
"type": "LIGHT",
|
"inventory_count": 1,
|
||||||
"display": "\u0f08"
|
"components": [
|
||||||
|
{"type": "LightSource", "config": {"strength": 70, "radius": 2.0}},
|
||||||
|
{"type": "Tile", "config": {"chr": "\u0f08"}},
|
||||||
|
{"type": "Weapon", "config": {"damage": 35}}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"SWORD_RUSTY": {
|
"SWORD_RUSTY": {
|
||||||
"id": "SWORD_RUSTY",
|
"id": "SWORD_RUSTY",
|
||||||
|
@ -14,8 +18,24 @@
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [24, 205, 189],
|
"background": [24, 205, 189],
|
||||||
"description": "A sword left to rot in a deep hole where it acquired a patina of dirt and tetanus. You aren't sure if it's more deadly for you to hold it or for the people you stab with it.",
|
"description": "A sword left to rot in a deep hole where it acquired a patina of dirt and tetanus. You aren't sure if it's more deadly for you to hold it or for the people you stab with it.",
|
||||||
"type": "WEAPON",
|
"inventory_count": 1,
|
||||||
"display":"\u1e37"
|
"components": [
|
||||||
|
{"type": "Weapon", "config": {"damage": 15}},
|
||||||
|
{"type": "Tile", "config": {"chr": "\u1e37"}}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"SWORD_LIGHT_AND_FLAME": {
|
||||||
|
"id": "SWORD_LIGHT_AND_FLAME",
|
||||||
|
"name": "Sword of Light and Flame",
|
||||||
|
"foreground": [24, 205, 189],
|
||||||
|
"background": [24, 205, 189],
|
||||||
|
"description": "A sword so powerful, a great man from the Land of The Rising Sun thrust it into the ocean of Nerf to chill its effects.",
|
||||||
|
"inventory_count": 1,
|
||||||
|
"components": [
|
||||||
|
{"type": "LightSource", "config": {"strength": 70, "radius": 1.8}},
|
||||||
|
{"type": "Tile", "config": {"chr": "\u0236"}},
|
||||||
|
{"type": "Weapon", "config": {"damage": 30}}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"CHEST_SMALL": {
|
"CHEST_SMALL": {
|
||||||
"id": "CHEST_SMALL",
|
"id": "CHEST_SMALL",
|
||||||
|
@ -23,8 +43,11 @@
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [24, 205, 189],
|
"background": [24, 205, 189],
|
||||||
"description": "A small chest of gold. You wonder who would leave something like this around.",
|
"description": "A small chest of gold. You wonder who would leave something like this around.",
|
||||||
"type": "LOOT",
|
"components": [
|
||||||
"display":"\uaaea"
|
{"type": "Tile", "config": {"chr": "\uaaea"}},
|
||||||
|
{"type": "Loot", "config": {"amount": 10}}
|
||||||
|
],
|
||||||
|
"inventory_count": 1
|
||||||
},
|
},
|
||||||
"WALL_TORCH": {
|
"WALL_TORCH": {
|
||||||
"id": "WALL_TORCH",
|
"id": "WALL_TORCH",
|
||||||
|
@ -32,7 +55,11 @@
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [24, 205, 189],
|
"background": [24, 205, 189],
|
||||||
"description": "A torch on a wall you can't pick up.",
|
"description": "A torch on a wall you can't pick up.",
|
||||||
"type": "FIXED_LIGHT",
|
"inventory_count": 0,
|
||||||
|
"components": [
|
||||||
|
{"type": "Tile", "config": {"chr": "\u06bf"}},
|
||||||
|
{"type": "LightSource", "config": {"strength": 60, "radius": 1.8}}
|
||||||
|
],
|
||||||
"display": "☀"
|
"display": "☀"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
dbc.cpp
1
dbc.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
void dbc::log(const string &message) {
|
void dbc::log(const string &message) {
|
||||||
fmt::print("{}\n", message);
|
fmt::print("{}\n", message);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
TODAY'S GOAL:
|
TODAY'S GOAL:
|
||||||
|
|
||||||
* I don't handle death at all. It crashes when I die.
|
|
||||||
* https://pkl-lang.org/
|
* https://pkl-lang.org/
|
||||||
* Check out https://github.com/stephenberry/glaze
|
* Check out https://github.com/stephenberry/glaze
|
||||||
* Things are still in walls because I +1 the x,y if they're colliding.
|
* Things are still in walls because I +1 the x,y if they're colliding.
|
||||||
|
|
|
@ -148,12 +148,16 @@ void System::collision(DinkyECS::World &world, Player &player) {
|
||||||
world.set<LightSource>(player.entity, new_light);
|
world.set<LightSource>(player.entity, new_light);
|
||||||
inventory.light = new_light;
|
inventory.light = new_light;
|
||||||
world.remove<LightSource>(entity);
|
world.remove<LightSource>(entity);
|
||||||
} else if(world.has<Weapon>(entity)) {
|
}
|
||||||
|
|
||||||
|
if(world.has<Weapon>(entity)) {
|
||||||
inventory.add(item);
|
inventory.add(item);
|
||||||
auto &weapon = world.get<Weapon>(entity);
|
auto &weapon = world.get<Weapon>(entity);
|
||||||
player_combat.damage = weapon.damage;
|
player_combat.damage = weapon.damage;
|
||||||
world.remove<Weapon>(entity);
|
world.remove<Weapon>(entity);
|
||||||
} else if(world.has<Loot>(entity)) {
|
}
|
||||||
|
|
||||||
|
if(world.has<Loot>(entity)) {
|
||||||
auto &loot = world.get<Loot>(entity);
|
auto &loot = world.get<Loot>(entity);
|
||||||
inventory.gold += loot.amount;
|
inventory.gold += loot.amount;
|
||||||
world.remove<Loot>(entity);
|
world.remove<Loot>(entity);
|
||||||
|
|
|
@ -168,30 +168,43 @@ 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) {
|
DinkyECS::Entity place_item(DinkyECS::World &world, Map &game_map, std::string name, int in_room) {
|
||||||
auto &config = world.get_the<GameConfig>();
|
auto &config = world.get_the<GameConfig>();
|
||||||
auto item = world.entity();
|
auto item = world.entity();
|
||||||
auto pos = game_map.place_entity(in_room);
|
auto pos = game_map.place_entity(in_room);
|
||||||
json item_data = config.items[name];
|
json item_data = config.items[name];
|
||||||
|
|
||||||
world.set<Position>(item, {pos.x+1, pos.y+1});
|
world.set<Position>(item, {pos.x+1, pos.y+1});
|
||||||
world.set<Tile>(item, {item_data["display"]});
|
|
||||||
|
|
||||||
if(item_data["type"] == "WEAPON") {
|
if(item_data["inventory_count"] > 0) {
|
||||||
world.set<InventoryItem>(item, {1, item_data});
|
world.set<InventoryItem>(item, {item_data["inventory_count"], item_data});
|
||||||
world.set<Weapon>(item, {20});
|
|
||||||
} else if(item_data["type"] == "LIGHT") {
|
|
||||||
world.set<InventoryItem>(item, {1, item_data});
|
|
||||||
world.set<LightSource>(item, {70,2.0f});
|
|
||||||
} else if(item_data["type"] == "LOOT") {
|
|
||||||
world.set<InventoryItem>(item, {1, item_data});
|
|
||||||
world.set<Loot>(item, {100});
|
|
||||||
} else if(item_data["type"] == "FIXED_LIGHT") {
|
|
||||||
world.set<LightSource>(item, {90,3.0f});
|
|
||||||
} else {
|
|
||||||
dbc::sentinel(format("ITEM MISSING TYPE: {}", name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(item_data.contains("components")) {
|
||||||
|
configure_components(world, item, item_data);
|
||||||
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,8 +215,10 @@ DinkyECS::Entity place_combatant(DinkyECS::World &world, Map &game_map, std::str
|
||||||
auto enemy_data = config.enemies[name];
|
auto enemy_data = config.enemies[name];
|
||||||
world.set<Position>(enemy, {game_map.place_entity(in_room)});
|
world.set<Position>(enemy, {game_map.place_entity(in_room)});
|
||||||
world.set<Motion>(enemy, {0,0});
|
world.set<Motion>(enemy, {0,0});
|
||||||
world.set<Tile>(enemy, {enemy_data["display"]});
|
|
||||||
world.set<Combat>(enemy, {enemy_data["hp"], enemy_data["damage"]});
|
if(enemy_data.contains("components")) {
|
||||||
|
configure_components(world, enemy, enemy_data);
|
||||||
|
}
|
||||||
return enemy;
|
return enemy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue