diff --git a/assets/map_tiles.png b/assets/map_tiles.png index 5c610aa..f342d63 100644 Binary files a/assets/map_tiles.png and b/assets/map_tiles.png differ diff --git a/tools/icongen.cpp b/tools/icongen.cpp index d57f8de..919a76e 100644 --- a/tools/icongen.cpp +++ b/tools/icongen.cpp @@ -16,6 +16,9 @@ using namespace shiterator; using MapRow = BaseRow; using MapGrid = Base; +using BoolRow = BaseRow; +using BoolGrid = Base; + struct MapTileBuilder { unsigned int $font_size = 20; sf::Glyph $glyph; @@ -41,8 +44,8 @@ struct MapTileBuilder { auto temp = $font.getGlyph(for_char, $font_size, false); auto temp_size = $font_size; - while(temp.textureRect.size.y < int($size.y)-1 - && temp.textureRect.size.x < int($size.x)-1) + while(temp.textureRect.size.y < int($size.y) + && temp.textureRect.size.x < int($size.x)) { $glyph = temp; $font_size = temp_size; @@ -66,7 +69,7 @@ struct MapTileBuilder { } - void run(MapGrid& map) { + void run(MapGrid& map, BoolGrid& centered) { sf::Vector2f cell_pos{0.0f,0.0f}; for(each_row_t it{map}; it.next();) { @@ -74,6 +77,7 @@ struct MapTileBuilder { if(map[it.y][it.x] == 0) continue; cell_pos.x = it.x * $size.x; cell_pos.y = it.y * $size.y; + bool is_centered = centered[it.y][it.x]; wchar_t display_char = map[it.y][it.x]; std::wstring content{display_char}; @@ -93,14 +97,21 @@ struct MapTileBuilder { dbc::check(int($size.x - t_size.x) > 0, "font too big on x"); dbc::check(int($size.y - t_size.y) > 0, "font too big on y"); - sf::Vector2f center{ - (float($size.x) - float(t_size.x)) / 2.0f, - (float($size.y) - float(t_size.y)) / 2.0f}; - sf::Vector2f scale{float($size.x) / float(t_size.x), float($size.y) / float(t_size.y)}; + if(is_centered) { + sf::Vector2f center{ + (float($size.x) - float(t_size.x)) / 2.0f, + (float($size.y) - float(t_size.y)) / 2.0f}; + + sf::Vector2f scale{float($size.x) / float(t_size.x) * 0.8f, float($size.y) / float(t_size.y) * 0.8f}; + sprite.setScale(scale); + sprite.setPosition({cell_pos.x + center.x, cell_pos.y + center.y}); + } else { + sf::Vector2f scale{float($size.x) / float(t_size.x), float($size.y) / float(t_size.y)}; + sprite.setScale(scale); + sprite.setPosition(cell_pos); + } - sprite.setScale(scale); - sprite.setPosition(cell_pos); sprite.setColor({0, 0, 0, 255}); $render.draw(sprite); @@ -110,13 +121,14 @@ struct MapTileBuilder { } }; -void load_config(MapGrid& map, each_row_t& it, std::string path, +void load_config(MapGrid& map, BoolGrid& centered, bool is_centered, each_row_t& it, std::string path, std::function finder) { Config tiles(path); for(auto [key, val] : tiles.json().items()) { it.next(); map[it.y][it.x] = finder(val); + centered[it.y][it.x] = is_centered; } } @@ -136,18 +148,19 @@ wchar_t component_display(nlohmann::json& val) { int main() { MapGrid map = make(TILE_COUNT, TILE_COUNT); + BoolGrid centered = make(TILE_COUNT, TILE_COUNT); each_row_t it{map}; - load_config(map, it, "./assets/tiles.json", [](nlohmann::json& val) -> wchar_t { + load_config(map, centered, false, it, "./assets/tiles.json", [](nlohmann::json& val) -> wchar_t { return val["display"]; }); - load_config(map, it, "./assets/items.json", component_display); - load_config(map, it, "./assets/devices.json", component_display); - load_config(map, it, "./assets/enemies.json", component_display); + load_config(map, centered, true, it, "./assets/items.json", component_display); + load_config(map, centered, true, it, "./assets/devices.json", component_display); + load_config(map, centered, true, it, "./assets/enemies.json", component_display); MapTileBuilder builder(32, 32); - builder.run(map); + builder.run(map, centered); builder.save_image("./assets/map_tiles.png"); return 0;