From 7c56f350ab53ac6eb4e9b34508c848dd5f462e84 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 28 Jan 2025 14:04:01 -0500 Subject: [PATCH] Enemies now actually adopt their color and all items too. --- assets/items.json | 24 ++++++++++++------------ components.cpp | 9 ++++++++- components.hpp | 7 +++++++ systems.cpp | 4 ++-- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/assets/items.json b/assets/items.json index a80a419..3580cd5 100644 --- a/assets/items.json +++ b/assets/items.json @@ -2,8 +2,8 @@ "TORCH_BAD": { "id": "TORCH_BAD", "name": "Crappy Torch", - "foreground": [24, 205, 189], - "background": [230, 20, 120], + "foreground": [24, 120, 189], + "background": [230,120, 120], "description": "A torch that barely lights the way. You wonder if it'd be better to not see the person who murders you.", "inventory_count": 1, "components": [ @@ -14,8 +14,8 @@ "SWORD_RUSTY": { "id": "SWORD_RUSTY", "name": "Rusty Junk Sword", - "foreground": [24, 205, 189], - "background": [24, 205, 189], + "foreground": [24, 120, 189], + "background": [24, 120, 189], "description": "A sword left to rot in a deep hole where it acquired a patina of dirt and tetanus. You aren't sure if it's more deadly for you to hold it or for the people you stab with it.", "inventory_count": 1, "components": [ @@ -26,8 +26,8 @@ "SWORD_LIGHT_AND_FLAME": { "id": "SWORD_LIGHT_AND_FLAME", "name": "Sword of Light and Flame", - "foreground": [24, 205, 189], - "background": [24, 205, 189], + "foreground": [24, 205, 210], + "background": [24, 205, 210], "description": "A sword so powerful, a great man from the Land of The Rising Sun thrust it into the ocean of Nerf to chill its effects.", "inventory_count": 1, "components": [ @@ -39,8 +39,8 @@ "CHEST_SMALL": { "id": "CHEST_SMALL", "name": "Small Chest", - "foreground": [24, 205, 189], - "background": [24, 205, 189], + "foreground": [150, 100, 189], + "background": [150, 100, 189], "description": "A small chest of gold. You wonder who would leave something like this around.", "components": [ {"type": "Tile", "config": {"chr": "\uaaea"}}, @@ -51,8 +51,8 @@ "WALL_TORCH": { "id": "WALL_TORCH", "name": "Basic Wall Torch", - "foreground": [24, 205, 189], - "background": [24, 205, 189], + "foreground": [24, 205, 210], + "background": [24, 205, 210], "description": "A torch on a wall you can't pick up.", "inventory_count": 0, "components": [ @@ -63,8 +63,8 @@ "POTION_HEALING_SMALL": { "id": "POTION_HEALING_SMALL", "name": "Small Healing Potion", - "foreground": [24, 205, 189], - "background": [24, 205, 189], + "foreground": [255, 205, 189], + "background": [255, 205, 189], "description": "A small healing potion.", "inventory_count": 1, "components": [ diff --git a/components.cpp b/components.cpp index c5e3893..3d2e0e7 100644 --- a/components.cpp +++ b/components.cpp @@ -13,7 +13,14 @@ namespace components { } else if(comp_type == "Loot") { world.set(entity, {config["amount"]}); } else if(comp_type == "Tile") { - world.set(entity, {config["chr"]}); + world.set(entity, { + config["chr"], + entity_data["foreground"][0], + entity_data["foreground"][1], + entity_data["foreground"][2], + entity_data["background"][0], + entity_data["background"][1], + entity_data["background"][2]}); } else if(comp_type == "EnemyConfig") { world.set(entity, {config["hearing_distance"]}); } else if(comp_type == "Combat") { diff --git a/components.hpp b/components.hpp index ee0ffae..7f47c2e 100644 --- a/components.hpp +++ b/components.hpp @@ -32,6 +32,13 @@ namespace components { struct Tile { std::string chr; + uint8_t fg_h = 0; + uint8_t fg_s = 0; + uint8_t fg_v = 0; + uint8_t bg_h = 0; + uint8_t bg_s = 0; + uint8_t bg_v = 0; + DEFINE_SERIALIZABLE(Tile, chr); }; diff --git a/systems.cpp b/systems.cpp index 5269f2a..d930740 100644 --- a/systems.cpp +++ b/systems.cpp @@ -213,8 +213,8 @@ void System::draw_entities(DinkyECS::World &world, Map &map, const Matrix &light const TileCell& cell = tiles.at(pos.location.x, pos.location.y); // the 2 and 4 are from ftxui::Canvas since it does a kind of "subpixel" drawing - canvas.DrawText(loc.x*2, loc.y*4, tile.chr, [light_value, cell](auto &pixel) { - pixel.foreground_color = Color::HSV(255, 200, 180 * light_value); + canvas.DrawText(loc.x*2, loc.y*4, tile.chr, [tile, light_value, cell](auto &pixel) { + pixel.foreground_color = Color::HSV(tile.fg_h, tile.fg_s, tile.fg_v * light_value); pixel.background_color = Color::HSV(cell.bg_h, cell.bg_s, cell.bg_v * light_value); }); }