diff --git a/assets/enemies.json b/assets/enemies.json index 33700f7..a72c7d0 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -2,9 +2,9 @@ "PLAYER_TILE": { "placement": "fixed", "components": [ - {"_type": "Tile", "display": 42603, + {"_type": "Tile", "display": 41981, "foreground": [255, 200, 125], - "background": [30, 20, 75] + "background": [0,0,0] }, {"_type": "Combat", "hp": 200, "max_hp": 200, "damage": 10, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -13,9 +13,9 @@ }, "GOLD_SAVIOR": { "components": [ - {"_type": "Tile", "display": 2189, + {"_type": "Tile", "display": 42586, "foreground": [131, 213, 238], - "background": [30, 20, 75] + "background": [0,0,0] }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -30,7 +30,7 @@ "components": [ {"_type": "Tile", "display": 2189, "foreground": [131, 213, 238], - "background": [30, 20, 75] + "background": [0,0,0] }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -45,7 +45,7 @@ "components": [ {"_type": "Tile", "display": 1898, "foreground": [156, 172, 197], - "background": [30, 20, 75] + "background": [0,0,0] }, {"_type": "Combat", "hp": 40, "max_hp": 40, "damage": 10, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": true}, @@ -60,7 +60,7 @@ "components": [ {"_type": "Tile", "display": 2220, "foreground": [205, 164, 246], - "background": [30, 20, 75] + "background": [0,0,0] }, {"_type": "Combat", "hp": 50, "max_hp": 50, "damage": 2, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -75,7 +75,7 @@ "components": [ {"_type": "Tile", "display": 1218, "foreground": [205, 164, 246], - "background": [30, 20, 75] + "background": [0,0,0] }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, diff --git a/assets/items.json b/assets/items.json index d523e57..bfefd71 100644 --- a/assets/items.json +++ b/assets/items.json @@ -8,7 +8,7 @@ {"_type": "LightSource", "strength": 50, "radius": 2.5}, {"_type": "Tile", "display": 3848, "foreground": [24, 120, 189], - "background": [230,120, 120] + "background": [0,0,0] }, {"_type": "Sprite", "name": "torch_horizontal_floor", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "pickup", "death": "blank"} @@ -22,7 +22,7 @@ "components": [ {"_type": "Tile", "display": 1003, "foreground": [255, 205, 189], - "background": [255, 205, 189] + "background": [0,0,0] }, {"_type": "Curative", "hp": 20}, {"_type": "Sprite", "name": "healing_potion_small", "width": 256, "height": 256, "scale": 1.0}, diff --git a/assets/map_tiles.json b/assets/map_tiles.json index 545e8ed..3523cd8 100644 --- a/assets/map_tiles.json +++ b/assets/map_tiles.json @@ -7,122 +7,122 @@ }, { "centered": false, - "display": 35, - "x": 32, + "display": 8284, + "x": 64, "y": 0 }, { "centered": false, - "display": 10398, - "x": 64, + "display": 11590, + "x": 128, "y": 0 }, { "centered": false, - "display": 35, - "x": 96, + "display": 10899, + "x": 192, "y": 0 }, { "centered": false, - "display": 35, - "x": 128, + "display": 9256, + "x": 256, "y": 0 }, { "centered": false, - "display": 8820, - "x": 160, + "display": 9608, + "x": 320, "y": 0 }, { "centered": false, - "display": 9608, - "x": 192, + "display": 10747, + "x": 384, "y": 0 }, { "centered": false, - "display": 35, - "x": 224, + "display": 8285, + "x": 448, "y": 0 }, { "centered": true, "display": 1003, - "x": 256, + "x": 512, "y": 0 }, { "centered": true, "display": 3848, - "x": 288, + "x": 576, "y": 0 }, { "centered": true, "display": 85, "x": 0, - "y": 32 + "y": 64 }, { "centered": true, "display": 8687, - "x": 32, - "y": 32 + "x": 64, + "y": 64 }, { "centered": true, "display": 10949, - "x": 64, - "y": 32 + "x": 128, + "y": 64 }, { "centered": true, "display": 8793, - "x": 96, - "y": 32 + "x": 192, + "y": 64 }, { "centered": true, "display": 95, - "x": 128, - "y": 32 + "x": 256, + "y": 64 }, { "centered": true, "display": 1898, - "x": 160, - "y": 32 + "x": 320, + "y": 64 }, { "centered": true, - "display": 2189, - "x": 192, - "y": 32 + "display": 42586, + "x": 384, + "y": 64 }, { "centered": true, "display": 2189, - "x": 224, - "y": 32 + "x": 448, + "y": 64 }, { "centered": true, - "display": 42603, - "x": 256, - "y": 32 + "display": 41981, + "x": 512, + "y": 64 }, { "centered": true, "display": 2220, - "x": 288, - "y": 32 + "x": 576, + "y": 64 }, { "centered": true, "display": 1218, "x": 0, - "y": 64 + "y": 128 } ] diff --git a/assets/map_tiles.png b/assets/map_tiles.png index fc25b4a..40d3093 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 d6b1694..0d81922 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -2,7 +2,7 @@ "floor_tile": { "texture": "assets/textures/floor_gray_stone.png", "collision": false, - "display": 10398, + "display": 8284, "ceiling": "ceiling_black", "light": 0, "foreground": [40, 40, 40], @@ -20,10 +20,10 @@ "wall_moss": { "texture": "assets/textures/glowing_moss_wall.png", "collision": true, - "display": 8820, + "display": 9256, "light": 20, - "foreground": [100, 150, 100], - "background": [100, 100, 100], + "foreground": [100, 100, 180], + "background": [100, 150, 100], "id": 2 }, "ceiling_black": { @@ -37,37 +37,38 @@ "lava_floor": { "texture": "assets/textures/lava_floor.png", "collision": false, - "display": 35, + "display": 10899, "ceiling": "ceiling_black", "light": 20, "foreground": [200, 100, 100], - "background": [10, 10, 10], + "background": [100, 100, 50], "id": 5 }, "gray_stone_floor_light": { "texture": "assets/textures/gray_stone_floor_light.png", "collision": false, - "display": 35, - "ceiling": "ceiling_blue_light", + "display": 11590, + "ceiling": "zceiling_blue_light", "light": 40, - "foreground": [40, 40, 40], + "background": [80, 80, 80], + "foreground": [40, 60, 180], "id": 6 }, - "ceiling_blue_light": { - "texture": "assets/textures/ceiling_blue_light.png", - "collision": false, - "display": 35, - "light": 0, - "foreground": [100, 100, 100], - "id": 7 - }, "wood_wall": { "texture": "assets/textures/wood_wall.png", "collision": false, - "display": 35, + "display": 10747, "light": 0, "foreground": [70, 70, 70], "background": [100, 100, 100], "id": 8 + }, + "zceiling_blue_light": { + "texture": "assets/textures/ceiling_blue_light.png", + "collision": false, + "display": 8285, + "light": 0, + "foreground": [100, 100, 100], + "id": 7 } } diff --git a/tests/map.cpp b/tests/map.cpp index 47f1ea0..938e26f 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -96,7 +96,7 @@ TEST_CASE("map image test", "[map-sprite]") { auto &walls = level.map->tiles(); auto &tile_set = textures::get_map_tile_set(); - sf::Vector2i size{32,32}; + sf::Vector2i size{64,64}; matrix::dump("TILES?", walls); std::unordered_map sprite_coord; @@ -140,8 +140,6 @@ TEST_CASE("map image test", "[map-sprite]") { REQUIRE(sprite_coord.contains(entity_glyph.display)); auto sprite = render_sprite(sprite_coord, size, entity_glyph.display, map_sprites); - - sprite.setColor({255,150,150,255}); sprite.setPosition({float(pos.location.x * size.x), float(pos.location.y * size.y)}); render.draw(sprite); }); diff --git a/tools/icongen.cpp b/tools/icongen.cpp index 7188328..ba4277c 100644 --- a/tools/icongen.cpp +++ b/tools/icongen.cpp @@ -12,7 +12,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=32; +constexpr const size_t DEFAULT_DIM=64; +using namespace nlohmann; using namespace shiterator; @@ -92,30 +93,36 @@ struct MapTileBuilder { for(each_row_t it{config.map}; it.next();) { // a 0 slot means we're done if(config.map[it.y][it.x] == 0) break; + cell_pos.x = it.x * $size.x; cell_pos.y = it.y * $size.y; bool is_centered = config.centered[it.y][it.x]; wchar_t display_char = config.map[it.y][it.x]; std::wstring content{display_char}; + auto bg = config.backgrounds.at(display_char); + auto fg = config.colors.at(display_char); best_size(display_char, is_centered); sf::Text icon{$font, content, $font_size}; - icon.setFillColor({0, 0, 0, 255}); + icon.setFillColor({255, 255, 255, 255}); $temp_render.draw(icon); $temp_render.clear({0,0,0,0}); - auto font_texture = $font.getTexture($font_size); + auto& font_texture = $font.getTexture($font_size); sf::Sprite sprite{font_texture, $glyph.textureRect}; auto t_size = $glyph.textureRect.size; dbc::check($size.x - t_size.x >= 0, "font too big on x"); dbc::check($size.y - t_size.y >= 0, "font too big on y"); + fmt::println("display: {}, bg: {},{},{},{}; fg: {},{},{},{}", + (int)display_char, bg.r, bg.g, bg.b, bg.a, fg.r, fg.g, fg.b, fg.a); + // draw the background first - background.setFillColor(config.backgrounds[display_char]); + background.setFillColor(bg); if(is_centered) { sf::Vector2f center{ @@ -131,23 +138,22 @@ struct MapTileBuilder { background.setPosition(cell_pos); } - sprite.setColor(config.colors[display_char]); + sprite.setColor(fg); $render->draw(background); $render->draw(sprite); + $render->display(); } - - $render->display(); } void save_config(MapConfig& config, const std::string &path) { (void)path; - nlohmann::json result = nlohmann::json::array(); + json result = json::array(); for(each_row_t it{config.map}; it.next();) { if(config.map[it.y][it.x] == 0) break; - nlohmann::json val; + json val; val["x"] = $size.x * it.x; val["y"] = $size.y * it.y; @@ -162,60 +168,69 @@ struct MapTileBuilder { } }; -void load_config(MapConfig& config, bool is_centered, std::string path, std::function finder) +void load_config(MapConfig& config, bool is_centered, std::string path, std::function finder) { Config tiles(path); for(auto [key, val] : tiles.json().items()) { config.it.next(); - auto display = finder(val); + auto data = finder(val); + wchar_t display = data["display"]; config.map[config.it.y][config.it.x] = display; config.centered[config.it.y][config.it.x] = is_centered; - if(val.contains("foreground")) { - auto fg_color = val["foreground"]; + dbc::check(!config.colors.contains(display), + fmt::format("duplicate color for display={} key={}", + (int)display, (std::string)key)); + + if(data.contains("foreground")) { + auto fg_color = data["foreground"]; sf::Color fg{fg_color[0], fg_color[1], fg_color[2]}; + fmt::println("TILE {}, display: {} has foreground: {},{},{}", key, (int)display, fg.r, fg.g, fg.b); config.colors.insert_or_assign(display, fg); } else { + fmt::println("TILE {}, {} has DEFAULT COLOR", key, (int)display); config.colors.insert_or_assign(display, DEFAULT_COLOR); } - if(val.contains("background")) { - auto bg_color = val["background"]; + if(data.contains("background")) { + auto bg_color = data["background"]; sf::Color bg{bg_color[0], bg_color[1], bg_color[2]}; + fmt::println("TILE {} display: {} has background: {},{},{}", key, (int)display, bg.r, bg.g, bg.b); config.backgrounds.insert_or_assign(display, bg); } else { + fmt::println("TILE {} display: {} has transparent background", key, (int)display); sf::Color bg{0, 0, 0, 0}; config.backgrounds.insert_or_assign(display, bg); } - } } -wchar_t component_display(nlohmann::json& val) { +json& component_display(json& val) { auto& components = val["components"]; for(auto& comp : components) { if(comp["_type"] == "Tile") { - return comp["display"]; + return comp; } } dbc::log("BAD CHAR"); - return L'!'; + return val; } int main() { MapConfig config; - load_config(config, false, "./assets/tiles.json", [](nlohmann::json& val) -> wchar_t { - return val["display"]; + load_config(config, false, "./assets/tiles.json", [](json& val) -> json& { + return val; }); load_config(config, true, "./assets/items.json", component_display); load_config(config, true, "./assets/devices.json", component_display); load_config(config, true, "./assets/enemies.json", component_display); + fmt::println("-----------------------------------------"); MapTileBuilder builder(DEFAULT_DIM, DEFAULT_DIM); builder.run(config);