|
|
|
@ -10,6 +10,8 @@ |
|
|
|
|
|
|
|
|
|
namespace fs = std::filesystem; |
|
|
|
|
constexpr const int TILE_COUNT=10; |
|
|
|
|
constexpr const sf::Color DEFAULT_COLOR{255, 255, 255, 255}; |
|
|
|
|
constexpr const size_t DEFAULT_DIM=128; |
|
|
|
|
|
|
|
|
|
using namespace shiterator; |
|
|
|
|
|
|
|
|
@ -23,19 +25,17 @@ struct MapTileBuilder { |
|
|
|
|
unsigned int $font_size = 20; |
|
|
|
|
sf::Glyph $glyph; |
|
|
|
|
sf::Font $font{FONT_FILE_NAME}; |
|
|
|
|
std::shared_ptr<sf::RenderTexture> $render = nullptr; |
|
|
|
|
sf::Vector2u $size; |
|
|
|
|
sf::Vector2u $image_size; |
|
|
|
|
sf::RenderTexture $render; |
|
|
|
|
sf::RenderTexture $temp_render; |
|
|
|
|
|
|
|
|
|
MapTileBuilder(size_t x, size_t y) : |
|
|
|
|
$size(x, y), |
|
|
|
|
$image_size($size.x * TILE_COUNT, $size.y * TILE_COUNT), |
|
|
|
|
$render($image_size), |
|
|
|
|
$temp_render($size) |
|
|
|
|
{ |
|
|
|
|
$font.setSmooth(false); |
|
|
|
|
$render.setSmooth(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void best_size(wchar_t for_char) { |
|
|
|
@ -56,25 +56,29 @@ struct MapTileBuilder { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void save_image(std::string icon_path) { |
|
|
|
|
dbc::check($render != nullptr, "You have to call run() first."); |
|
|
|
|
fs::path out_path{icon_path}; |
|
|
|
|
|
|
|
|
|
if(fs::exists(out_path)) { |
|
|
|
|
fs::remove(out_path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sf::Image out_img = $render.getTexture().copyToImage(); |
|
|
|
|
sf::Image out_img = $render->getTexture().copyToImage(); |
|
|
|
|
|
|
|
|
|
bool worked = out_img.saveToFile(out_path); |
|
|
|
|
dbc::check(worked, "Failed to write screenshot.png"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void run(MapGrid& map, unsigned int width, unsigned int height, BoolGrid& centered) { |
|
|
|
|
sf::Vector2u crop{$size.x * width, $size.y * height}; |
|
|
|
|
$render = std::make_shared<sf::RenderTexture>(crop); |
|
|
|
|
|
|
|
|
|
void run(MapGrid& map, BoolGrid& centered) { |
|
|
|
|
$render->setSmooth(false); |
|
|
|
|
sf::Vector2f cell_pos{0.0f,0.0f}; |
|
|
|
|
|
|
|
|
|
for(each_row_t<MapGrid> it{map}; it.next();) { |
|
|
|
|
// skip empty slots
|
|
|
|
|
if(map[it.y][it.x] == 0) continue; |
|
|
|
|
// a 0 slot means we're done
|
|
|
|
|
if(map[it.y][it.x] == 0) break; |
|
|
|
|
cell_pos.x = it.x * $size.x; |
|
|
|
|
cell_pos.y = it.y * $size.y; |
|
|
|
|
bool is_centered = centered[it.y][it.x]; |
|
|
|
@ -97,7 +101,6 @@ 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"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(is_centered) { |
|
|
|
|
sf::Vector2f center{ |
|
|
|
|
(float($size.x) - float(t_size.x)) / 2.0f, |
|
|
|
@ -112,12 +115,12 @@ struct MapTileBuilder { |
|
|
|
|
sprite.setPosition(cell_pos); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sprite.setColor({0, 0, 0, 255}); |
|
|
|
|
sprite.setColor(DEFAULT_COLOR); |
|
|
|
|
|
|
|
|
|
$render.draw(sprite); |
|
|
|
|
$render->draw(sprite); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$render.display(); |
|
|
|
|
$render->display(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -159,8 +162,8 @@ int main() { |
|
|
|
|
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, centered); |
|
|
|
|
MapTileBuilder builder(DEFAULT_DIM, DEFAULT_DIM); |
|
|
|
|
builder.run(map, it.width, it.y, centered); |
|
|
|
|
|
|
|
|
|
builder.save_image("./assets/map_tiles.png"); |
|
|
|
|
return 0; |
|
|
|
|