Add more assertions.
[tagua/yd.git] / src / graphicalsystem.h
blobbf9e82da97eab374275792932977ddc423256a3e
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 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.
9 */
11 #ifndef GRAPHICALSYSTEM_H
12 #define GRAPHICALSYSTEM_H
14 #include <boost/shared_ptr.hpp>
15 #include <QObject>
16 #include <core/taguaapi.h>
17 #include <core/piece.h>
18 #include <core/state_fwd.h>
19 #include <core/namedsprite.h>
21 class ChessBoard;
22 class ChessTable;
23 class Components;
24 class IAnimator;
25 class INamer;
26 class IState;
27 class Move;
28 class IndexConverter;
29 class PointConverter;
30 class UserEntity;
32 class GraphicalSystem : public QObject,
33 private TaguaAPI {
34 Q_OBJECT
36 public:
38 /** The current chess table */
39 ChessTable* m_view;
41 /** The current board */
42 // FIXME: why is this needed? couldn't it be extracted from the view dynamically?
43 ChessBoard* m_board;
45 /** The current state */
46 StatePtr m_state;
48 /** The variant specific animator */
49 IAnimator* m_animator;
51 Components* m_components;
53 /** @a GraphicalPosition interface function implementation */
54 // virtual void addTag(const QString& name, Point, bool over = false);
56 /** @a GraphicalPosition interface function implementation */
57 // virtual void clearTags(const QString& name);
59 /** @a GraphicalPosition interface function implementation */
60 // virtual void setTags(const QString& name, Point p1 = Point::invalid(), Point p2 = Point::invalid(),
61 // Point p3 = Point::invalid(), Point p4 = Point::invalid(),
62 // Point p5 = Point::invalid(), Point p6 = Point::invalid() );
64 public Q_SLOTS:
65 /** internal function to listen at setting changes */
66 void settingsChanged();
68 private:
69 /**
70 * @return the board point converter. (interface for TaguaAPI)
72 virtual const PointConverter* converter() const;
74 /**
75 * @return the index converter of the specified pool.
77 virtual const IndexConverter* indexConverter(int pool) const;
79 /**
80 * @return the current abstract position. (interface for TaguaAPI)
82 virtual const IState* state() const;
84 /**
85 * @return a sprite at the position @a index in the graphical pool. (interface for TaguaAPI)
87 virtual NamedSprite getSprite(const Point& p);
89 /**
90 * Removes a sprite at the position @a index in the graphical pool. (interface for TaguaAPI)
91 * @return the newly created sprite.
93 virtual NamedSprite takeSprite(const Point& p);
95 /**
96 * Sets the piece at the position @a index in the graphical pool. (interface for TaguaAPI)
97 * @return the newly created sprite.
99 virtual NamedSprite setPiece(const Point& p, const Piece& piece, bool show);
102 * Create a new piece, but do not add it to the graphical system.
103 * @return the newly created sprite.
105 virtual NamedSprite createPiece(const Point& p, const Piece& piece, bool show);
108 * Sets the sprite at the position @a index in the graphical pool. (interface for TaguaAPI)
109 * @return the newly created sprite.
111 virtual void setSprite(const Point& p, const NamedSprite& sprite);
114 * @return how many sprites are contained in the pool
116 virtual int poolSize(int pool);
119 * @return the sprite at the position @a index in the graphical pool. (interface for TaguaAPI)
121 virtual NamedSprite getPoolSprite(const IColor* pool, int index);
124 * Removes the sprite at the position @a index in the graphical pool. (interface for TaguaAPI)
126 virtual void removePoolSprite(const IColor* pool, int index);
129 * Removes the sprite at the position @a index in the graphical pool (only for drops).
130 * (interface for TaguaAPI)
131 * @return the removed sprite.
133 virtual NamedSprite takePoolSprite(const IColor* pool, int index);
136 * Inserts a sprite at the position @a index in the graphical pool. (interface for TaguaAPI)
137 * @return the newly created sprite.
139 virtual NamedSprite insertPoolPiece(const IColor* pool,
140 int index,
141 const Piece& piece);
144 * @return the piece of the pool that has been dropped, or (-1,-1). (interface for TaguaAPI)
146 virtual std::pair<const IColor*, int> droppedPoolPiece();
148 public:
149 /** Constructor */
150 GraphicalSystem(ChessTable* view, const StatePtr& startingPosition, Components* components);
151 virtual ~GraphicalSystem();
153 /** Sets the reference entity */
154 void setup(const boost::shared_ptr<UserEntity>& entity);
156 /** Goes forward playing a move, that has to be legal and checked */
157 void forward(const Move& move,
158 const StatePtr& pos,
159 const SpritePtr& = SpritePtr());
161 /** Goes back undoing a move, that has to be legal and checked */
162 void back(const Move& lastMove,
163 const Move& move,
164 const StatePtr& pos);
166 /** Warps to a new position */
167 void warp(const Move& lastMove,
168 const StatePtr& pos);
170 /** Adjusts a sprite to the correct position */
171 void adjustSprite(const Point& p);
173 /** Sets the current turn */
174 void setTurn(const IColor* turn);
178 // TAGUA API
179 Components* components() const;
181 virtual AnimationPtr group(const QString& flags) const;
182 virtual AnimationPtr appear(const NamedSprite& sprite,
183 const QString& flags) const;
184 virtual AnimationPtr disappear(const NamedSprite& sprite,
185 const QString& flags) const;
186 virtual AnimationPtr move(const NamedSprite& sprite,
187 const Point& destination,
188 const QString& flags) const;
189 virtual AnimationPtr move(const NamedSprite& sprite,
190 int pool,
191 int destination,
192 const QString& flags) const;
193 virtual AnimationPtr morph(const NamedSprite& sprite1,
194 const NamedSprite& sprite2,
195 const QString& flags) const;
199 #endif //GRAPHICALSYSTEM_H