World builder now loads the tile map json and usese the keys to figure out how to randomize the floor configurations.

main
Zed A. Shaw 1 week ago
parent 6b4bc6cc11
commit 03c5546cdf
  1. 8
      assets/config.json
  2. 12
      assets/enemies.json
  3. 21
      assets/tiles.json
  4. 4
      components.hpp
  5. 11
      config.cpp
  6. 2
      config.hpp
  7. 12
      save.cpp
  8. 1
      status.txt
  9. 2
      tests/tilemap.cpp
  10. 5
      tilemap.cpp
  11. 1
      tilemap.hpp
  12. 5
      worldbuilder.cpp

@ -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
},

@ -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"
}
}

@ -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"
}
}

@ -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 {

@ -17,6 +17,17 @@ std::wstring Config::wstring(const std::string key) {
return $converter.from_bytes(str_val);
}
std::vector<std::string> Config::keys() {
// BUG: I mean, c'mon seriously this is how?
std::vector<std::string> 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<std::codecvt_utf8_utf16<wchar_t>> $converter;
const std::string& str_val = $config[main_key][sub_key];

@ -12,6 +12,8 @@ struct Config {
Config(nlohmann::json config, std::string src_path)
: $config(config), $src_path(src_path) {}
std::vector<std::string> keys();
nlohmann::json &operator[](const std::string &key);
std::wstring wstring(const std::string main_key);

@ -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);
Config enemies("./assets/enemies.json");
auto map = config["map"];
world.set_the<Config>(config);
world.set_the<MapConfig>({
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"];

@ -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

@ -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();

@ -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<std::string> 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");

@ -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<std::string> tile_names();
void dump(int show_x=-1, int show_y=-1);
bool INVARIANT();

@ -155,10 +155,7 @@ void WorldBuilder::generate() {
$map.expand();
$map.load_tiles();
std::array<string, 6> 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<size_t>(0, room_types.size() - 1);

Loading…
Cancel
Save