|
|
|
@ -16,6 +16,9 @@ using namespace shiterator; |
|
|
|
|
using MapRow = BaseRow<wchar_t>; |
|
|
|
|
using MapGrid = Base<wchar_t>; |
|
|
|
|
|
|
|
|
|
using BoolRow = BaseRow<bool>; |
|
|
|
|
using BoolGrid = Base<bool>; |
|
|
|
|
|
|
|
|
|
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<MapGrid> 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<MapGrid>& it, std::string path, |
|
|
|
|
void load_config(MapGrid& map, BoolGrid& centered, bool is_centered, each_row_t<MapGrid>& it, std::string path, |
|
|
|
|
std::function<wchar_t(nlohmann::json&)> 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<wchar_t>(TILE_COUNT, TILE_COUNT); |
|
|
|
|
BoolGrid centered = make<bool>(TILE_COUNT, TILE_COUNT); |
|
|
|
|
each_row_t<MapGrid> 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; |
|
|
|
|