This cleans up how I'm rendering the map but there's no way I can render a large map like this. It'd be way too big.
This commit is contained in:
parent
3b06105813
commit
d9219a8c64
3 changed files with 74 additions and 42 deletions
28
textures.cpp
28
textures.cpp
|
@ -78,10 +78,31 @@ namespace textures {
|
|||
}
|
||||
}
|
||||
|
||||
void load_map_tiles() {
|
||||
Config config("./assets/map_tiles.json");
|
||||
nlohmann::json& tiles = config.json();
|
||||
|
||||
for(auto tile : tiles) {
|
||||
sf::Vector2i coords{tile["x"], tile["y"]};
|
||||
dbc::check(coords.x % ICONGEN_MAP_TILE_DIM == 0, "x coordinates wrong in map");
|
||||
dbc::check(coords.y % ICONGEN_MAP_TILE_DIM == 0, "y coordinates wrong in map");
|
||||
|
||||
sf::IntRect square{coords, {ICONGEN_MAP_TILE_DIM, ICONGEN_MAP_TILE_DIM}};
|
||||
sf::Sprite sprite{TMGR.map_sprite_sheet, square};
|
||||
wchar_t display = tile["display"];
|
||||
|
||||
dbc::check(!TMGR.map_sprites.contains(display),
|
||||
fmt::format("duplicate tile display {} in map_tiles.json", int(display)));
|
||||
|
||||
TMGR.map_sprites.try_emplace(display, sprite);
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
if(!initialized) {
|
||||
load_tiles();
|
||||
load_sprites();
|
||||
load_map_tiles();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
@ -134,4 +155,11 @@ namespace textures {
|
|||
fmt::format("there is no texture named {} in tiles.json", name));
|
||||
return TMGR.name_to_id.at(name);
|
||||
}
|
||||
|
||||
sf::Sprite& get_map_sprite(wchar_t display) {
|
||||
dbc::check(TMGR.map_sprites.contains(display),
|
||||
fmt::format("map_sprites.json doesn't have {} sprite", int(display)));
|
||||
|
||||
return TMGR.map_sprites.at(display);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue