1 #include "animationfactory.h"
4 #include "namedsprite.h"
5 #include "pointconverter.h"
6 #include "indexconverter.h"
7 #include "graphicalapi.h"
8 #include "mastersettings.h"
11 AnimationPtr
appear(const AnimationSettings
& s
, const NamedSprite
& sprite
, Animate::AnimationType type
) {
13 type
= Animate::Instant
;
17 return AnimationPtr(new FadeAnimation(sprite
.sprite(), 0, 255));
18 case Animate::Instant
:
20 return AnimationPtr(new DropAnimation(sprite
.sprite()));
24 AnimationPtr
disappear(const AnimationSettings
& s
, const NamedSprite
& sprite
, Animate::AnimationType type
) {
26 type
= Animate::Instant
;
30 return AnimationPtr(new FadeAnimation(sprite
.sprite(), 255, 0));
31 case Animate::Instant
:
33 return AnimationPtr(new CaptureAnimation(sprite
.sprite()));
38 AnimationSettings::AnimationSettings() {
42 void AnimationSettings::reload() {
43 Settings s
= settings().group("animations");
45 enabled
= s
.flag("enabled", true);
47 s
.group("sequence").flag("enabled", true)
48 ? s
.group("sequence")["max"].value
<int>()
50 movement
= s
["movement"].flag("enabled", true);
51 explode
= s
["explode"].flag("enabled", true);
52 fading
= s
["fading"].flag("enabled", true);
53 transform
= s
["transform"].flag("enabled", true);
56 AnimationFactory::AnimationFactory(GraphicalAPI
* api
)
58 m_group
= AnimationGroupPtr(new AnimationGroup
);
61 AnimationGroupPtr
AnimationFactory::group() const {
65 void AnimationFactory::setGroup(const AnimationGroupPtr
& group
) {
69 void AnimationFactory::addPreAnimation(const Animate::Scheme
& scheme
, Animate::AnimationType type
) {
70 m_group
->addPreAnimation(m_api
->animate(scheme
, type
));
73 void AnimationFactory::addPostAnimation(const Animate::Scheme
& scheme
, Animate::AnimationType type
) {
74 m_group
->addPostAnimation(m_api
->animate(scheme
, type
));
77 AnimationFactory::operator AnimationGroupPtr() const {
85 move::move(const NamedSprite
& sprite
, const Point
& to
, int type
)
90 AnimationPtr
move::run(const AnimationSettings
& s
, const PointConverter
* converter
, AnimationType type
) const {
91 int mov_type
= m_type
;
94 else if (!s
.transform
) {
95 mov_type
&= ~Rotating
;
100 MovementAnimation
* mov
;
101 QPoint destination
= converter
->toReal(m_to
);
102 Point origin
= converter
->toLogical(m_sprite
.sprite()->pos() +
103 Point(converter
->squareSize(), converter
->squareSize()) / 2);
104 if ((mov_type
& LShaped
) && origin
!= m_to
) {
105 mov
= new KnightMovementAnimation(m_sprite
.sprite(), destination
, mov_type
& Rotating
);
108 mov
= new MovementAnimation(m_sprite
.sprite(), destination
, mov_type
& Rotating
);
110 return AnimationPtr(mov
);
114 return AnimationPtr(new InstantAnimation(m_sprite
.sprite(), converter
->toReal(m_to
)));
118 appear::appear(const NamedSprite
& sprite
)
119 : m_sprite(sprite
) { }
121 AnimationPtr
appear::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
122 return Common::appear(s
, m_sprite
, type
);
125 disappear::disappear(const NamedSprite
& sprite
)
126 : m_sprite(sprite
) { }
128 AnimationPtr
disappear::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
129 return Common::disappear(s
, m_sprite
, type
);
132 destroy::destroy(const NamedSprite
& sprite
)
133 : m_sprite(sprite
) { }
135 AnimationPtr
destroy::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
137 return Common::disappear(s
, m_sprite
, type
);
142 return AnimationPtr(new ExplodeAnimation(m_sprite
.sprite(), Random::instance()));
145 return AnimationPtr(new CaptureAnimation(m_sprite
.sprite()));
149 morph::morph(const NamedSprite
& sprite
, const NamedSprite
& new_sprite
)
151 , m_new_sprite(new_sprite
) { }
153 AnimationPtr
morph::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
159 return AnimationPtr(new CrossFadingAnimation(m_sprite
.sprite(), m_new_sprite
.sprite()));
162 return AnimationPtr(new PromotionAnimation(m_sprite
.sprite(), m_new_sprite
.sprite()));
168 move::move(const NamedSprite
& sprite
, int to
)
172 AnimationPtr
move::run(const AnimationSettings
& s
, const IndexConverter
* converter
, AnimationType type
) const {
178 return AnimationPtr(new MovementAnimation(m_sprite
.sprite(), converter
->toReal(m_to
)));
181 return AnimationPtr(new InstantAnimation(m_sprite
.sprite(), converter
->toReal(m_to
)));
185 appear::appear(const NamedSprite
& sprite
)
186 : m_sprite(sprite
) { }
188 AnimationPtr
appear::run(const AnimationSettings
& s
, const IndexConverter
*, AnimationType type
) const {
189 return Common::appear(s
, m_sprite
, type
);
192 disappear::disappear(const NamedSprite
& sprite
)
193 : m_sprite(sprite
) { }
195 AnimationPtr
disappear::run(const AnimationSettings
& s
, const IndexConverter
*, AnimationType type
) const {
196 return Common::disappear(s
, m_sprite
, type
);