new 4475edb243ed4627f4c5f2c470ca40b3def034d4
[tagua/yd.git] / src / core / baseanimator.cpp
blob4c068f798e930134e37bf629130aa0db366ff43d
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 */
10 #include "baseanimator.h"
12 #include "animation.h"
13 #include "board.h"
14 #include "namer.h"
15 #include "piece.h"
16 #include "state.h"
17 #include "taguaapi.h"
19 BaseAnimator::BaseAnimator(TaguaAPI* api, const INamer* namer)
20 : m_api(api)
21 , m_namer(namer) { }
23 AnimationPtr BaseAnimator::warp(const IState* state) {
24 const IState* current = m_api->state();
25 AnimationPtr res = m_api->group("default");
27 for (int i = 0; i < current->board()->size().x; i++) {
28 for (int j = 0; j < current->board()->size().y; j++) {
29 Point p(i, j);
31 NamedSprite sprite = m_api->getSprite(p);
32 const Piece* piece = state->board()->get(p);
33 AnimationPtr anim;
35 if (!sprite && piece != NULL && *piece != Piece()) {
36 anim = m_api->appear(m_api->setPiece(p, *piece, false), "instant");
39 else if (sprite && (piece == NULL || *piece == Piece())) {
40 m_api->takeSprite(p);
41 anim = m_api->disappear(sprite, "instant");
44 // sprite and piece differ
45 else if (sprite && piece != NULL && *piece != Piece() &&
46 m_namer->name(*piece) != sprite.name()) {
47 m_api->takeSprite(p);
48 anim = m_api->morph(sprite, m_api->setPiece(p, *piece, false), "instant");
51 res->addPreAnimation(anim);
55 return res;
58 AnimationPtr BaseAnimator::forward(const Move&, const IState*) {
59 return AnimationPtr();
62 AnimationPtr BaseAnimator::back(const Move&, const IState*) {
63 return AnimationPtr();