The layout is now also coming from the bosses.json file so it's totally configured there.
This commit is contained in:
parent
e5fa76b03c
commit
2d836a9e2a
6 changed files with 27 additions and 17 deletions
|
|
@ -2,6 +2,14 @@
|
||||||
"RAT_KING": {
|
"RAT_KING": {
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "AnimatedScene",
|
{"_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",
|
"background": "test_background",
|
||||||
"floor": false,
|
"floor": false,
|
||||||
"floor_pos": "floor1",
|
"floor_pos": "floor1",
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ namespace components {
|
||||||
|
|
||||||
struct AnimatedScene {
|
struct AnimatedScene {
|
||||||
std::string background;
|
std::string background;
|
||||||
|
std::vector<std::string> layout;
|
||||||
json actors;
|
json actors;
|
||||||
json fixtures;
|
json fixtures;
|
||||||
};
|
};
|
||||||
|
|
@ -149,7 +150,7 @@ namespace components {
|
||||||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
||||||
|
|
||||||
ENROLL_COMPONENT(Tile, display, foreground, background);
|
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(Sprite, name, scale);
|
||||||
ENROLL_COMPONENT(Curative, hp);
|
ENROLL_COMPONENT(Curative, hp);
|
||||||
ENROLL_COMPONENT(LightSource, strength, radius);
|
ENROLL_COMPONENT(LightSource, strength, radius);
|
||||||
|
|
|
||||||
20
scene.cpp
20
scene.cpp
|
|
@ -1,5 +1,6 @@
|
||||||
#include "scene.hpp"
|
#include "scene.hpp"
|
||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
const bool DEBUG=false;
|
const bool DEBUG=false;
|
||||||
const bool YOU_REMOVED_MID_CELL_IDIOT=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) {
|
Element config_scene_element(nlohmann::json& config, bool and_play, bool duped) {
|
||||||
std::string sprite_name = config["sprite"];
|
std::string sprite_name = config["sprite"];
|
||||||
auto st = textures::get_sprite(sprite_name);
|
auto st = textures::get_sprite(sprite_name, duped);
|
||||||
|
|
||||||
if(duped) {
|
|
||||||
st.sprite = std::make_shared<sf::Sprite>(*st.texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
float scale_x = config["scale_x"];
|
float scale_x = config["scale_x"];
|
||||||
float scale_y = config["scale_y"];
|
float scale_y = config["scale_y"];
|
||||||
|
|
@ -47,6 +44,10 @@ namespace scene {
|
||||||
auto element = config_scene_element(fixture, true, true);
|
auto element = config_scene_element(fixture, true, true);
|
||||||
$fixtures.push_back(element);
|
$fixtures.push_back(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(auto& line : $scene.layout) {
|
||||||
|
$layout.append(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::init() {
|
void Engine::init() {
|
||||||
|
|
@ -55,14 +56,7 @@ namespace scene {
|
||||||
auto& background = $ui.get<Background>($ui.MAIN);
|
auto& background = $ui.get<Background>($ui.MAIN);
|
||||||
background.set_sprite($scene.background, true);
|
background.set_sprite($scene.background, true);
|
||||||
|
|
||||||
$ui.layout(
|
$ui.layout($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|_]"
|
|
||||||
);
|
|
||||||
|
|
||||||
for(auto& actor : $actors) {
|
for(auto& actor : $actors) {
|
||||||
actor.pos = position_sprite(actor.st, actor.cell,
|
actor.pos = position_sprite(actor.st, actor.cell,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ namespace scene {
|
||||||
struct Engine {
|
struct Engine {
|
||||||
guecs::UI $ui;
|
guecs::UI $ui;
|
||||||
components::AnimatedScene& $scene;
|
components::AnimatedScene& $scene;
|
||||||
|
std::string $layout;
|
||||||
std::unordered_map<std::string, int> $actor_name_ids;
|
std::unordered_map<std::string, int> $actor_name_ids;
|
||||||
std::vector<Element> $fixtures;
|
std::vector<Element> $fixtures;
|
||||||
std::vector<Element> $actors;
|
std::vector<Element> $actors;
|
||||||
|
|
|
||||||
10
textures.cpp
10
textures.cpp
|
|
@ -146,8 +146,14 @@ namespace textures {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteTexture get_sprite(const string& name) {
|
SpriteTexture get_sprite(const string& name, bool duped) {
|
||||||
return get(name, TMGR.sprite_textures);
|
auto& st = get(name, TMGR.sprite_textures);
|
||||||
|
|
||||||
|
if(duped) {
|
||||||
|
st.sprite = make_shared<sf::Sprite>(*st.sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteTexture get_icon(const string& name) {
|
SpriteTexture get_icon(const string& name) {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace textures {
|
||||||
|
|
||||||
void init();
|
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);
|
SpriteTexture get_icon(const std::string& name);
|
||||||
|
|
||||||
sf::Image load_image(const std::string& filename);
|
sf::Image load_image(const std::string& filename);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue