World builder now loads the tile map json and usese the keys to figure out how to randomize the floor configurations.
This commit is contained in:
parent
6b4bc6cc11
commit
03c5546cdf
12 changed files with 45 additions and 39 deletions
|
@ -1,12 +1,4 @@
|
||||||
{
|
{
|
||||||
"map": {
|
|
||||||
"WALL_TILE": "\ua5b8",
|
|
||||||
"FLOOR_TILE": "\u2849",
|
|
||||||
"PLAYER_TILE": "\ua66b",
|
|
||||||
"ENEMY_TILE": "\u1d5c",
|
|
||||||
"BG_TILE": "█",
|
|
||||||
"WATER_TILE": "\u224b"
|
|
||||||
},
|
|
||||||
"enemy": {
|
"enemy": {
|
||||||
"HEARING_DISTANCE": 8
|
"HEARING_DISTANCE": 8
|
||||||
},
|
},
|
||||||
|
|
12
assets/enemies.json
Normal file
12
assets/enemies.json
Normal file
|
@ -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],
|
"background": [200, 29, 75],
|
||||||
"display":"\u1378"
|
"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": {
|
"BG_TILE": {
|
||||||
"foreground": [230, 20, 125],
|
"foreground": [230, 20, 125],
|
||||||
"background": [230, 20, 125],
|
"background": [230, 20, 125],
|
||||||
"display":"█"
|
"display":"█"
|
||||||
},
|
},
|
||||||
"WATER_TILE": {
|
"WATER_TILE": {
|
||||||
"foreground": [132, 200, 180],
|
"foreground": [156, 164, 238],
|
||||||
"background": [147, 220, 100],
|
"background": [200, 15, 75],
|
||||||
"display":"\u098c"
|
"display":"\u2a93"
|
||||||
},
|
},
|
||||||
"SAND_TILE": {
|
"SAND_TILE": {
|
||||||
"foreground": [24, 106, 180],
|
"foreground": [24, 106, 180],
|
||||||
|
@ -53,5 +43,10 @@
|
||||||
"foreground": [41, 180, 180],
|
"foreground": [41, 180, 180],
|
||||||
"background": [75, 100, 100],
|
"background": [75, 100, 100],
|
||||||
"display":"\u0799"
|
"display":"\u0799"
|
||||||
|
},
|
||||||
|
"BROKEN_TILE": {
|
||||||
|
"foreground": [159, 164, 15],
|
||||||
|
"background": [199, 15, 79],
|
||||||
|
"display":"\u2274"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,12 +38,8 @@ namespace components {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MapConfig {
|
struct MapConfig {
|
||||||
std::string WALL_TILE;
|
|
||||||
std::string FLOOR_TILE;
|
|
||||||
std::string PLAYER_TILE;
|
std::string PLAYER_TILE;
|
||||||
std::string ENEMY_TILE;
|
std::string ENEMY_TILE;
|
||||||
std::string BG_TILE;
|
|
||||||
std::string WATER_TILE;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EnemyConfig {
|
struct EnemyConfig {
|
||||||
|
|
11
config.cpp
11
config.cpp
|
@ -17,6 +17,17 @@ std::wstring Config::wstring(const std::string key) {
|
||||||
return $converter.from_bytes(str_val);
|
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 Config::wstring(const std::string main_key, const std::string sub_key) {
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||||
const std::string& str_val = $config[main_key][sub_key];
|
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(nlohmann::json config, std::string src_path)
|
||||||
: $config(config), $src_path(src_path) {}
|
: $config(config), $src_path(src_path) {}
|
||||||
|
|
||||||
|
std::vector<std::string> keys();
|
||||||
|
|
||||||
nlohmann::json &operator[](const std::string &key);
|
nlohmann::json &operator[](const std::string &key);
|
||||||
|
|
||||||
std::wstring wstring(const std::string main_key);
|
std::wstring wstring(const std::string main_key);
|
||||||
|
|
12
save.cpp
12
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) {
|
void save::load_configs(DinkyECS::World &world) {
|
||||||
Config config("./assets/config.json");
|
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>({
|
world.set_the<MapConfig>({
|
||||||
map["WALL_TILE"],
|
enemies["PLAYER_TILE"]["display"],
|
||||||
map["FLOOR_TILE"],
|
enemies["ENEMY_TILE"]["display"],
|
||||||
map["PLAYER_TILE"],
|
|
||||||
map["ENEMY_TILE"],
|
|
||||||
map["BG_TILE"],
|
|
||||||
map["WATER_TILE"],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
auto enemy = config["enemy"];
|
auto enemy = config["enemy"];
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
TODAY'S GOAL:
|
TODAY'S GOAL:
|
||||||
|
|
||||||
|
* MapConfig must die.
|
||||||
* Tile component needs to go, use the Tiles from the json.
|
* Tile component needs to go, use the Tiles from the json.
|
||||||
* Fire icon \u2034
|
* Fire icon \u2034
|
||||||
* Water icon \u224b
|
* Water icon \u224b
|
||||||
|
|
|
@ -17,7 +17,7 @@ TEST_CASE("tilemap can load tiles and make a map", "[tilemap]") {
|
||||||
WorldBuilder builder(map);
|
WorldBuilder builder(map);
|
||||||
builder.generate();
|
builder.generate();
|
||||||
|
|
||||||
TileMap tiles(width, height);
|
TileMap tiles(map.width(), map.height());
|
||||||
auto& walls = map.walls();
|
auto& walls = map.walls();
|
||||||
tiles.load(walls);
|
tiles.load(walls);
|
||||||
tiles.dump();
|
tiles.dump();
|
||||||
|
|
|
@ -53,11 +53,14 @@ void TileMap::load(matrix::Matrix &walls) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const TileCell &TileMap::at(size_t x, size_t y) {
|
const TileCell &TileMap::at(size_t x, size_t y) {
|
||||||
return $display[y][x];
|
return $display[y][x];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> TileMap::tile_names() {
|
||||||
|
return $config.keys();
|
||||||
|
}
|
||||||
|
|
||||||
bool TileMap::INVARIANT() {
|
bool TileMap::INVARIANT() {
|
||||||
dbc::check(matrix::height($tile_ids) == $height, "$tile_ids has wrong height");
|
dbc::check(matrix::height($tile_ids) == $height, "$tile_ids has wrong height");
|
||||||
dbc::check(matrix::width($tile_ids) == $width, "$tile_ids has wrong width");
|
dbc::check(matrix::width($tile_ids) == $width, "$tile_ids has wrong width");
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
void load(matrix::Matrix &walls);
|
void load(matrix::Matrix &walls);
|
||||||
const TileCell &at(size_t x, size_t y);
|
const TileCell &at(size_t x, size_t y);
|
||||||
void set_tile(size_t x, size_t y, std::string tile_name);
|
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);
|
void dump(int show_x=-1, int show_y=-1);
|
||||||
bool INVARIANT();
|
bool INVARIANT();
|
||||||
|
|
|
@ -155,10 +155,7 @@ void WorldBuilder::generate() {
|
||||||
$map.expand();
|
$map.expand();
|
||||||
$map.load_tiles();
|
$map.load_tiles();
|
||||||
|
|
||||||
std::array<string, 6> room_types{
|
auto room_types = $map.$tiles.tile_names();
|
||||||
"WATER_TILE", "SAND_TILE", "MOSAIC_TILE_1",
|
|
||||||
"MOSAIC_TILE_2", "MOSAIC_TILE_3", "GRASS_TILE"
|
|
||||||
};
|
|
||||||
|
|
||||||
for(size_t i = 0; i < $map.$rooms.size() - 1; i++) {
|
for(size_t i = 0; i < $map.$rooms.size() - 1; i++) {
|
||||||
size_t room_type = Random::uniform<size_t>(0, room_types.size() - 1);
|
size_t room_type = Random::uniform<size_t>(0, room_types.size() - 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue