Fixed pool update.
[tagua/yd.git] / src / animationfactory.cpp
blobc76aced458dcf4d9946367d2742efb226a9f9510
1 #include "animationfactory.h"
3 #include "animation.h"
4 #include "namedsprite.h"
5 #include "pointconverter.h"
6 #include "graphicalapi.h"
8 AnimationFactory::AnimationFactory(GraphicalAPI* api)
9 : m_api(api) {
10 m_group = AnimationGroupPtr(new AnimationGroup);
13 AnimationGroupPtr AnimationFactory::group() const {
14 return m_group;
17 void AnimationFactory::setGroup(const AnimationGroupPtr& group) {
18 m_group = group;
21 void AnimationFactory::addPreAnimation(const Animate::Scheme& scheme, Animate::AnimationType type) {
22 m_group->addPreAnimation(m_api->animate(scheme, type));
25 void AnimationFactory::addPostAnimation(const Animate::Scheme& scheme, Animate::AnimationType type) {
26 m_group->addPostAnimation(m_api->animate(scheme, type));
29 AnimationFactory::operator AnimationGroupPtr() const {
30 return group();
33 namespace Animate {
35 Scheme::~Scheme() { }
37 move::move(const NamedSprite& sprite, const Point& to, int type)
38 : m_sprite(sprite)
39 , m_to(to)
40 , m_type(type) { }
42 AnimationPtr move::run(const PointConverter* converter, AnimationType type) const {
43 switch (type) {
44 case Normal: {
45 MovementAnimation* mov;
46 if (m_type & LShaped) {
47 mov = new KnightMovementAnimation(m_sprite.sprite(), converter->toReal(m_to), m_type & Rotating);
49 else {
50 mov = new MovementAnimation(m_sprite.sprite(), converter->toReal(m_to), m_type & Rotating);
52 return AnimationPtr(mov);
54 case Instant:
55 default:
56 return AnimationPtr(new InstantAnimation(m_sprite.sprite(), converter->toReal(m_to)));
60 appear::appear(const NamedSprite& sprite)
61 : m_sprite(sprite) { }
63 AnimationPtr appear::run(const PointConverter*, AnimationType type) const {
64 switch (type) {
65 case Normal:
66 return AnimationPtr(new FadeAnimation(m_sprite.sprite(), 0, 255));
67 case Instant:
68 default:
69 return AnimationPtr(new DropAnimation(m_sprite.sprite()));
73 disappear::disappear(const NamedSprite& sprite)
74 : m_sprite(sprite) { }
76 AnimationPtr disappear::run(const PointConverter*, AnimationType type) const {
77 switch (type) {
78 case Normal:
79 return AnimationPtr(new FadeAnimation(m_sprite.sprite(), 255, 0));
80 case Instant:
81 default:
82 return AnimationPtr(new CaptureAnimation(m_sprite.sprite()));
86 destroy::destroy(const NamedSprite& sprite)
87 : m_sprite(sprite) { }
89 AnimationPtr destroy::run(const PointConverter*, AnimationType type) const {
90 switch (type) {
91 case Normal:
92 return AnimationPtr(new ExplodeAnimation(m_sprite.sprite(), Random::instance()));
93 case Instant:
94 default:
95 return AnimationPtr(new CaptureAnimation(m_sprite.sprite()));
99 morph::morph(const NamedSprite& sprite, const NamedSprite& new_sprite)
100 : m_sprite(sprite)
101 , m_new_sprite(new_sprite) { }
103 AnimationPtr morph::run(const PointConverter*, AnimationType type) const {
104 switch (type) {
105 case Normal:
106 return AnimationPtr(new CrossFadingAnimation(m_sprite.sprite(), m_new_sprite.sprite()));
107 case Instant:
108 default:
109 return AnimationPtr(new PromotionAnimation(m_sprite.sprite(), m_new_sprite.sprite()));