Colors are now being loaded from assets/palette.json

master
Zed A. Shaw 2 days ago
parent 48a7f72411
commit f4fa50a413
  1. 4
      Makefile
  2. 20
      assets/devices.json
  3. 24
      assets/enemies.json
  4. 8
      assets/items.json
  5. BIN
      assets/map_tiles.png
  6. 46
      assets/palette.json
  7. 30
      assets/tiles.json
  8. 4
      components.hpp
  9. 2
      meson.build
  10. 15
      palette.cpp
  11. 2
      palette.hpp
  12. 2
      tests/palette.cpp
  13. 8
      tools/icongen.cpp

@ -37,7 +37,7 @@ tracy_build:
meson compile -j 10 -C builddir meson compile -j 10 -C builddir
test: asset_build build test: asset_build build
./builddir/runtests "[color-palette]" ./builddir/runtests
run: build test run: build test
ifeq '$(OS)' 'Windows_NT' ifeq '$(OS)' 'Windows_NT'
@ -60,7 +60,7 @@ clean:
meson compile --clean -C builddir meson compile --clean -C builddir
debug_test: build 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: win_installer:
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'

@ -8,8 +8,8 @@
"randomized": false, "randomized": false,
"components": [ "components": [
{"_type": "Tile", "display": 10949, {"_type": "Tile", "display": 10949,
"foreground": [24, 205, 189], "foreground": "devices/fg:stairs_down",
"background": [24, 205, 189] "background": "devices/bg:stairs_down"
}, },
{"_type": "Device", {"_type": "Device",
"config": {}, "config": {},
@ -25,8 +25,8 @@
"placement": "fixed", "placement": "fixed",
"components": [ "components": [
{"_type": "Tile", "display": 8793, {"_type": "Tile", "display": 8793,
"foreground": [24, 205, 189], "foreground": "devices/fg:stairs_up",
"background": [24, 205, 189] "background": "devices/fg:stairs_up"
}, },
{"_type": "Device", {"_type": "Device",
"config": {}, "config": {},
@ -41,8 +41,8 @@
"inventory_count": 0, "inventory_count": 0,
"components": [ "components": [
{"_type": "Tile", "display": 95, {"_type": "Tile", "display": 95,
"foreground": [24, 205, 189], "foreground": "devices/fg:tripwire",
"background": [24, 205, 189] "background": "devices/bg:tripwire"
}, },
{"_type": "Device", "config": {}, "events": ["TRAP"]}, {"_type": "Device", "config": {}, "events": ["TRAP"]},
{"_type": "Sprite", "name": "tripwire_trap", "width": 256, "height": 256, "scale": 1.0} {"_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.", "description": "A small rotten barrel that may hold things.",
"components": [ "components": [
{"_type": "Tile", "display": 85, {"_type": "Tile", "display": 85,
"foreground": [150, 100, 189], "foreground": "devices/fg:barrel",
"background": [150, 100, 189] "background": "devices/bg:barrel"
}, },
{"_type": "Device", "config": {}, "events": ["LOOT_CONTAINER"]}, {"_type": "Device", "config": {}, "events": ["LOOT_CONTAINER"]},
{"_type": "Sprite", "name": "barrel_small", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sprite", "name": "barrel_small", "width": 256, "height": 256, "scale": 1.0},
@ -68,8 +68,8 @@
"description": "Something died here. Was this your doing?", "description": "Something died here. Was this your doing?",
"components": [ "components": [
{"_type": "Tile", "display": 8687, {"_type": "Tile", "display": 8687,
"foreground": [32, 123, 164], "foreground": "devices/fg:grave_stone",
"background": [24, 205, 189] "background": "devices/bg:grave_stone"
}, },
{"_type": "Device", "config": {}, "events": ["LOOT_CONTAINER"]}, {"_type": "Device", "config": {}, "events": ["LOOT_CONTAINER"]},
{"_type": "Sprite", "name": "grave_stone", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sprite", "name": "grave_stone", "width": 256, "height": 256, "scale": 1.0},

@ -3,8 +3,8 @@
"placement": "fixed", "placement": "fixed",
"components": [ "components": [
{"_type": "Tile", "display": 41981, {"_type": "Tile", "display": 41981,
"foreground": [255, 200, 125], "foreground": "enemies/fg:player",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Combat", "hp": 200, "max_hp": 200, "damage": 10, "dead": false}, {"_type": "Combat", "hp": 200, "max_hp": 200, "damage": 10, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false},
@ -14,8 +14,8 @@
"GOLD_SAVIOR": { "GOLD_SAVIOR": {
"components": [ "components": [
{"_type": "Tile", "display": 42586, {"_type": "Tile", "display": 42586,
"foreground": [131, 213, 238], "foreground": "enemies/fg:gold_savior",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false},
@ -29,8 +29,8 @@
"KNIGHT": { "KNIGHT": {
"components": [ "components": [
{"_type": "Tile", "display": 2189, {"_type": "Tile", "display": 2189,
"foreground": [131, 213, 238], "foreground": "enemies/fg:knight",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false},
@ -44,8 +44,8 @@
"AXE_RANGER": { "AXE_RANGER": {
"components": [ "components": [
{"_type": "Tile", "display": 1898, {"_type": "Tile", "display": 1898,
"foreground": [156, 172, 197], "foreground": "enemies/fg:axe_ranger",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Combat", "hp": 40, "max_hp": 40, "damage": 10, "dead": false}, {"_type": "Combat", "hp": 40, "max_hp": 40, "damage": 10, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": true},
@ -59,8 +59,8 @@
"RAT_GIANT": { "RAT_GIANT": {
"components": [ "components": [
{"_type": "Tile", "display": 2220, {"_type": "Tile", "display": 2220,
"foreground": [205, 164, 246], "foreground": "enemies/fg:rat_giant",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Combat", "hp": 50, "max_hp": 50, "damage": 2, "dead": false}, {"_type": "Combat", "hp": 50, "max_hp": 50, "damage": 2, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false},
@ -74,8 +74,8 @@
"SPIDER_GIANT_HAIRY": { "SPIDER_GIANT_HAIRY": {
"components": [ "components": [
{"_type": "Tile", "display": 1218, {"_type": "Tile", "display": 1218,
"foreground": [205, 164, 246], "foreground": "enemies/fg:spider_giant",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false},

@ -7,8 +7,8 @@
"components": [ "components": [
{"_type": "LightSource", "strength": 50, "radius": 2.5}, {"_type": "LightSource", "strength": 50, "radius": 2.5},
{"_type": "Tile", "display": 3848, {"_type": "Tile", "display": 3848,
"foreground": [24, 120, 189], "foreground": "items/fg:flame",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Sprite", "name": "torch_horizontal_floor", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sprite", "name": "torch_horizontal_floor", "width": 256, "height": 256, "scale": 1.0},
{"_type": "Sound", "attack": "pickup", "death": "blank"} {"_type": "Sound", "attack": "pickup", "death": "blank"}
@ -21,8 +21,8 @@
"inventory_count": 1, "inventory_count": 1,
"components": [ "components": [
{"_type": "Tile", "display": 1003, {"_type": "Tile", "display": 1003,
"foreground": [255, 205, 189], "foreground": "items/fg:potion",
"background": [0,0,0] "background": "color:transparent"
}, },
{"_type": "Curative", "hp": 20}, {"_type": "Curative", "hp": 20},
{"_type": "Sprite", "name": "healing_potion_small", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sprite", "name": "healing_potion_small", "width": 256, "height": 256, "scale": 1.0},

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

@ -1,4 +1,7 @@
{ {
"color": {
"transparent": [255, 255, 255, 255]
},
"gui/line": { "gui/line": {
"light": [200,200,200], "light": [200,200,200],
"mid": [100,100,100], "mid": [100,100,100],
@ -15,5 +18,48 @@
"light": [200,200,200], "light": [200,200,200],
"mid": [100,100,100], "mid": [100,100,100],
"dark": [10,10,10] "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]
} }
} }

@ -5,7 +5,7 @@
"display": 8284, "display": 8284,
"ceiling": "ceiling_black", "ceiling": "ceiling_black",
"light": 0, "light": 0,
"foreground": [40, 40, 40], "foreground": "tiles/fg:floor_tile",
"id": 0 "id": 0
}, },
"wall_plain": { "wall_plain": {
@ -13,8 +13,8 @@
"collision": true, "collision": true,
"display": 9608, "display": 9608,
"light": 0, "light": 0,
"foreground": [100, 100, 100], "foreground": "tiles/fg:wall_plain",
"background": [10, 10, 10], "background": "tiles/bg:wall_plain",
"id": 1 "id": 1
}, },
"wall_moss": { "wall_moss": {
@ -22,8 +22,8 @@
"collision": true, "collision": true,
"display": 9256, "display": 9256,
"light": 20, "light": 20,
"background": [100, 100, 180], "background": "tiles/bg:wall_moss",
"foreground": [100, 150, 100], "foreground": "tiles/fg:wall_moss",
"id": 2 "id": 2
}, },
"ceiling_black": { "ceiling_black": {
@ -31,7 +31,7 @@
"collision": false, "collision": false,
"display": 35, "display": 35,
"light": 0, "light": 0,
"foreground": [100, 100, 100], "foreground": "tiles/fg:ceiling_black",
"id": 4 "id": 4
}, },
"lava_floor": { "lava_floor": {
@ -40,18 +40,18 @@
"display": 10899, "display": 10899,
"ceiling": "ceiling_black", "ceiling": "ceiling_black",
"light": 20, "light": 20,
"foreground": [200, 100, 100], "foreground": "tiles/fg:lava_floor",
"background": [100, 100, 50], "background": "tiles/bg:lava_floor",
"id": 5 "id": 5
}, },
"gray_stone_floor_light": { "gray_stone_floor_light": {
"texture": "assets/textures/gray_stone_floor_light.png", "texture": "assets/textures/gray_stone_floor_light.png",
"collision": false, "collision": false,
"display": 11590, "display": 11590,
"ceiling": "zceiling_blue_light", "ceiling": "zBUGceiling_blue_light",
"light": 40, "light": 40,
"background": [80, 80, 80], "foreground": "tiles/fg:gray_stone_floor_light",
"foreground": [40, 60, 180], "background": "tiles/bg:gray_stone_floor_light",
"id": 6 "id": 6
}, },
"wood_wall": { "wood_wall": {
@ -59,16 +59,16 @@
"collision": false, "collision": false,
"display": 10747, "display": 10747,
"light": 0, "light": 0,
"foreground": [70, 70, 70], "foreground": "tiles/fg:wood_wall",
"background": [100, 100, 100], "background": "tiles/bg:wood_wall",
"id": 8 "id": 8
}, },
"zceiling_blue_light": { "zBUGceiling_blue_light": {
"texture": "assets/textures/ceiling_blue_light.png", "texture": "assets/textures/ceiling_blue_light.png",
"collision": false, "collision": false,
"display": 8285, "display": 8285,
"light": 0, "light": 0,
"foreground": [100, 100, 100], "foreground": "tiles/fg:BAD",
"id": 7 "id": 7
} }
} }

@ -39,8 +39,8 @@ namespace components {
struct Tile { struct Tile {
wchar_t display; wchar_t display;
std::array<uint8_t, 3> foreground; std::string foreground;
std::array<uint8_t, 3> background; std::string background;
}; };
struct GameConfig { struct GameConfig {

@ -172,7 +172,7 @@ executable('zedcaster',
dependencies: dependencies) dependencies: dependencies)
executable('icongen', 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, cpp_args: cpp_args,
link_args: link_args, link_args: link_args,
override_options: exe_defaults, override_options: exe_defaults,

@ -9,11 +9,13 @@ namespace palette {
struct PaletteMgr { struct PaletteMgr {
std::unordered_map<string, sf::Color> palettes; std::unordered_map<string, sf::Color> palettes;
std::string config;
}; };
static PaletteMgr COLOR; static PaletteMgr COLOR;
void init(const string &json_file) { void init(const string &json_file) {
COLOR.config = json_file;
Config config(json_file); Config config(json_file);
json& colors = config.json(); json& colors = config.json();
@ -23,7 +25,7 @@ namespace palette {
for(auto [value, rgba] : value_specs.items()) { for(auto [value, rgba] : value_specs.items()) {
auto color_path = base_key + ":" + value; auto color_path = base_key + ":" + value;
dbc::check(!COLOR.palettes.contains(color_path), 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]; uint8_t alpha = rgba.size() == 3 ? 255 : (uint8_t)rgba[3];
@ -35,6 +37,17 @@ namespace palette {
} }
sf::Color get(const string& key) { 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); 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);
}
} }

@ -7,4 +7,6 @@ namespace palette {
void init(const std::string &config="assets/palette.json"); void init(const std::string &config="assets/palette.json");
sf::Color get(const string &key); sf::Color get(const string &key);
sf::Color get(const string &key, const string &value);
} }

@ -12,7 +12,7 @@ TEST_CASE("color palette test", "[color-palette]") {
auto gui_text = palette::get("gui/text:dark"); auto gui_text = palette::get("gui/text:dark");
REQUIRE(gui_text == expect); REQUIRE(gui_text == expect);
gui_text = palette::get("gui/text:mid"); gui_text = palette::get("gui/text", "mid");
REQUIRE(gui_text != expect); REQUIRE(gui_text != expect);
expect = {100, 100, 100, 255}; expect = {100, 100, 100, 255};

@ -9,6 +9,7 @@
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include "textures.hpp" #include "textures.hpp"
#include "palette.hpp"
namespace fs = std::filesystem; namespace fs = std::filesystem;
constexpr const int TILE_COUNT=10; 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)); (int)display, (std::string)key));
if(data.contains("foreground")) { if(data.contains("foreground")) {
auto fg_color = data["foreground"]; auto fg = palette::get(data["foreground"]);
sf::Color fg{fg_color[0], fg_color[1], fg_color[2]};
config.colors.insert_or_assign(display, fg); config.colors.insert_or_assign(display, fg);
} else { } else {
config.colors.insert_or_assign(display, DEFAULT_COLOR); config.colors.insert_or_assign(display, DEFAULT_COLOR);
} }
if(data.contains("background")) { if(data.contains("background")) {
auto bg_color = data["background"]; auto bg = palette::get(data["background"]);
sf::Color bg{bg_color[0], bg_color[1], bg_color[2]};
config.backgrounds.insert_or_assign(display, bg); config.backgrounds.insert_or_assign(display, bg);
} else { } else {
sf::Color bg{0, 0, 0, 0}; sf::Color bg{0, 0, 0, 0};
@ -249,6 +248,7 @@ json& component_display(json& val) {
} }
int main() { int main() {
palette::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& {

Loading…
Cancel
Save