From 06a174040f19051e086ce8c56bbf554bf49083e0 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 27 Sep 2025 11:58:44 -0400 Subject: [PATCH] The whole boss fight scene is now configurable with json. --- assets/bosses.json | 39 ++++++++++++--------------------------- boss/ui.cpp | 16 ++++++++-------- boss/ui.hpp | 5 +++++ components.hpp | 6 ++++-- tests/components.cpp | 6 ------ 5 files changed, 29 insertions(+), 43 deletions(-) diff --git a/assets/bosses.json b/assets/bosses.json index f82834b..3497df3 100644 --- a/assets/bosses.json +++ b/assets/bosses.json @@ -4,7 +4,18 @@ {"_type": "BossFight", "background": "test_background", "floor": "test_floor", - "weapon_sound": "Sword_Hit_2" + "floor_pos": "floor4", + "player": { + "sprite": "test_player", + "start_pos": "player1", + "scale": 0.5, + "mid_cell": false + }, + "boss": { + "start_pos": "boss2", + "scale": 0.7, + "mid_cell": true + } }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, {"_type": "Animation", @@ -19,31 +30,5 @@ {"_type": "Sprite", "name": "test_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false}, {"_type": "Sound", "attack": "Marmot_Scream_1", "death": "Creature_Death_1"} ] - }, - "DEVILS_FINGERS": { - "components": [ - {"_type": "BossFight", - "background": "test_background", - "floor": "test_floor", - "weapon_sound": "Sword_Hit_2" - }, - {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, - {"_type": "Animation", - "easing": 1, - "ease_rate": 0.1, - "simple": false, - "frames": 2, - "speed": 0.02, - "scale": 0.1, - "stationary": true - }, - {"_type": "Sprite", - "name": "test_boss", - "width": 720, - "height": 720, - "scale": 1.0 - }, - {"_type": "Sound", "attack": "Spider_1", "death": "Spider_2"} - ] } } diff --git a/boss/ui.cpp b/boss/ui.cpp index 66a0e90..e28ae35 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -8,23 +8,23 @@ namespace boss { UI::UI(shared_ptr world, Entity boss_id) : $world(world), $boss_id(boss_id), + $scene(world->get($boss_id)), $combat_ui(true) { - auto& sprite = world->get($boss_id); + auto& sprite = $world->get($boss_id); $boss_sprite = textures::get_sprite(sprite.name); - auto& boss_conf = world->get($boss_id); // floor is std::optional - $floor_sprite = textures::get_sprite(*boss_conf.floor); + $floor_sprite = textures::get_sprite(*$scene.floor); - $player_sprite = textures::get_sprite("test_player"); + $player_sprite = textures::get_sprite($scene.player["sprite"]); } void UI::init() { $arena.position(SCREEN_WIDTH-BOSS_VIEW_WIDTH,0, BOSS_VIEW_WIDTH, SCREEN_HEIGHT); $arena.set($arena.MAIN, {$arena.$parser, THEME.DARK_MID}); auto& background = $arena.get($arena.MAIN); - background.set_sprite("test_background", true); + background.set_sprite($scene.background, true); $arena.layout( "[_ |boss1 |boss2 |boss3 |boss4 |_]" @@ -35,9 +35,9 @@ namespace boss { "[floor4|player5|player6|player7|player8|_]" ); - position_sprite($boss_sprite, "boss3", 0.7, true); - position_sprite($player_sprite, "player2", 0.5, false); - position_sprite($floor_sprite, "floor1", 1.0, false); + position_sprite($boss_sprite, $scene.boss["start_pos"], $scene.boss["scale"], $scene.boss["mid_cell"]); + position_sprite($player_sprite, $scene.player["start_pos"], $scene.player["scale"], $scene.player["mid_cell"]); + position_sprite($floor_sprite, $scene.floor_pos, 1.0, false); $arena.init(); diff --git a/boss/ui.hpp b/boss/ui.hpp index 41ea682..a908b1c 100644 --- a/boss/ui.hpp +++ b/boss/ui.hpp @@ -6,6 +6,10 @@ #include "textures.hpp" #include "gui/combat_ui.hpp" +namespace components { + struct BossFight; +} + namespace boss { using std::shared_ptr; using namespace DinkyECS; @@ -14,6 +18,7 @@ namespace boss { struct UI { shared_ptr $world = nullptr; Entity $boss_id = NONE; + components::BossFight& $scene; gui::CombatUI $combat_ui; SpriteTexture $boss_sprite; SpriteTexture $player_sprite; diff --git a/components.hpp b/components.hpp index b8eb454..3d4eba2 100644 --- a/components.hpp +++ b/components.hpp @@ -79,7 +79,9 @@ namespace components { struct BossFight { std::string background; std::optional floor; - std::string weapon_sound; + std::string floor_pos; + json player; + json boss; }; struct Combat { @@ -147,7 +149,7 @@ namespace components { using ComponentMap = std::unordered_map; ENROLL_COMPONENT(Tile, display, foreground, background); - ENROLL_COMPONENT(BossFight, background, floor, weapon_sound); + ENROLL_COMPONENT(BossFight, background, floor, floor_pos, player, boss); ENROLL_COMPONENT(Sprite, name, width, height, scale); ENROLL_COMPONENT(Curative, hp); ENROLL_COMPONENT(LightSource, strength, radius); diff --git a/tests/components.cpp b/tests/components.cpp index 32bbbc4..ff8e43a 100644 --- a/tests/components.cpp +++ b/tests/components.cpp @@ -52,10 +52,4 @@ TEST_CASE("make sure json_mods works", "[components]") { auto boss = world.get(rat_king); REQUIRE(boss.floor != std::nullopt); - - // now load the other one for the other way optional is used - auto devils_fingers = world.entity(); - components::configure_entity(world, devils_fingers, config["DEVILS_FINGERS"]["components"]); - auto boss2 = world.get(devils_fingers); - REQUIRE(boss2.floor != std::nullopt); }