diff --git a/assets/map_tiles.png b/assets/map_tiles.png index 40d3093..1c87bb7 100644 Binary files a/assets/map_tiles.png and b/assets/map_tiles.png differ diff --git a/assets/tiles.json b/assets/tiles.json index 0d81922..91fc600 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -22,8 +22,8 @@ "collision": true, "display": 9256, "light": 20, - "foreground": [100, 100, 180], - "background": [100, 150, 100], + "background": [100, 100, 180], + "foreground": [100, 150, 100], "id": 2 }, "ceiling_black": { diff --git a/meson.build b/meson.build index 03ada2e..40915a8 100644 --- a/meson.build +++ b/meson.build @@ -170,7 +170,7 @@ executable('zedcaster', dependencies: dependencies) executable('icongen', - [ 'config.cpp', 'dbc.cpp', 'tools/icongen.cpp' ], + [ 'textures.cpp', 'config.cpp', 'dbc.cpp', 'tools/icongen.cpp' ], cpp_args: cpp_args, link_args: link_args, override_options: exe_defaults, diff --git a/tests/map.cpp b/tests/map.cpp index 938e26f..15eb3b7 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -132,7 +132,6 @@ TEST_CASE("map image test", "[map-sprite]") { auto sprite = render_sprite(sprite_coord, size, display, map_sprites); sprite.setPosition({float(it.x * size.x), float(it.y * size.y)}); - sprite.setColor({255, 255, 255, 200}); render.draw(sprite); } diff --git a/textures.cpp b/textures.cpp index 479245a..81d4978 100644 --- a/textures.cpp +++ b/textures.cpp @@ -120,6 +120,10 @@ namespace textures { return (const uint32_t *)TMGR.surfaces[num].getPixelsPtr(); } + sf::Image& get_surface_img(size_t num) { + return TMGR.surfaces[num]; + } + const uint32_t* get_ceiling(size_t num) { size_t ceiling_num = TMGR.ceilings[num]; return (const uint32_t *)TMGR.surfaces[ceiling_num].getPixelsPtr(); diff --git a/textures.hpp b/textures.hpp index 5ec9e3f..39841d6 100644 --- a/textures.hpp +++ b/textures.hpp @@ -36,6 +36,8 @@ namespace textures { const uint32_t* get_surface(size_t num); + sf::Image& get_surface_img(size_t num); + const uint32_t* get_ceiling(size_t num); size_t get_id(const std::string& name); diff --git a/tools/icongen.cpp b/tools/icongen.cpp index ba4277c..134e839 100644 --- a/tools/icongen.cpp +++ b/tools/icongen.cpp @@ -8,6 +8,7 @@ #include "shiterator.hpp" #include #include +#include "textures.hpp" namespace fs = std::filesystem; constexpr const int TILE_COUNT=10; @@ -28,6 +29,7 @@ struct MapConfig { BoolGrid centered = make(TILE_COUNT, TILE_COUNT); std::unordered_map colors; std::unordered_map backgrounds; + std::unordered_map names; each_row_t it{map}; }; @@ -81,8 +83,43 @@ struct MapTileBuilder { 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(crop); + $render->clear({0,0,0,0}); + + $render->setSmooth(false); + sf::Vector2f cell_pos{0.0f,0.0f}; + + for(each_row_t 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) { - 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(crop); $render->clear({0,0,0,0}); @@ -107,7 +144,6 @@ struct MapTileBuilder { sf::Text icon{$font, content, $font_size}; icon.setFillColor({255, 255, 255, 255}); - $temp_render.draw(icon); $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"]; config.map[config.it.y][config.it.x] = display; config.centered[config.it.y][config.it.x] = is_centered; + config.names.insert_or_assign(display, key); dbc::check(!config.colors.contains(display), fmt::format("duplicate color for display={} key={}", @@ -220,6 +257,7 @@ json& component_display(json& val) { } int main() { + textures::init(); MapConfig config; load_config(config, false, "./assets/tiles.json", [](json& val) -> json& {