Initial level management works and can go down levels but need to rework the ecs a bit to have the concept of 'constant' information and make copying it easy.

main
Zed A. Shaw 1 month ago
parent 58fae858ff
commit 2735a0ac1f
  1. 10
      dinkyecs.hpp
  2. 1
      levelmanager.cpp
  3. 9
      worldbuilder.cpp

@ -29,10 +29,20 @@ namespace DinkyECS {
std::unordered_map<std::type_index, EntityMap> $components; std::unordered_map<std::type_index, EntityMap> $components;
std::unordered_map<std::type_index, std::any> $facts; std::unordered_map<std::type_index, std::any> $facts;
std::unordered_map<std::type_index, EventQueue> $events; std::unordered_map<std::type_index, EventQueue> $events;
std::vector<Entity> constants;
Entity entity() { Entity entity() {
return ++entity_count; return ++entity_count;
} }
/*
void clone_into(DinkyECS::World &from_world, DinkyECS::World &to_world) {
}
void update_constants(DinkyECS::World &from_world, DinkyECS::World &to_world) {
}
*/
template <typename Comp> template <typename Comp>
EntityMap& entity_map_for() { EntityMap& entity_map_for() {

@ -39,7 +39,6 @@ size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
auto& tile = prev_world->get<Tile>(player.entity); auto& tile = prev_world->get<Tile>(player.entity);
fmt::println("player tile is: {}", tile.chr);
world->set<Tile>(player.entity, tile); world->set<Tile>(player.entity, tile);
} }

@ -7,9 +7,10 @@
using namespace fmt; using namespace fmt;
using namespace components; using namespace components;
inline void check_player(DinkyECS::World &world) { inline void check_player(DinkyECS::World &world, DinkyECS::Entity entity) {
auto player = world.get_the<Player>(); auto player = world.get_the<Player>();
fmt::println("PLAYER ENTITY: {}", player.entity); dbc::check(player.entity != entity, "player shouldn't be added to world");
auto tile = world.get<Tile>(player.entity); auto tile = world.get<Tile>(player.entity);
dbc::check(tile.chr == "\ua66b", format("PLAYER TILE CHANGED {} != {}", tile.chr, "\ua66b")); dbc::check(tile.chr == "\ua66b", format("PLAYER TILE CHANGED {} != {}", tile.chr, "\ua66b"));
} }
@ -222,11 +223,10 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config
int rand_entity = Random::uniform<int>(0, keys.size() - 1); int rand_entity = Random::uniform<int>(0, keys.size() - 1);
std::string key = keys[rand_entity]; std::string key = keys[rand_entity];
auto entity_data = entity_db[key]; auto entity_data = entity_db[key];
check_player(world);
// pass that to the config as it'll be a generic json // pass that to the config as it'll be a generic json
auto entity = configure_entity_in_map(world, $map, entity_data, room_num); auto entity = configure_entity_in_map(world, $map, entity_data, room_num);
fmt::println("ENTITY: {}", entity); check_player(world, entity);
} }
} }
@ -235,7 +235,6 @@ void WorldBuilder::place_entities(DinkyECS::World &world) {
// configure a player as a fact of the world // configure a player as a fact of the world
if(world.has_the<Player>()) { if(world.has_the<Player>()) {
fmt::println("PLAYER ALREADY EXISTS LEAVING ALONE");
auto& player = world.get_the<Player>(); auto& player = world.get_the<Player>();
Point pos_out; Point pos_out;
bool placed = $map.place_entity(0, pos_out); bool placed = $map.place_entity(0, pos_out);

Loading…
Cancel
Save