GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
SpriteAnimationList.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 
7 #pragma once
8 
9 #include "GDCore/Extensions/Builtin/SpriteExtension/Animation.h"
10 
11 namespace gd {
12 class InitialInstance;
13 class SerializerElement;
14 class PropertyDescriptor;
15 class ArbitraryResourceWorker;
16 } // namespace gd
17 
18 namespace gd {
19 
30 class GD_CORE_API SpriteAnimationList {
31  public:
33  virtual ~SpriteAnimationList();
34 
35  void ExposeResources(gd::ArbitraryResourceWorker& worker);
36 
41  const Animation& GetAnimation(std::size_t nb) const;
42 
47  Animation& GetAnimation(std::size_t nb);
48 
52  std::size_t GetAnimationsCount() const { return animations.size(); };
53 
57  void AddAnimation(const Animation& animation);
58 
62  bool RemoveAnimation(std::size_t nb);
63 
67  void RemoveAllAnimations() { animations.clear(); }
68 
72  bool HasNoAnimations() const { return animations.empty(); }
73 
77  void SwapAnimations(std::size_t firstIndex, std::size_t secondIndex);
78 
82  void MoveAnimation(std::size_t oldIndex, std::size_t newIndex);
83 
88  const std::vector<Animation>& GetAllAnimations() const { return animations; }
89 
94  return adaptCollisionMaskAutomatically;
95  }
96 
101  adaptCollisionMaskAutomatically = enable;
102  }
103 
104  void UnserializeFrom(const gd::SerializerElement& element);
105  void SerializeTo(gd::SerializerElement& element) const;
106 
107  private:
108 
109  mutable std::vector<Animation> animations;
110 
111  static Animation badAnimation; //< Bad animation when an out of bound
112  // animation is requested.
113  bool adaptCollisionMaskAutomatically;
117 };
118 
119 } // namespace gd
Class representing an animation of a SpriteObject.
Definition: Animation.h:22
ArbitraryResourceWorker is used so as to inventory resources and sometimes update them.
Definition: ArbitraryResourceWorker.h:44
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
A list of animations, containing directions with images and collision mask.
Definition: SpriteAnimationList.h:30
std::size_t GetAnimationsCount() const
Return the number of animations this object has.
Definition: SpriteAnimationList.h:52
void RemoveAllAnimations()
Remove all animations.
Definition: SpriteAnimationList.h:67
bool AdaptCollisionMaskAutomatically() const
Check if the collision mask adapts automatically to the animation.
Definition: SpriteAnimationList.h:93
const std::vector< Animation > & GetAllAnimations() const
Return a read-only reference to the vector containing all the animation of the object.
Definition: SpriteAnimationList.h:88
bool HasNoAnimations() const
Return true if the object hasn't any animation.
Definition: SpriteAnimationList.h:72
void SetAdaptCollisionMaskAutomatically(bool enable)
Set if the collision mask adapts automatically to the animation.
Definition: SpriteAnimationList.h:100
Definition: CommonTools.h:24