]> git.localhorst.tv Git - l2e.git/blobdiff - src/graphics/Animation.h
changed how animation runners handle sprite overrides
[l2e.git] / src / graphics / Animation.h
index 0baba35d915e2ee91754a64a7028a5bb2a82a4e3..4442f89efddac88b3ecf7cb178cb219f01a50ca9 100644 (file)
 #include "../app/Application.h"
 #include "../app/State.h"
 #include "../app/Timer.h"
-#include "../geometry/operators.h"
-#include "../geometry/Point.h"
+#include "../loader/fwd.h"
 #include "../geometry/Vector.h"
 
+#include <memory>
 #include <SDL.h>
 
 namespace graphics {
@@ -30,17 +30,24 @@ public:
        virtual ~Animation() { };
 
 public:
-
        const Sprite *GetSprite() const { return sprite; }
        int FrameTime() const { return frameTime; }
        bool Repeat() const { return repeat; }
 
+public:
+       void SetSprite(const Sprite *s) { sprite = s; }
+       void SetFrameTime(int t) { frameTime = t; }
+       void SetRepeat(bool r) { repeat = r; }
+
 public:
        virtual int NumFrames() const = 0;
        virtual int Col(int frame) const = 0;
        virtual int Row(int frame) const = 0;
        virtual geometry::Vector<int> Offset(int frame) const { return geometry::Vector<int>(); }
 
+protected:
+       static void AddFields(loader::TypeDescription &, const Animation &, std::ptrdiff_t offset, int boolId, int numberId, int spriteId);
+
 private:
        const Sprite *sprite;
        int frameTime;
@@ -53,7 +60,7 @@ class AnimationRunner {
 
 public:
        explicit AnimationRunner(const Animation *a = 0, int colOffset = 0, int rowOffset = 0)
-       : animation(a), sprite(a ? a->GetSprite() : 0), colOffset(colOffset), rowOffset(rowOffset) { }
+       : animation(a), sprite(0), colOffset(colOffset), rowOffset(rowOffset) { }
 
 public:
        bool Valid() const { return animation; }
@@ -88,22 +95,24 @@ public:
        void SetRowOffset(int offset) { rowOffset = offset; }
        int RowOffset() const { return rowOffset; }
 
+       void ChangeAnimation(const Animation *a) { animation = a; }
+       const Animation *GetAnimation() const { return animation; }
+
        void ChangeSprite(const Sprite *s) { sprite = s; }
-       const Sprite *GetSprite() const { return sprite; }
+       const Sprite *GetSprite() const { return sprite ? sprite : animation->GetSprite(); }
 
-       void Draw(SDL_Surface *dest, geometry::Point<int> position) const {
-               sprite->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset());
+       void Draw(SDL_Surface *dest, geometry::Vector<int> position) const {
+               GetSprite()->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset());
        }
-       void DrawTopRight(SDL_Surface *dest, geometry::Point<int> position) const {
-               geometry::Vector<int> offset(-sprite->Width(), 0);
+       void DrawTopRight(SDL_Surface *dest, geometry::Vector<int> position) const {
+               geometry::Vector<int> offset(-GetSprite()->Width(), 0);
                Draw(dest, position + offset);
        }
-       void DrawCenter(SDL_Surface *dest, geometry::Point<int> position) const {
-               geometry::Vector<int> offset(-sprite->Width() / 2, -sprite->Height() / 2);
-               Draw(dest, position + offset);
+       void DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const {
+               Draw(dest, position - (GetSprite()->Size() / 2));
        }
-       void DrawCenterBottom(SDL_Surface *dest, geometry::Point<int> position) const {
-               geometry::Vector<int> offset(-sprite->Width() / 2, -sprite->Height());
+       void DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const {
+               geometry::Vector<int> offset(-GetSprite()->Width() / 2, -GetSprite()->Height());
                Draw(dest, position + offset);
        }