2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #include "animationfactory.h"
13 #include "animation.h"
14 #include "namedsprite.h"
15 #include "pointconverter.h"
16 #include "indexconverter.h"
17 #include "graphicalapi.h"
18 #include "mastersettings.h"
21 AnimationPtr
appear(const AnimationSettings
& s
, const NamedSprite
& sprite
, Animate::AnimationType type
) {
23 type
= Animate::Instant
;
27 return AnimationPtr(new FadeAnimation(sprite
.sprite(), 0, 255));
28 case Animate::Instant
:
30 return AnimationPtr(new DropAnimation(sprite
.sprite()));
34 AnimationPtr
disappear(const AnimationSettings
& s
, const NamedSprite
& sprite
, Animate::AnimationType type
) {
36 type
= Animate::Instant
;
40 return AnimationPtr(new FadeAnimation(sprite
.sprite(), 255, 0));
41 case Animate::Instant
:
43 return AnimationPtr(new CaptureAnimation(sprite
.sprite()));
48 AnimationSettings::AnimationSettings() {
52 void AnimationSettings::reload() {
53 Settings s
= settings().group("animations");
55 enabled
= s
.flag("enabled", true);
57 s
.group("sequence").flag("enabled", true)
58 ? s
.group("sequence")["max"].value
<int>()
60 movement
= s
["movement"].flag("enabled", true);
61 explode
= s
["explode"].flag("enabled", true);
62 fading
= s
["fading"].flag("enabled", true);
63 transform
= s
["transform"].flag("enabled", true);
66 AnimationFactory::AnimationFactory(GraphicalAPI
* api
)
68 m_group
= AnimationGroupPtr(new AnimationGroup
);
71 AnimationGroupPtr
AnimationFactory::group() const {
75 void AnimationFactory::setGroup(const AnimationGroupPtr
& group
) {
79 void AnimationFactory::addPreAnimation(const Animate::Scheme
& scheme
, Animate::AnimationType type
) {
80 m_group
->addPreAnimation(m_api
->animate(scheme
, type
));
83 void AnimationFactory::addPostAnimation(const Animate::Scheme
& scheme
, Animate::AnimationType type
) {
84 m_group
->addPostAnimation(m_api
->animate(scheme
, type
));
87 AnimationFactory::operator AnimationGroupPtr() const {
95 move::move(const NamedSprite
& sprite
, const Point
& to
, int type
)
100 AnimationPtr
move::run(const AnimationSettings
& s
, const PointConverter
* converter
, AnimationType type
) const {
101 int mov_type
= m_type
;
104 else if (!s
.transform
) {
105 mov_type
&= ~Rotating
;
110 MovementAnimation
* mov
;
111 QPoint destination
= converter
->toReal(m_to
);
112 Point origin
= converter
->toLogical(m_sprite
.sprite()->pos() +
113 Point(converter
->squareSize(), converter
->squareSize()) / 2);
114 if ((mov_type
& LShaped
) && origin
!= m_to
) {
115 mov
= new KnightMovementAnimation(m_sprite
.sprite(), destination
, mov_type
& Rotating
);
118 mov
= new MovementAnimation(m_sprite
.sprite(), destination
, mov_type
& Rotating
);
120 return AnimationPtr(mov
);
124 return AnimationPtr(new InstantAnimation(m_sprite
.sprite(), converter
->toReal(m_to
)));
128 appear::appear(const NamedSprite
& sprite
)
129 : m_sprite(sprite
) { }
131 AnimationPtr
appear::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
132 return Common::appear(s
, m_sprite
, type
);
135 disappear::disappear(const NamedSprite
& sprite
)
136 : m_sprite(sprite
) { }
138 AnimationPtr
disappear::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
139 return Common::disappear(s
, m_sprite
, type
);
142 destroy::destroy(const NamedSprite
& sprite
)
143 : m_sprite(sprite
) { }
145 AnimationPtr
destroy::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
147 return Common::disappear(s
, m_sprite
, type
);
152 return AnimationPtr(new ExplodeAnimation(m_sprite
.sprite(), Random::instance()));
155 return AnimationPtr(new CaptureAnimation(m_sprite
.sprite()));
159 morph::morph(const NamedSprite
& sprite
, const NamedSprite
& new_sprite
)
161 , m_new_sprite(new_sprite
) { }
163 AnimationPtr
morph::run(const AnimationSettings
& s
, const PointConverter
*, AnimationType type
) const {
169 return AnimationPtr(new CrossFadingAnimation(m_sprite
.sprite(), m_new_sprite
.sprite()));
172 return AnimationPtr(new PromotionAnimation(m_sprite
.sprite(), m_new_sprite
.sprite()));
178 move::move(const NamedSprite
& sprite
, int to
)
182 AnimationPtr
move::run(const AnimationSettings
& s
, const IndexConverter
* converter
, AnimationType type
) const {
188 return AnimationPtr(new MovementAnimation(m_sprite
.sprite(), converter
->toReal(m_to
)));
191 return AnimationPtr(new InstantAnimation(m_sprite
.sprite(), converter
->toReal(m_to
)));
195 appear::appear(const NamedSprite
& sprite
)
196 : m_sprite(sprite
) { }
198 AnimationPtr
appear::run(const AnimationSettings
& s
, const IndexConverter
*, AnimationType type
) const {
199 return Common::appear(s
, m_sprite
, type
);
202 disappear::disappear(const NamedSprite
& sprite
)
203 : m_sprite(sprite
) { }
205 AnimationPtr
disappear::run(const AnimationSettings
& s
, const IndexConverter
*, AnimationType type
) const {
206 return Common::disappear(s
, m_sprite
, type
);