From b3b8cbbeeebe88f06061d514962254741e06f9b2 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 1 Mar 2025 00:46:40 -0500 Subject: [PATCH] Started to set things up so that the boss fight UI can load enemies and configs out of the components setup. --- assets/enemies.json | 2 +- boss_fight_ui.cpp | 5 ++++- boss_fight_ui.hpp | 1 + components.cpp | 8 -------- components.hpp | 13 ++++++++----- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/assets/enemies.json b/assets/enemies.json index 6a4167f..c9d266d 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -78,7 +78,7 @@ {"_type": "EnemyConfig", "hearing_distance": 3}, {"_type": "Animation", "easing": 2, "ease_rate": 0.2, "scale": 0.1, "simple": true, "frames": 10, "speed": 1.0}, {"_type": "Sprite", "name": "rat_king"}, - {"_type": "Sound", "attack": "Medium_Rat", "death": "Creature_Death_1"} + {"_type": "Sound", "attack": "Sword_Hit_2", "death": "Creature_Death_1"} ] }, "SPIDER_GIANT_HAIRY": { diff --git a/boss_fight_ui.cpp b/boss_fight_ui.cpp index 11e218c..4ebcde9 100644 --- a/boss_fight_ui.cpp +++ b/boss_fight_ui.cpp @@ -32,6 +32,9 @@ namespace gui { } void BossFightUI::init() { + auto& config = $level.world->get_the(); + $sounds = components::get(config.enemies["RAT_KING"]); + $status.world().set_the({$status.$parser}); for(auto& [name, cell] : $status.cells()) { @@ -65,7 +68,7 @@ namespace gui { $boss_image.sprite->setScale({scale, scale}); if(scale > 1.0) { - if(!sound::playing("Sword_Hit_2")) sound::play("Sword_Hit_2"); + if(!sound::playing($sounds.attack)) sound::play($sounds.attack); $boss_image.sprite->setColor({255,255,255}); } diff --git a/boss_fight_ui.hpp b/boss_fight_ui.hpp index 52190c8..8c7c808 100644 --- a/boss_fight_ui.hpp +++ b/boss_fight_ui.hpp @@ -21,6 +21,7 @@ namespace gui { sf::Clock $clock; int $boss_hp = 10; bool $boss_hit = false; + components::Sound $sounds; GameLevel $level; guecs::UI $status; guecs::UI $overlay; diff --git a/components.cpp b/components.cpp index 6e8fab1..0c93a92 100644 --- a/components.cpp +++ b/components.cpp @@ -3,14 +3,6 @@ #include "easings.hpp" namespace components { - ENROLL_COMPONENT(Position, location.x, location.y); - ENROLL_COMPONENT(EnemyConfig, hearing_distance); - ENROLL_COMPONENT(Motion, dx, dy, random); - ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); - ENROLL_COMPONENT(Device, config, events); - ENROLL_COMPONENT(Animation, scale, simple, frames, speed, easing, ease_rate); - ENROLL_COMPONENT(Sound, attack, death); - void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data) { for (auto &i : data) { dbc::check(i.contains("_type") && i["_type"].is_string(), fmt::format("component has no _type: {}", data.dump())); diff --git a/components.hpp b/components.hpp index 4a21460..38228ff 100644 --- a/components.hpp +++ b/components.hpp @@ -116,14 +116,19 @@ namespace components { template struct NameOf; - // these need to be here if you're using components::convert outside of components.cpp ENROLL_COMPONENT(Tile, display, foreground, background); ENROLL_COMPONENT(Sprite, name); ENROLL_COMPONENT(Curative, hp); ENROLL_COMPONENT(LightSource, strength, radius); ENROLL_COMPONENT(Weapon, damage); ENROLL_COMPONENT(Loot, amount); - + ENROLL_COMPONENT(Position, location.x, location.y); + ENROLL_COMPONENT(EnemyConfig, hearing_distance); + ENROLL_COMPONENT(Motion, dx, dy, random); + ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); + ENROLL_COMPONENT(Device, config, events); + ENROLL_COMPONENT(Animation, scale, simple, frames, speed, easing, ease_rate); + ENROLL_COMPONENT(Sound, attack, death); using ReflFuncSignature = std::function; using ComponentMap = std::unordered_map; @@ -140,9 +145,7 @@ namespace components { template COMPONENT get(nlohmann::json &data) { for (auto &i : data["components"]) { if(i["_type"] == NameOf::name) { - COMPONENT result; - from_json(i, result); - return result; + return convert(i); } }