diff --git a/Makefile b/Makefile index 23c0dc6..11b8c6b 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ tracy_build: meson compile -j 10 -C builddir test: asset_build build - ./builddir/runtests "[color-palette]" + ./builddir/runtests run: build test ifeq '$(OS)' 'Windows_NT' @@ -60,7 +60,7 @@ clean: meson compile --clean -C builddir debug_test: build - gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[color-palette]" + gdb --nx -x .gdbinit --ex run --args builddir/runtests -e win_installer: powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' diff --git a/assets/devices.json b/assets/devices.json index 4b412f2..2bf5533 100644 --- a/assets/devices.json +++ b/assets/devices.json @@ -8,8 +8,8 @@ "randomized": false, "components": [ {"_type": "Tile", "display": 10949, - "foreground": [24, 205, 189], - "background": [24, 205, 189] + "foreground": "devices/fg:stairs_down", + "background": "devices/bg:stairs_down" }, {"_type": "Device", "config": {}, @@ -25,8 +25,8 @@ "placement": "fixed", "components": [ {"_type": "Tile", "display": 8793, - "foreground": [24, 205, 189], - "background": [24, 205, 189] + "foreground": "devices/fg:stairs_up", + "background": "devices/fg:stairs_up" }, {"_type": "Device", "config": {}, @@ -41,8 +41,8 @@ "inventory_count": 0, "components": [ {"_type": "Tile", "display": 95, - "foreground": [24, 205, 189], - "background": [24, 205, 189] + "foreground": "devices/fg:tripwire", + "background": "devices/bg:tripwire" }, {"_type": "Device", "config": {}, "events": ["TRAP"]}, {"_type": "Sprite", "name": "tripwire_trap", "width": 256, "height": 256, "scale": 1.0} @@ -54,8 +54,8 @@ "description": "A small rotten barrel that may hold things.", "components": [ {"_type": "Tile", "display": 85, - "foreground": [150, 100, 189], - "background": [150, 100, 189] + "foreground": "devices/fg:barrel", + "background": "devices/bg:barrel" }, {"_type": "Device", "config": {}, "events": ["LOOT_CONTAINER"]}, {"_type": "Sprite", "name": "barrel_small", "width": 256, "height": 256, "scale": 1.0}, @@ -68,8 +68,8 @@ "description": "Something died here. Was this your doing?", "components": [ {"_type": "Tile", "display": 8687, - "foreground": [32, 123, 164], - "background": [24, 205, 189] + "foreground": "devices/fg:grave_stone", + "background": "devices/bg:grave_stone" }, {"_type": "Device", "config": {}, "events": ["LOOT_CONTAINER"]}, {"_type": "Sprite", "name": "grave_stone", "width": 256, "height": 256, "scale": 1.0}, diff --git a/assets/enemies.json b/assets/enemies.json index a72c7d0..18d3a36 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -3,8 +3,8 @@ "placement": "fixed", "components": [ {"_type": "Tile", "display": 41981, - "foreground": [255, 200, 125], - "background": [0,0,0] + "foreground": "enemies/fg:player", + "background": "color:transparent" }, {"_type": "Combat", "hp": 200, "max_hp": 200, "damage": 10, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -14,8 +14,8 @@ "GOLD_SAVIOR": { "components": [ {"_type": "Tile", "display": 42586, - "foreground": [131, 213, 238], - "background": [0,0,0] + "foreground": "enemies/fg:gold_savior", + "background": "color:transparent" }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -29,8 +29,8 @@ "KNIGHT": { "components": [ {"_type": "Tile", "display": 2189, - "foreground": [131, 213, 238], - "background": [0,0,0] + "foreground": "enemies/fg:knight", + "background": "color:transparent" }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -44,8 +44,8 @@ "AXE_RANGER": { "components": [ {"_type": "Tile", "display": 1898, - "foreground": [156, 172, 197], - "background": [0,0,0] + "foreground": "enemies/fg:axe_ranger", + "background": "color:transparent" }, {"_type": "Combat", "hp": 40, "max_hp": 40, "damage": 10, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": true}, @@ -59,8 +59,8 @@ "RAT_GIANT": { "components": [ {"_type": "Tile", "display": 2220, - "foreground": [205, 164, 246], - "background": [0,0,0] + "foreground": "enemies/fg:rat_giant", + "background": "color:transparent" }, {"_type": "Combat", "hp": 50, "max_hp": 50, "damage": 2, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, @@ -74,8 +74,8 @@ "SPIDER_GIANT_HAIRY": { "components": [ {"_type": "Tile", "display": 1218, - "foreground": [205, 164, 246], - "background": [0,0,0] + "foreground": "enemies/fg:spider_giant", + "background": "color:transparent" }, {"_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 bfefd71..5c25db3 100644 --- a/assets/items.json +++ b/assets/items.json @@ -7,8 +7,8 @@ "components": [ {"_type": "LightSource", "strength": 50, "radius": 2.5}, {"_type": "Tile", "display": 3848, - "foreground": [24, 120, 189], - "background": [0,0,0] + "foreground": "items/fg:flame", + "background": "color:transparent" }, {"_type": "Sprite", "name": "torch_horizontal_floor", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "pickup", "death": "blank"} @@ -21,8 +21,8 @@ "inventory_count": 1, "components": [ {"_type": "Tile", "display": 1003, - "foreground": [255, 205, 189], - "background": [0,0,0] + "foreground": "items/fg:potion", + "background": "color:transparent" }, {"_type": "Curative", "hp": 20}, {"_type": "Sprite", "name": "healing_potion_small", "width": 256, "height": 256, "scale": 1.0}, diff --git a/assets/map_tiles.png b/assets/map_tiles.png index 1c87bb7..33cd57b 100644 Binary files a/assets/map_tiles.png and b/assets/map_tiles.png differ diff --git a/assets/palette.json b/assets/palette.json index 8ae68f2..116cf7d 100644 --- a/assets/palette.json +++ b/assets/palette.json @@ -1,4 +1,7 @@ { + "color": { + "transparent": [255, 255, 255, 255] + }, "gui/line": { "light": [200,200,200], "mid": [100,100,100], @@ -15,5 +18,48 @@ "light": [200,200,200], "mid": [100,100,100], "dark": [10,10,10] + }, + "items/fg": { + "flame": [24, 120, 189], + "potion": [255, 205, 189] + }, + "enemies/fg": { + "player": [255, 200, 125], + "gold_savior": [131, 213, 238], + "knight": [131, 213, 238], + "axe_ranger": [156, 172, 197], + "rat_giant": [205, 164, 246], + "spider_giant": [205, 164, 246] + }, + "tiles/fg": { + "floor_tile": [40, 40, 40], + "wall_plain": [100, 100, 100], + "wall_moss": [100, 150, 100], + "ceiling_black": [100, 100, 100], + "lava_floor": [200, 100, 100], + "gray_stone_floor_light": [40, 60, 180], + "wood_wall": [70, 70, 70], + "BAD": [255, 0, 0] + }, + "tiles/bg": { + "wall_plain": [10, 10, 10], + "wall_moss": [100, 100, 180], + "lava_floor": [100, 100, 50], + "gray_stone_floor_light": [80, 80, 80], + "wood_wall": [100, 100, 100] + }, + "devices/fg": { + "stairs_down": [24, 205, 189], + "stairs_up": [24, 205, 189], + "tripwire": [24, 205, 189], + "barrel": [150, 100, 189], + "grave_stone": [32, 123, 164] + }, + "devices/bg": { + "stairs_down": [24, 205, 189], + "stairs_up": [24, 205, 189], + "tripwire": [24, 205, 189], + "barrel": [150, 100, 189], + "grave_stone": [24, 205, 189] } } diff --git a/assets/tiles.json b/assets/tiles.json index 91fc600..b3908e9 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -5,7 +5,7 @@ "display": 8284, "ceiling": "ceiling_black", "light": 0, - "foreground": [40, 40, 40], + "foreground": "tiles/fg:floor_tile", "id": 0 }, "wall_plain": { @@ -13,8 +13,8 @@ "collision": true, "display": 9608, "light": 0, - "foreground": [100, 100, 100], - "background": [10, 10, 10], + "foreground": "tiles/fg:wall_plain", + "background": "tiles/bg:wall_plain", "id": 1 }, "wall_moss": { @@ -22,8 +22,8 @@ "collision": true, "display": 9256, "light": 20, - "background": [100, 100, 180], - "foreground": [100, 150, 100], + "background": "tiles/bg:wall_moss", + "foreground": "tiles/fg:wall_moss", "id": 2 }, "ceiling_black": { @@ -31,7 +31,7 @@ "collision": false, "display": 35, "light": 0, - "foreground": [100, 100, 100], + "foreground": "tiles/fg:ceiling_black", "id": 4 }, "lava_floor": { @@ -40,18 +40,18 @@ "display": 10899, "ceiling": "ceiling_black", "light": 20, - "foreground": [200, 100, 100], - "background": [100, 100, 50], + "foreground": "tiles/fg:lava_floor", + "background": "tiles/bg:lava_floor", "id": 5 }, "gray_stone_floor_light": { "texture": "assets/textures/gray_stone_floor_light.png", "collision": false, "display": 11590, - "ceiling": "zceiling_blue_light", + "ceiling": "zBUGceiling_blue_light", "light": 40, - "background": [80, 80, 80], - "foreground": [40, 60, 180], + "foreground": "tiles/fg:gray_stone_floor_light", + "background": "tiles/bg:gray_stone_floor_light", "id": 6 }, "wood_wall": { @@ -59,16 +59,16 @@ "collision": false, "display": 10747, "light": 0, - "foreground": [70, 70, 70], - "background": [100, 100, 100], + "foreground": "tiles/fg:wood_wall", + "background": "tiles/bg:wood_wall", "id": 8 }, - "zceiling_blue_light": { + "zBUGceiling_blue_light": { "texture": "assets/textures/ceiling_blue_light.png", "collision": false, "display": 8285, "light": 0, - "foreground": [100, 100, 100], + "foreground": "tiles/fg:BAD", "id": 7 } } diff --git a/components.hpp b/components.hpp index 6bb6744..e1bbd56 100644 --- a/components.hpp +++ b/components.hpp @@ -39,8 +39,8 @@ namespace components { struct Tile { wchar_t display; - std::array foreground; - std::array background; + std::string foreground; + std::string background; }; struct GameConfig { diff --git a/meson.build b/meson.build index 0a2221c..54ad88e 100644 --- a/meson.build +++ b/meson.build @@ -172,7 +172,7 @@ executable('zedcaster', dependencies: dependencies) executable('icongen', - [ 'textures.cpp', 'config.cpp', 'dbc.cpp', 'tools/icongen.cpp' ], + [ 'palette.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/palette.cpp b/palette.cpp index 63c0c12..cb689fb 100644 --- a/palette.cpp +++ b/palette.cpp @@ -9,11 +9,13 @@ namespace palette { struct PaletteMgr { std::unordered_map palettes; + std::string config; }; static PaletteMgr COLOR; void init(const string &json_file) { + COLOR.config = json_file; Config config(json_file); json& colors = config.json(); @@ -23,7 +25,7 @@ namespace palette { for(auto [value, rgba] : value_specs.items()) { auto color_path = base_key + ":" + value; dbc::check(!COLOR.palettes.contains(color_path), - fmt::format("PALLETES already has a color path {}", color_path)); + fmt::format("PALLETES config {} already has a color path {}", COLOR.config, color_path)); uint8_t alpha = rgba.size() == 3 ? 255 : (uint8_t)rgba[3]; @@ -35,6 +37,17 @@ namespace palette { } sf::Color get(const string& key) { + dbc::check(COLOR.palettes.contains(key), + fmt::format("COLOR {} is missing from {}", key, COLOR.config)); return COLOR.palettes.at(key); } + + sf::Color get(const string& key, const string& value) { + std::string color{key + ":" + value}; + + dbc::check(COLOR.palettes.contains(color), + fmt::format("COLOR {} is missing from {}", color, COLOR.config)); + + return COLOR.palettes.at(color); + } } diff --git a/palette.hpp b/palette.hpp index ad4a39a..03686d1 100644 --- a/palette.hpp +++ b/palette.hpp @@ -7,4 +7,6 @@ namespace palette { void init(const std::string &config="assets/palette.json"); sf::Color get(const string &key); + + sf::Color get(const string &key, const string &value); } diff --git a/tests/palette.cpp b/tests/palette.cpp index c3d2bbd..1fd28c2 100644 --- a/tests/palette.cpp +++ b/tests/palette.cpp @@ -12,7 +12,7 @@ TEST_CASE("color palette test", "[color-palette]") { auto gui_text = palette::get("gui/text:dark"); REQUIRE(gui_text == expect); - gui_text = palette::get("gui/text:mid"); + gui_text = palette::get("gui/text", "mid"); REQUIRE(gui_text != expect); expect = {100, 100, 100, 255}; diff --git a/tools/icongen.cpp b/tools/icongen.cpp index 4d25ac7..63d2759 100644 --- a/tools/icongen.cpp +++ b/tools/icongen.cpp @@ -9,6 +9,7 @@ #include #include #include "textures.hpp" +#include "palette.hpp" namespace fs = std::filesystem; constexpr const int TILE_COUNT=10; @@ -217,16 +218,14 @@ void load_config(MapConfig& config, bool is_centered, std::string path, std::fun (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]}; + auto fg = palette::get(data["foreground"]); config.colors.insert_or_assign(display, fg); } else { config.colors.insert_or_assign(display, DEFAULT_COLOR); } if(data.contains("background")) { - auto bg_color = data["background"]; - sf::Color bg{bg_color[0], bg_color[1], bg_color[2]}; + auto bg = palette::get(data["background"]); config.backgrounds.insert_or_assign(display, bg); } else { sf::Color bg{0, 0, 0, 0}; @@ -249,6 +248,7 @@ json& component_display(json& val) { } int main() { + palette::init(); MapConfig config; load_config(config, false, "./assets/tiles.json", [](json& val) -> json& {