Colors are now being loaded from assets/palette.json
This commit is contained in:
		
							parent
							
								
									48a7f72411
								
							
						
					
					
						commit
						f4fa50a413
					
				
					 13 changed files with 113 additions and 52 deletions
				
			
		
							
								
								
									
										4
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								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' | ||||
|  |  | |||
|  | @ -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}, | ||||
|  |  | |||
|  | @ -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}, | ||||
|  |  | |||
|  | @ -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}, | ||||
|  |  | |||
										
											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": { | ||||
|     "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] | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -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 | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -39,8 +39,8 @@ namespace components { | |||
| 
 | ||||
|   struct Tile { | ||||
|     wchar_t display; | ||||
|     std::array<uint8_t, 3> foreground; | ||||
|     std::array<uint8_t, 3> background; | ||||
|     std::string foreground; | ||||
|     std::string background; | ||||
|   }; | ||||
| 
 | ||||
|   struct GameConfig { | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
							
								
								
									
										15
									
								
								palette.cpp
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								palette.cpp
									
										
									
									
									
								
							|  | @ -9,11 +9,13 @@ namespace palette { | |||
| 
 | ||||
|   struct PaletteMgr { | ||||
|     std::unordered_map<string, sf::Color> 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); | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -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); | ||||
| } | ||||
|  |  | |||
|  | @ -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}; | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ | |||
| #include <functional> | ||||
| #include <iostream> | ||||
| #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& { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zed A. Shaw
						Zed A. Shaw