diff --git a/assets/bosses.json b/assets/bosses.json index f1fe420..34db83b 100644 --- a/assets/bosses.json +++ b/assets/bosses.json @@ -2,6 +2,14 @@ "RAT_KING": { "components": [ {"_type": "AnimatedScene", + "layout": [ + "[status|boss1 |boss2 |boss3 |boss4 |_]", + "[torch1|boss5 |boss6 |boss7 |boss8 |torch2]", + "[floor1|boss9 |boss10|boss11|boss12|_]", + "[floor2|boss13|boss14|boss15|boss16|_]", + "[floor3|player1|player2|player3|player4|_]", + "[floor4|player5|player6|player7|player8|_]" + ], "background": "test_background", "floor": false, "floor_pos": "floor1", diff --git a/components.hpp b/components.hpp index d91b522..774d9ac 100644 --- a/components.hpp +++ b/components.hpp @@ -83,6 +83,7 @@ namespace components { struct AnimatedScene { std::string background; + std::vector layout; json actors; json fixtures; }; @@ -149,7 +150,7 @@ namespace components { using ComponentMap = std::unordered_map; ENROLL_COMPONENT(Tile, display, foreground, background); - ENROLL_COMPONENT(AnimatedScene, background, actors, fixtures); + ENROLL_COMPONENT(AnimatedScene, background, layout, actors, fixtures); ENROLL_COMPONENT(Sprite, name, scale); ENROLL_COMPONENT(Curative, hp); ENROLL_COMPONENT(LightSource, strength, radius); diff --git a/scene.cpp b/scene.cpp index 3313b4b..7a9772a 100644 --- a/scene.cpp +++ b/scene.cpp @@ -1,5 +1,6 @@ #include "scene.hpp" #include "animation.hpp" +#include const bool DEBUG=false; const bool YOU_REMOVED_MID_CELL_IDIOT=false; @@ -9,11 +10,7 @@ namespace scene { Element config_scene_element(nlohmann::json& config, bool and_play, bool duped) { std::string sprite_name = config["sprite"]; - auto st = textures::get_sprite(sprite_name); - - if(duped) { - st.sprite = std::make_shared(*st.texture); - } + auto st = textures::get_sprite(sprite_name, duped); float scale_x = config["scale_x"]; float scale_y = config["scale_y"]; @@ -47,6 +44,10 @@ namespace scene { auto element = config_scene_element(fixture, true, true); $fixtures.push_back(element); } + + for(auto& line : $scene.layout) { + $layout.append(line); + } } void Engine::init() { @@ -55,14 +56,7 @@ namespace scene { auto& background = $ui.get($ui.MAIN); background.set_sprite($scene.background, true); - $ui.layout( - "[status|boss1 |boss2 |boss3 |boss4 |_]" - "[torch1|boss5 |boss6 |boss7 |boss8 |torch2]" - "[floor1|boss9 |boss10|boss11|boss12|_]" - "[floor2|boss13|boss14|boss15|boss16|_]" - "[floor3|player1|player2|player3|player4|_]" - "[floor4|player5|player6|player7|player8|_]" - ); + $ui.layout($layout); for(auto& actor : $actors) { actor.pos = position_sprite(actor.st, actor.cell, diff --git a/scene.hpp b/scene.hpp index d74966e..743a7ee 100644 --- a/scene.hpp +++ b/scene.hpp @@ -26,6 +26,7 @@ namespace scene { struct Engine { guecs::UI $ui; components::AnimatedScene& $scene; + std::string $layout; std::unordered_map $actor_name_ids; std::vector $fixtures; std::vector $actors; diff --git a/textures.cpp b/textures.cpp index 0f31e17..225b71d 100644 --- a/textures.cpp +++ b/textures.cpp @@ -146,8 +146,14 @@ namespace textures { return result; } - SpriteTexture get_sprite(const string& name) { - return get(name, TMGR.sprite_textures); + SpriteTexture get_sprite(const string& name, bool duped) { + auto& st = get(name, TMGR.sprite_textures); + + if(duped) { + st.sprite = make_shared(*st.sprite); + } + + return st; } SpriteTexture get_icon(const string& name) { diff --git a/textures.hpp b/textures.hpp index cb7d998..2cafe5f 100644 --- a/textures.hpp +++ b/textures.hpp @@ -31,7 +31,7 @@ namespace textures { void init(); - SpriteTexture get_sprite(const std::string& name); + SpriteTexture get_sprite(const std::string& name, bool duped=false); SpriteTexture get_icon(const std::string& name); sf::Image load_image(const std::string& filename);