diff --git a/assets/config.json b/assets/config.json index 141dcb9..5e2047a 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,12 +1,4 @@ { - "map": { - "WALL_TILE": "\ua5b8", - "FLOOR_TILE": "\u2849", - "PLAYER_TILE": "\ua66b", - "ENEMY_TILE": "\u1d5c", - "BG_TILE": "█", - "WATER_TILE": "\u224b" - }, "enemy": { "HEARING_DISTANCE": 8 }, diff --git a/assets/enemies.json b/assets/enemies.json new file mode 100644 index 0000000..9508d02 --- /dev/null +++ b/assets/enemies.json @@ -0,0 +1,12 @@ +{ + "PLAYER_TILE": { + "foreground": [255, 200, 125], + "background": [30, 20, 75], + "display":"\ua66b" + }, + "ENEMY_TILE": { + "foreground": [255, 200, 125], + "background": [30, 20, 75], + "display":"\u1d5c" + } +} diff --git a/assets/tiles.json b/assets/tiles.json index 382b0cc..5c11134 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -24,25 +24,15 @@ "background": [200, 29, 75], "display":"\u1378" }, - "PLAYER_TILE": { - "foreground": [255, 200, 125], - "background": [30, 20, 75], - "display":"\ua66b" - }, - "ENEMY_TILE": { - "foreground": [255, 200, 125], - "background": [30, 20, 75], - "display":"\u1d5c" - }, "BG_TILE": { "foreground": [230, 20, 125], "background": [230, 20, 125], "display":"█" }, "WATER_TILE": { - "foreground": [132, 200, 180], - "background": [147, 220, 100], - "display":"\u098c" + "foreground": [156, 164, 238], + "background": [200, 15, 75], + "display":"\u2a93" }, "SAND_TILE": { "foreground": [24, 106, 180], @@ -53,5 +43,10 @@ "foreground": [41, 180, 180], "background": [75, 100, 100], "display":"\u0799" + }, + "BROKEN_TILE": { + "foreground": [159, 164, 15], + "background": [199, 15, 79], + "display":"\u2274" } } diff --git a/components.hpp b/components.hpp index de24616..3e4bbb4 100644 --- a/components.hpp +++ b/components.hpp @@ -38,12 +38,8 @@ namespace components { }; struct MapConfig { - std::string WALL_TILE; - std::string FLOOR_TILE; std::string PLAYER_TILE; std::string ENEMY_TILE; - std::string BG_TILE; - std::string WATER_TILE; }; struct EnemyConfig { diff --git a/config.cpp b/config.cpp index 7d169af..7c9eb60 100644 --- a/config.cpp +++ b/config.cpp @@ -17,6 +17,17 @@ std::wstring Config::wstring(const std::string key) { return $converter.from_bytes(str_val); } +std::vector Config::keys() { + // BUG: I mean, c'mon seriously this is how? + std::vector keys; + + for(const auto& el : $config.items()) { + keys.push_back(el.key()); + } + + return keys; +} + std::wstring Config::wstring(const std::string main_key, const std::string sub_key) { std::wstring_convert> $converter; const std::string& str_val = $config[main_key][sub_key]; diff --git a/config.hpp b/config.hpp index 910d34c..b7daaa3 100644 --- a/config.hpp +++ b/config.hpp @@ -12,6 +12,8 @@ struct Config { Config(nlohmann::json config, std::string src_path) : $config(config), $src_path(src_path) {} + std::vector keys(); + nlohmann::json &operator[](const std::string &key); std::wstring wstring(const std::string main_key); diff --git a/save.cpp b/save.cpp index 6b03275..a3f6916 100644 --- a/save.cpp +++ b/save.cpp @@ -85,16 +85,12 @@ void save::from_file(fs::path path, DinkyECS::World &world_out, Map &map_out) { void save::load_configs(DinkyECS::World &world) { Config config("./assets/config.json"); - world.set_the(config); + Config enemies("./assets/enemies.json"); - auto map = config["map"]; + world.set_the(config); world.set_the({ - map["WALL_TILE"], - map["FLOOR_TILE"], - map["PLAYER_TILE"], - map["ENEMY_TILE"], - map["BG_TILE"], - map["WATER_TILE"], + enemies["PLAYER_TILE"]["display"], + enemies["ENEMY_TILE"]["display"], }); auto enemy = config["enemy"]; diff --git a/status.txt b/status.txt index 03caeaa..5e5a6ca 100644 --- a/status.txt +++ b/status.txt @@ -1,5 +1,6 @@ TODAY'S GOAL: +* MapConfig must die. * Tile component needs to go, use the Tiles from the json. * Fire icon \u2034 * Water icon \u224b diff --git a/tests/tilemap.cpp b/tests/tilemap.cpp index 7b5018f..86185c9 100644 --- a/tests/tilemap.cpp +++ b/tests/tilemap.cpp @@ -17,7 +17,7 @@ TEST_CASE("tilemap can load tiles and make a map", "[tilemap]") { WorldBuilder builder(map); builder.generate(); - TileMap tiles(width, height); + TileMap tiles(map.width(), map.height()); auto& walls = map.walls(); tiles.load(walls); tiles.dump(); diff --git a/tilemap.cpp b/tilemap.cpp index b65ef59..0bc0901 100644 --- a/tilemap.cpp +++ b/tilemap.cpp @@ -53,11 +53,14 @@ void TileMap::load(matrix::Matrix &walls) { } } - const TileCell &TileMap::at(size_t x, size_t y) { return $display[y][x]; } +std::vector TileMap::tile_names() { + return $config.keys(); +} + bool TileMap::INVARIANT() { dbc::check(matrix::height($tile_ids) == $height, "$tile_ids has wrong height"); dbc::check(matrix::width($tile_ids) == $width, "$tile_ids has wrong width"); diff --git a/tilemap.hpp b/tilemap.hpp index 3567b54..be3df9d 100644 --- a/tilemap.hpp +++ b/tilemap.hpp @@ -40,6 +40,7 @@ public: void load(matrix::Matrix &walls); const TileCell &at(size_t x, size_t y); void set_tile(size_t x, size_t y, std::string tile_name); + std::vector tile_names(); void dump(int show_x=-1, int show_y=-1); bool INVARIANT(); diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 869ece9..0e0f7ac 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -155,10 +155,7 @@ void WorldBuilder::generate() { $map.expand(); $map.load_tiles(); - std::array room_types{ - "WATER_TILE", "SAND_TILE", "MOSAIC_TILE_1", - "MOSAIC_TILE_2", "MOSAIC_TILE_3", "GRASS_TILE" - }; + auto room_types = $map.$tiles.tile_names(); for(size_t i = 0; i < $map.$rooms.size() - 1; i++) { size_t room_type = Random::uniform(0, room_types.size() - 1);