|
|
@ -8,6 +8,7 @@ |
|
|
|
#include "shiterator.hpp" |
|
|
|
#include "shiterator.hpp" |
|
|
|
#include <functional> |
|
|
|
#include <functional> |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
#include "textures.hpp" |
|
|
|
|
|
|
|
|
|
|
|
namespace fs = std::filesystem; |
|
|
|
namespace fs = std::filesystem; |
|
|
|
constexpr const int TILE_COUNT=10; |
|
|
|
constexpr const int TILE_COUNT=10; |
|
|
@ -28,6 +29,7 @@ struct MapConfig { |
|
|
|
BoolGrid centered = make<bool>(TILE_COUNT, TILE_COUNT); |
|
|
|
BoolGrid centered = make<bool>(TILE_COUNT, TILE_COUNT); |
|
|
|
std::unordered_map<wchar_t, sf::Color> colors; |
|
|
|
std::unordered_map<wchar_t, sf::Color> colors; |
|
|
|
std::unordered_map<wchar_t, sf::Color> backgrounds; |
|
|
|
std::unordered_map<wchar_t, sf::Color> backgrounds; |
|
|
|
|
|
|
|
std::unordered_map<wchar_t, std::string> names; |
|
|
|
each_row_t<MapGrid> it{map}; |
|
|
|
each_row_t<MapGrid> it{map}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -81,8 +83,43 @@ struct MapTileBuilder { |
|
|
|
dbc::check(worked, "Failed to write screenshot.png"); |
|
|
|
dbc::check(worked, "Failed to write screenshot.png"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void run_real_textures(MapConfig &config) { |
|
|
|
|
|
|
|
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, ($size.y) * ((unsigned int)config.it.y + 1)}; |
|
|
|
|
|
|
|
fmt::println("TEXTURE CROP: {},{}; size: {},{}", $size.x, $size.y, crop.x, crop.y); |
|
|
|
|
|
|
|
$render = std::make_shared<sf::RenderTexture>(crop); |
|
|
|
|
|
|
|
$render->clear({0,0,0,0}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$render->setSmooth(false); |
|
|
|
|
|
|
|
sf::Vector2f cell_pos{0.0f,0.0f}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(each_row_t<MapGrid> it{config.map}; it.next();) { |
|
|
|
|
|
|
|
wchar_t display_char = config.map[it.y][it.x]; |
|
|
|
|
|
|
|
// stop when there's no more cells set
|
|
|
|
|
|
|
|
if(display_char == 0) break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cell_pos.x = it.x * $size.x; |
|
|
|
|
|
|
|
cell_pos.y = it.y * $size.y; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto& name = config.names.at(display_char); |
|
|
|
|
|
|
|
auto id = textures::get_id(name); |
|
|
|
|
|
|
|
auto& img = textures::get_surface_img(id); |
|
|
|
|
|
|
|
auto img_size = img.getSize(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::Texture surface{img}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::Vector2f scale{float($size.x) / float(img_size.x), |
|
|
|
|
|
|
|
float($size.y) / float(img_size.y)}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::Sprite sprite{surface}; |
|
|
|
|
|
|
|
sprite.setScale(scale); |
|
|
|
|
|
|
|
sprite.setPosition(cell_pos); |
|
|
|
|
|
|
|
$render->draw(sprite); |
|
|
|
|
|
|
|
$render->display(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void run(MapConfig& config) { |
|
|
|
void run(MapConfig& config) { |
|
|
|
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, $size.y * (unsigned int)config.it.y}; |
|
|
|
sf::Vector2u crop{$size.x * (unsigned int)config.it.width, $size.y * ((unsigned int)config.it.y+1)}; |
|
|
|
$render = std::make_shared<sf::RenderTexture>(crop); |
|
|
|
$render = std::make_shared<sf::RenderTexture>(crop); |
|
|
|
$render->clear({0,0,0,0}); |
|
|
|
$render->clear({0,0,0,0}); |
|
|
|
|
|
|
|
|
|
|
@ -107,7 +144,6 @@ struct MapTileBuilder { |
|
|
|
|
|
|
|
|
|
|
|
sf::Text icon{$font, content, $font_size}; |
|
|
|
sf::Text icon{$font, content, $font_size}; |
|
|
|
icon.setFillColor({255, 255, 255, 255}); |
|
|
|
icon.setFillColor({255, 255, 255, 255}); |
|
|
|
|
|
|
|
|
|
|
|
$temp_render.draw(icon); |
|
|
|
$temp_render.draw(icon); |
|
|
|
$temp_render.clear({0,0,0,0}); |
|
|
|
$temp_render.clear({0,0,0,0}); |
|
|
|
|
|
|
|
|
|
|
@ -178,6 +214,7 @@ void load_config(MapConfig& config, bool is_centered, std::string path, std::fun |
|
|
|
wchar_t display = data["display"]; |
|
|
|
wchar_t display = data["display"]; |
|
|
|
config.map[config.it.y][config.it.x] = display; |
|
|
|
config.map[config.it.y][config.it.x] = display; |
|
|
|
config.centered[config.it.y][config.it.x] = is_centered; |
|
|
|
config.centered[config.it.y][config.it.x] = is_centered; |
|
|
|
|
|
|
|
config.names.insert_or_assign(display, key); |
|
|
|
|
|
|
|
|
|
|
|
dbc::check(!config.colors.contains(display), |
|
|
|
dbc::check(!config.colors.contains(display), |
|
|
|
fmt::format("duplicate color for display={} key={}", |
|
|
|
fmt::format("duplicate color for display={} key={}", |
|
|
@ -220,6 +257,7 @@ json& component_display(json& val) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
int main() { |
|
|
|
|
|
|
|
textures::init(); |
|
|
|
MapConfig config; |
|
|
|
MapConfig config; |
|
|
|
|
|
|
|
|
|
|
|
load_config(config, false, "./assets/tiles.json", [](json& val) -> json& { |
|
|
|
load_config(config, false, "./assets/tiles.json", [](json& val) -> json& { |
|
|
|