Rooms are now styled randomly based on assets/styles.json which will evolve into specifications for themes of levels and rooms in them plus other configs.
This commit is contained in:
parent
e45de2a2cf
commit
d2a5dfa713
7 changed files with 56 additions and 2 deletions
|
@ -12,13 +12,27 @@ using namespace components;
|
|||
|
||||
void WorldBuilder::stylize_rooms() {
|
||||
auto& tiles = $map.tiles();
|
||||
Config style_config("assets/styles.json");
|
||||
json& styles = style_config.json();
|
||||
|
||||
for(auto& room : $map.rooms()) {
|
||||
auto& style = styles[Random::uniform(size_t(0), styles.size() - 1)];
|
||||
|
||||
dbc::check(style.contains("floor"),
|
||||
fmt::format("no floor spec in style {}", (std::string)style["name"]));
|
||||
dbc::check(style.contains("walls"),
|
||||
fmt::format("no walls spec in style {}", (std::string)style["name"]));
|
||||
|
||||
auto& floor_name = style["floor"];
|
||||
auto& wall_name = style["walls"];
|
||||
size_t floor_id = textures::get_id(floor_name);
|
||||
size_t wall_id = textures::get_id(wall_name);
|
||||
|
||||
for(matrix::box it{tiles, room.x, room.y, room.width+1, room.height+1}; it.next();) {
|
||||
if(tiles[it.y][it.x] == 1) {
|
||||
tiles[it.y][it.x] = 2;
|
||||
tiles[it.y][it.x] = wall_id;
|
||||
} else if(tiles[it.y][it.x] == 0) {
|
||||
tiles[it.y][it.x] = 6;
|
||||
tiles[it.y][it.x] = floor_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue