diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 13:08:35 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 13:08:35 +0100 |
commit | f1788548fdc8491442e199c88058c223f506d42c (patch) | |
tree | 5946c2bd16f019fe2136be74de059f3dfa5a7437 | |
parent | f6d1aa2fe104323b17ef3ed56e33651c67b3febe (diff) | |
parent | 1ef80ecfdc1a70a6ebdd43fed82d0f9d305d63dc (diff) |
Merge branch 'loek/replay' of github.com:lonkaars/crepe into jaro/game
-rw-r--r-- | src/crepe/api/Animator.cpp | 17 | ||||
-rw-r--r-- | src/crepe/api/Animator.h | 6 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index c558d86..f9a283e 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,4 +1,3 @@ - #include "util/dbg.h" #include "Animator.h" @@ -6,6 +5,7 @@ #include "Sprite.h" using namespace crepe; +using namespace std; Animator::Animator( game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, @@ -57,3 +57,18 @@ void Animator::next_anim() { ctx.row = ++ctx.row % this->grid_size.x; this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w; } + +unique_ptr<Component> Animator::save() const { + return unique_ptr<Component>(new Animator(*this)); +} + +void Animator::restore(const Component & snapshot) { + *this = static_cast<const Animator &>(snapshot); +} + +Animator & Animator::operator=(const Animator & snapshot) { + this->data = snapshot.data; + this->elapsed_time = snapshot.elapsed_time; + this->frame = snapshot.frame; + return *this; +} diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 95539d3..d1f49c4 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -108,6 +108,12 @@ private: //! Uses the spritesheet friend AnimatorSystem; + +protected: + virtual std::unique_ptr<Component> save() const; + Animator(const Animator &) = default; + virtual void restore(const Component & snapshot); + virtual Animator & operator=(const Animator &); }; } // namespace crepe |