Can now mark json/components with std::optional and then they can be null/false to disable them.
This commit is contained in:
parent
243b4c2663
commit
281a7f687a
4 changed files with 50 additions and 20 deletions
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "components.hpp"
|
||||
#include "config.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "dinkyecs.hpp"
|
||||
|
@ -7,15 +6,10 @@
|
|||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <functional>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <optional>
|
||||
#include "easings.hpp"
|
||||
#include "json_mods.hpp"
|
||||
|
||||
#define ENROLL_COMPONENT(COMPONENT, ...) \
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(COMPONENT, __VA_ARGS__); \
|
||||
template <> struct NameOf<COMPONENT> { \
|
||||
static constexpr const char *name = #COMPONENT; \
|
||||
};
|
||||
|
||||
namespace components {
|
||||
using namespace nlohmann;
|
||||
|
@ -69,7 +63,7 @@ namespace components {
|
|||
|
||||
struct BossFight {
|
||||
std::string background;
|
||||
std::string stage;
|
||||
std::optional<std::string> stage;
|
||||
std::string weapon_sound;
|
||||
};
|
||||
|
||||
|
@ -126,8 +120,16 @@ namespace components {
|
|||
void step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out);
|
||||
};
|
||||
|
||||
struct Player {
|
||||
DinkyECS::Entity entity;
|
||||
};
|
||||
|
||||
template <typename T> struct NameOf;
|
||||
|
||||
using ReflFuncSignature = std::function<void(DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j)>;
|
||||
|
||||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
||||
|
||||
ENROLL_COMPONENT(Tile, display, foreground, background);
|
||||
ENROLL_COMPONENT(BossFight, background, stage, weapon_sound);
|
||||
ENROLL_COMPONENT(Sprite, name, width, height, scale);
|
||||
|
@ -144,12 +146,6 @@ namespace components {
|
|||
speed, easing, ease_rate, stationary);
|
||||
ENROLL_COMPONENT(Sound, attack, death);
|
||||
|
||||
using ReflFuncSignature = std::function<void(DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j)>;
|
||||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
||||
struct Player {
|
||||
DinkyECS::Entity entity;
|
||||
};
|
||||
|
||||
template<typename COMPONENT> COMPONENT convert(nlohmann::json &data) {
|
||||
COMPONENT result;
|
||||
from_json(data, result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue