6#include <nlohmann/json.hpp>
60 if (stateStr ==
"DOWN")
62 if (stateStr ==
"DIE")
64 if (stateStr ==
"SHOOT")
76 const nlohmann::json &data) {
79 if (data.contains(
"currentState")) {
80 if (data[
"currentState"].is_string()) {
83 }
else if (data[
"currentState"].is_number()) {
85 static_cast<animState>(data[
"currentState"].get<
int>());
90 if (data.contains(
"clips") && data[
"clips"].is_object()) {
91 for (
const auto &[stateName, clipData] : data[
"clips"].items()) {
93 std::size_t index =
static_cast<std::size_t
>(state);
95 anim.clips[index].startX = clipData.value<uint16_t>(
"startX", 0);
96 anim.clips[index].startY = clipData.value<uint16_t>(
"startY", 0);
97 anim.clips[index].totalFrames =
98 clipData.value<uint16_t>(
"totalFrames", 1);
99 anim.clips[index].frameDuration =
100 clipData.value<
float>(
"frameDuration", 0.1f);
101 anim.clips[index].loop = clipData.value(
"loop",
true);
102 anim.clips[index].reverse = clipData.value(
"reverse",
false);
103 anim.clips[index].frameWidth = clipData.value<uint16_t>(
"frameWidth", 0);
104 anim.clips[index].frameHeight =
105 clipData.value<uint16_t>(
"frameHeight", 0);
animState stringToAnimState(const std::string &stateStr)
Converts a state name to an animState.
Definition Animator.hpp:57
animState
Animation states an animator can switch between.
Definition Animator.hpp:18
void animatorFromJson(rtk::ecs::Registry ®, std::size_t entity, const nlohmann::json &data)
Adds an animator to an entity from its blueprint data.
Definition Animator.hpp:75
@ NONE
No state, forces the next clip to load.
Sprite sheet frames played for one animation state.
Definition Animator.hpp:31
uint16_t totalFrames
Number of frames.
Definition Animator.hpp:34
bool loop
Restarts after the last frame.
Definition Animator.hpp:36
uint16_t frameHeight
Frame height, 0 keeps the current one.
Definition Animator.hpp:39
bool reverse
Plays the frames backwards.
Definition Animator.hpp:37
uint16_t frameWidth
Frame width, 0 keeps the current one.
Definition Animator.hpp:38
uint16_t startY
Y of the first frame in the sheet.
Definition Animator.hpp:33
uint16_t startX
X of the first frame in the sheet.
Definition Animator.hpp:32
float frameDuration
Time per frame, in seconds.
Definition Animator.hpp:35
State machine that picks the Animation clip of an entity.
Definition Animator.hpp:45
animState previousState
Definition Animator.hpp:47
animState currentState
State to display.
Definition Animator.hpp:46
std::array< animationClip, static_cast< std::size_t >(animState::COUNT)> clips
One clip per state.
Definition Animator.hpp:49