From e487f0426d9de022b759ae6a529b10a72c31de8f Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Tue, 20 Nov 2007 14:25:15 +0100
Subject: [PATCH] Initial porting to the new component API.
Note: merging changes prior to this commit may be a nightmare. A lot of files
have been moved to core/, and a lot of types and method names have changed.
If you have changes in hlvariant/, they will probably merge cleanly, but still
have to be rewritten to be adapted to the new API.
If your changes touch files like board.cpp (which has been renamed to
chessboard.cpp, btw), piecepool.cpp, game.cpp or graphicalsystem.cpp, then
good luck :)
---
src/CMakeLists.txt | 61 ++--
src/agent.h | 1 -
src/agentgroup.h | 1 -
src/animation.h | 2 +-
src/animationfactory.cpp | 202 -----------
src/animationfactory.h | 223 ------------
src/animationsettings.cpp | 29 ++
src/{graphicalapi.cpp => animationsettings.h} | 18 +-
src/{board.cpp => chessboard.cpp} | 169 +++++----
src/{board.h => chessboard.h} | 48 +--
src/chesstable.cpp | 15 +-
src/chesstable.h | 14 +-
src/controllers/abstract.h | 14 +-
src/controllers/editgame.cpp | 147 ++++----
src/controllers/editgame.h | 24 +-
src/controllers/editposition.h | 1 -
src/core/CMakeLists.txt | 3 +
src/core/board.h | 2 +
src/core/color.cpp | 4 +
src/core/color.h | 7 +
src/core/defaultpolicy.cpp | 32 ++
src/core/defaultpolicy.h | 29 ++
src/{ => core}/interactiontype.h | 0
src/core/move.cpp | 4 +-
src/core/move.h | 8 +-
src/core/moveserializer.h | 3 +-
src/{graphicalapi.cpp => core/policy.cpp} | 6 +-
src/core/policy.h | 43 +++
.../poolcollection_fwd.h} | 10 +-
src/core/repository.h | 19 +-
src/core/state.h | 7 +-
src/{graphicalapi.cpp => core/state_fwd.h} | 10 +-
src/core/taguaapi.h | 3 +-
src/{ => core}/turnpolicy.cpp | 6 +-
src/{ => core}/turnpolicy.h | 14 +-
src/core/variant.h | 5 +
src/engine.h | 11 +-
src/engineinfo.cpp | 18 +-
src/engineinfo.h | 14 +-
src/entities/engineentity.cpp | 19 +-
src/entities/engineentity.h | 10 +-
src/entities/entity.cpp | 2 +-
src/entities/entity.h | 5 +-
src/entities/examinationentity.cpp | 29 +-
src/entities/examinationentity.h | 29 +-
src/entities/gameentity.cpp | 89 ++---
src/entities/gameentity.h | 40 ++-
src/entities/icsentity.cpp | 76 ++--
src/entities/icsentity.h | 33 +-
src/entities/userentity.cpp | 8 -
src/entities/userentity.h | 29 +-
src/fwd.h | 59 ---
src/game.cpp | 68 ++--
src/game.h | 26 +-
src/{graphicalapi.cpp => game_fwd.h} | 11 +-
src/game_p.h | 8 +-
src/gnushogiengine.cpp | 17 +-
src/gnushogiengine.h | 14 +-
src/graphicalapi.h | 115 ------
src/graphicalgame.cpp | 43 ++-
src/graphicalgame.h | 3 +
src/graphicalsystem.cpp | 166 ++++-----
src/graphicalsystem.h | 69 ++--
src/hlvariant/animator.h | 2 -
src/hlvariant/dropanimator.h | 3 +-
src/hlvariant/graphicalapi_unwrapped.h | 2 +-
src/hlvariant/movefactory.h | 1 -
src/hlvariant/tagua_wrapped.h | 2 -
src/icsapi.h | 18 +-
src/{graphicalapi.cpp => icsapi_fwd.h} | 10 +-
src/icsconnection.cpp | 14 +-
src/icsgamedata.cpp | 13 +-
src/icsgamedata.h | 5 +-
src/{premove.h => icslistener.h} | 25 +-
src/mainwindow.cpp | 34 +-
src/mainwindow.h | 4 +-
src/movefactory.h | 1 -
src/piecepool.cpp | 44 ++-
src/piecepool.h | 13 +-
src/poolinfo.h | 7 +-
src/positioninfo.cpp | 13 +-
src/positioninfo.h | 10 +-
src/pref_theme.cpp | 33 +-
src/pref_theme.h | 5 +-
src/premove.cpp | 27 --
src/tagua.h | 397 ---------------------
src/tagua_legacy.cpp | 282 ---------------
src/tagua_legacy.h | 118 ------
src/ui.cpp | 4 +-
src/ui.h | 13 +-
src/usermove.h | 1 -
src/variants.cpp | 122 +++----
src/variants.h | 13 +-
src/variants/chess/chess.cpp | 10 +-
src/variants/chess/namer.h | 3 +-
src/variants/chess/state.cpp | 6 +
src/variants/chess/state.h | 2 +
src/variants/chess/validator.h | 3 +-
src/xboardengine.cpp | 33 +-
src/xboardengine.h | 15 +-
100 files changed, 1144 insertions(+), 2359 deletions(-)
delete mode 100644 src/animationfactory.cpp
delete mode 100644 src/animationfactory.h
create mode 100644 src/animationsettings.cpp
copy src/{graphicalapi.cpp => animationsettings.h} (54%)
rename src/{board.cpp => chessboard.cpp} (80%)
rename src/{board.h => chessboard.h} (92%)
create mode 100644 src/core/defaultpolicy.cpp
create mode 100644 src/core/defaultpolicy.h
rename src/{ => core}/interactiontype.h (100%)
copy src/{graphicalapi.cpp => core/policy.cpp} (71%)
create mode 100644 src/core/policy.h
copy src/{graphicalapi.cpp => core/poolcollection_fwd.h} (60%)
copy src/{graphicalapi.cpp => core/state_fwd.h} (65%)
rename src/{ => core}/turnpolicy.cpp (85%)
rename src/{ => core}/turnpolicy.h (81%)
delete mode 100644 src/fwd.h
copy src/{graphicalapi.cpp => game_fwd.h} (68%)
delete mode 100644 src/graphicalapi.h
rename src/{graphicalapi.cpp => icsapi_fwd.h} (67%)
rename src/{premove.h => icslistener.h} (50%)
delete mode 100644 src/premove.cpp
delete mode 100644 src/tagua.h
delete mode 100644 src/tagua_legacy.cpp
delete mode 100644 src/tagua_legacy.h
rewrite src/variants.cpp (65%)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ae2d525..7161c2f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,45 +22,42 @@ set(tagua_SRC
entities/entity.cpp
entities/engineentity.cpp
entities/icsentity.cpp
-
- hlvariant/chess/variant.cpp
- hlvariant/chess/san.cpp
- hlvariant/chess/icsverbose.cpp
- hlvariant/chess/move.cpp
- hlvariant/chess/gamestate.cpp
- hlvariant/chess/piece.cpp
- hlvariant/chess/actions.cpp
-
- hlvariant/dummy/variant.cpp
-
- hlvariant/crazyhouse/variant.cpp
- hlvariant/crazyhouse/piece.cpp
-
- hlvariant/minichess5/variant.cpp
-
- hlvariant/shogi/variant.cpp
- hlvariant/shogi/piece.cpp
- hlvariant/shogi/shogiactions.cpp
+#
+# hlvariant/chess/variant.cpp
+# hlvariant/chess/san.cpp
+# hlvariant/chess/icsverbose.cpp
+# hlvariant/chess/move.cpp
+# hlvariant/chess/gamestate.cpp
+# hlvariant/chess/piece.cpp
+# hlvariant/chess/actions.cpp
+#
+# hlvariant/dummy/variant.cpp
+#
+# hlvariant/crazyhouse/variant.cpp
+# hlvariant/crazyhouse/piece.cpp
+#
+# hlvariant/minichess5/variant.cpp
+#
+# hlvariant/shogi/variant.cpp
+# hlvariant/shogi/piece.cpp
+# hlvariant/shogi/shogiactions.cpp
+#
+# hlvariant/minishogi/variant.cpp
+#
+# hlvariant/sho-shogi/variant.cpp
+#
+# hlvariant/tori-shogi/variant.cpp
+# hlvariant/tori-shogi/piece.cpp
- hlvariant/minishogi/variant.cpp
-
- hlvariant/sho-shogi/variant.cpp
-
- hlvariant/tori-shogi/variant.cpp
- hlvariant/tori-shogi/piece.cpp
-
- animationfactory.cpp
constrainedtext.cpp
movelist.cpp
infodisplay.cpp
engineinfo.cpp
- premove.cpp
mainanimation.cpp
random.cpp
sprite.cpp
pref_movelist.cpp
option.cpp
- graphicalapi.cpp
graphicalsystem.cpp
agentgroup.cpp
graphicalgame.cpp
@@ -96,7 +93,7 @@ set(tagua_SRC
movelist_textual.cpp
icsconnection.cpp
mainwindow.cpp
- board.cpp
+ chessboard.cpp
common.cpp
pgnparser.cpp
movement.cpp
@@ -107,13 +104,11 @@ set(tagua_SRC
themeinfo.cpp
namedsprite_utils.cpp
icsgamedata.cpp
- turnpolicy.cpp
decoratedmove.cpp
variants.cpp
actioncollection.cpp
tabwidget.cpp
-
- tagua_legacy.cpp
+ animationsettings.cpp
)
# remove spurious xpressive warnings
diff --git a/src/agent.h b/src/agent.h
index c6efe3a..35faf38 100644
--- a/src/agent.h
+++ b/src/agent.h
@@ -11,7 +11,6 @@
#ifndef AGENT_H
#define AGENT_H
-#include "fwd.h"
class Index;
class Agent {
diff --git a/src/agentgroup.h b/src/agentgroup.h
index 43c2ce5..5b7b39a 100644
--- a/src/agentgroup.h
+++ b/src/agentgroup.h
@@ -14,7 +14,6 @@
#include
#include
#include "weakset.h"
-#include "tagua.h"
#include "agent.h"
class AgentGroup {
diff --git a/src/animation.h b/src/animation.h
index e792490..4a3f570 100644
--- a/src/animation.h
+++ b/src/animation.h
@@ -18,8 +18,8 @@
#include
#include
+#include
#include "sprite.h"
-#include "fwd.h"
class Movement;
class Random;
diff --git a/src/animationfactory.cpp b/src/animationfactory.cpp
deleted file mode 100644
index 9f4b384..0000000
--- a/src/animationfactory.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-#include "animationfactory.h"
-
-#include
-#include "animation.h"
-#include "pointconverter.h"
-#include "indexconverter.h"
-#include "graphicalapi.h"
-#include "mastersettings.h"
-
-namespace Common {
- AnimationPtr appear(const AnimationSettings& s, const NamedSprite& sprite, Animate::AnimationType type) {
- if (!s.fading)
- type = Animate::Instant;
-
- switch (type) {
- case Animate::Normal:
- return AnimationPtr(new FadeAnimation(sprite.sprite(), 0, 255));
- case Animate::Instant:
- default:
- return AnimationPtr(new DropAnimation(sprite.sprite()));
- }
- }
-
- AnimationPtr disappear(const AnimationSettings& s, const NamedSprite& sprite, Animate::AnimationType type) {
- if (!s.fading)
- type = Animate::Instant;
-
- switch (type) {
- case Animate::Normal:
- return AnimationPtr(new FadeAnimation(sprite.sprite(), 255, 0));
- case Animate::Instant:
- default:
- return AnimationPtr(new CaptureAnimation(sprite.sprite()));
- }
- }
-};
-
-AnimationSettings::AnimationSettings() {
- reload();
-}
-
-void AnimationSettings::reload() {
- Settings s = settings().group("animations");
-
- enabled = s.flag("enabled", true);
- maxSequence =
- s.group("sequence").flag("enabled", true)
- ? s.group("sequence")["max"].value()
- : 0;
- movement = s["movement"].flag("enabled", true);
- explode = s["explode"].flag("enabled", true);
- fading = s["fading"].flag("enabled", true);
- transform = s["transform"].flag("enabled", true);
-}
-
-AnimationFactory::AnimationFactory(GraphicalAPI* api)
-: m_api(api) {
- m_group = AnimationGroupPtr(new AnimationGroup);
-}
-
-AnimationGroupPtr AnimationFactory::group() const {
- return m_group;
-}
-
-void AnimationFactory::setGroup(const AnimationGroupPtr& group) {
- m_group = group;
-}
-
-void AnimationFactory::addPreAnimation(const Animate::Scheme& scheme, Animate::AnimationType type) {
- m_group->addPreAnimation(m_api->animate(scheme, type));
-}
-
-void AnimationFactory::addPostAnimation(const Animate::Scheme& scheme, Animate::AnimationType type) {
- m_group->addPostAnimation(m_api->animate(scheme, type));
-}
-
-AnimationFactory::operator AnimationGroupPtr() const {
- return group();
-}
-
-namespace Animate {
-
- Scheme::~Scheme() { }
-
- move::move(const NamedSprite& sprite, const Point& to, int type)
- : m_sprite(sprite)
- , m_to(to)
- , m_type(type) { }
-
- AnimationPtr move::run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const {
- int mov_type = m_type;
- if (!s.movement)
- type = Instant;
- else if (!s.transform) {
- mov_type &= ~Rotating;
- }
-
- switch (type) {
- case Normal: {
- MovementAnimation* mov;
- QPoint destination = converter->toReal(m_to);
- Point origin = converter->toLogical(m_sprite.sprite()->pos() +
- Point(converter->squareSize(), converter->squareSize()) / 2);
- if ((mov_type & LShaped) && origin != m_to) {
- mov = new KnightMovementAnimation(m_sprite.sprite(), destination, mov_type & Rotating);
- }
- else {
- mov = new MovementAnimation(m_sprite.sprite(), destination, mov_type & Rotating);
- }
- return AnimationPtr(mov);
- }
- case Instant:
- default:
- return AnimationPtr(new InstantAnimation(m_sprite.sprite(), converter->toReal(m_to)));
- }
- }
-
- appear::appear(const NamedSprite& sprite)
- : m_sprite(sprite) { }
-
- AnimationPtr appear::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const {
- return Common::appear(s, m_sprite, type);
- }
-
- disappear::disappear(const NamedSprite& sprite)
- : m_sprite(sprite) { }
-
- AnimationPtr disappear::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const {
- return Common::disappear(s, m_sprite, type);
- }
-
- destroy::destroy(const NamedSprite& sprite)
- : m_sprite(sprite) { }
-
- AnimationPtr destroy::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const {
- if (!s.explode) {
- return Common::disappear(s, m_sprite, type);
- }
-
- switch (type) {
- case Normal:
- return AnimationPtr(new ExplodeAnimation(m_sprite.sprite(), Random::instance()));
- case Instant:
- default:
- return AnimationPtr(new CaptureAnimation(m_sprite.sprite()));
- }
- }
-
- morph::morph(const NamedSprite& sprite, const NamedSprite& new_sprite)
- : m_sprite(sprite)
- , m_new_sprite(new_sprite) { }
-
- AnimationPtr morph::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const {
- if (!s.fading)
- type = Instant;
-
- switch (type) {
- case Normal:
- return AnimationPtr(new CrossFadingAnimation(m_sprite.sprite(), m_new_sprite.sprite()));
- case Instant:
- default:
- return AnimationPtr(new PromotionAnimation(m_sprite.sprite(), m_new_sprite.sprite()));
- }
- }
-
- namespace Pool {
-
- move::move(const NamedSprite& sprite, int to)
- : m_sprite(sprite)
- , m_to(to) { }
-
- AnimationPtr move::run(const AnimationSettings& s, const IndexConverter* converter, AnimationType type) const {
- if (!s.movement)
- type = Instant;
-
- switch (type) {
- case Normal:
- return AnimationPtr(new MovementAnimation(m_sprite.sprite(), converter->toReal(m_to)));
- case Instant:
- default:
- return AnimationPtr(new InstantAnimation(m_sprite.sprite(), converter->toReal(m_to)));
- }
- }
-
- appear::appear(const NamedSprite& sprite)
- : m_sprite(sprite) { }
-
- AnimationPtr appear::run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const {
- return Common::appear(s, m_sprite, type);
- }
-
- disappear::disappear(const NamedSprite& sprite)
- : m_sprite(sprite) { }
-
- AnimationPtr disappear::run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const {
- return Common::disappear(s, m_sprite, type);
- }
-
- }
-
-}
-
diff --git a/src/animationfactory.h b/src/animationfactory.h
deleted file mode 100644
index 0d5a6cd..0000000
--- a/src/animationfactory.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- Copyright (c) 2007 Paolo Capriotti
- (c) 2007 Maurizio Monge
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-*/
-
-#ifndef ANIMATIONFACTORY_H
-#define ANIMATIONFACTORY_H
-
-#include "animation.h"
-#include "fwd.h"
-#include
-
-class NamedSprite;
-class PointConverter;
-class IndexConverter;
-class GraphicalAPI;
-class AnimationSettings;
-
-namespace Animate {
-
- /**
- * AnimationType distinguishes between those animations which honor settings
- * and those that are instantaneous regardless of user preferences.
- */
- enum AnimationType {
- Normal, /// Honor user settings.
- Instant /// Instantaneous animation.
- };
-
- /**
- * @brief A scheme of animations.
- *
- * Animation schemes are descriptions of an animation, i.e. what the animation
- * should suggest to the user. The actual Animation class implementing the scheme
- * depends of various factors, such as the AnimationType that the animator imposes
- * and user settings.
- */
- class Scheme {
- public:
- virtual ~Scheme();
-
- /**
- * Convert the scheme into an actual animation which can be enqueued in the
- * animation system, or grouped into an AnimationGroup.
- */
- virtual AnimationPtr run(const AnimationSettings& s, const PointConverter*, AnimationType) const = 0;
- };
-
-}
-
-struct AnimationSettings {
- bool enabled;
-
- int maxSequence;
- bool movement;
- bool explode;
- bool fading;
- bool transform;
-
- AnimationSettings();
- void reload();
-};
-
-/**
- * @brief A convenience wrapper around an AnimationGroup, useful for Animators.
- *
- * An AnimationFactory is a wrapper around AnimationGroup that accepts shemes instead
- * of Animations in its addPreAnimation() and addPostAnimation() methods.
- * It offers a convenient syntax to an animator when composing animations into groups.
- */
-class AnimationFactory {
- AnimationGroupPtr m_group;
- GraphicalAPI* m_api;
-public:
- AnimationFactory(GraphicalAPI* api);
-
- /** \return The wrapped animation group. */
- AnimationGroupPtr group() const;
-
- /** Change the wrapped animation group. */
- void setGroup(const AnimationGroupPtr& group);
-
- /**
- * Add a pre-animation to the group.
- * \param scheme The scheme producing the animation to be added.
- * \param type The AnimationType to be used when creating the animation.
- */
- void addPreAnimation(const Animate::Scheme& scheme, Animate::AnimationType type = Animate::Normal);
-
- /**
- * Add a post-animation to the group.
- * \param scheme The scheme producing the animation to be added.
- * \param type The AnimationType to be used when creating the animation.
- */
- void addPostAnimation(const Animate::Scheme& scheme, Animate::AnimationType type = Animate::Normal);
-
- /**
- * Implicitly convert the object to an AnimationGroup shared pointer,
- * using the group() member function.
- */
- operator AnimationGroupPtr() const;
-};
-
-namespace Animate {
-
- /**
- * @brief A movement animation scheme.
- *
- * Used to animate the movement of a piece on the board to a destination square.
- */
- class move : public Scheme {
- public:
- enum MovementType {
- Straight = 0x00,
- Rotating = 0x01,
- LShaped = 0x02
- };
- private:
- const NamedSprite& m_sprite;
- Point m_to;
- int m_type;
- public:
- move(const NamedSprite& sprite, const Point& to, int type = Straight);
- virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
- };
-
- /**
- * @brief Appear animation scheme.
- *
- * The appear scheme visualizes a new piece coming into existence. It is
- * used, for example, when retracting a capture in chess, to restore the captured
- * piece on the chessboard.
- */
- class appear : public Scheme {
- const NamedSprite& m_sprite;
- public:
- appear(const NamedSprite& sprite);
- virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
- };
-
- /**
- * @brief Disappear animation scheme.
- *
- * The disappear scheme visualizes a piece being removed from the board.
- */
- class disappear : public Scheme {
- const NamedSprite& m_sprite;
- public:
- disappear(const NamedSprite& sprite);
- virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
- };
-
- /**
- * @brief Animation scheme destroying a piece.
- *
- * This animation scheme is used to destroy a piece, removing it from the
- * board. It is similar to the disappear scheme, but can provide an additional
- * effect like an explosion.
- */
- class destroy : public Scheme {
- const NamedSprite& m_sprite;
- public:
- destroy(const NamedSprite& sprite);
- virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
- };
-
- /**
- * @brief Animation scheme for changing a piece into another.
- *
- * The morph animation scheme is used when a piece changes, like in chess promotions.
- */
- class morph : public Scheme {
- const NamedSprite& m_sprite;
- const NamedSprite& m_new_sprite;
- public:
- morph(const NamedSprite& sprite, const NamedSprite& new_sprite);
- virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
- };
-
- /**
- * Animations of the pool.
- */
- namespace Pool {
-
- class Scheme {
- public:
- virtual ~Scheme() { }
- virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter* converter, AnimationType) const = 0;
- };
-
- class move : public Scheme {
- const NamedSprite& m_sprite;
- int m_to;
- public:
- move(const NamedSprite& sprite, int to);
- virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const;
- };
-
- class appear : public Scheme {
- const NamedSprite& m_sprite;
- public:
- appear(const NamedSprite& sprite);
- virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const;
- };
-
- class disappear : public Scheme {
- const NamedSprite& m_sprite;
- public:
- disappear(const NamedSprite& sprite);
- virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const;
- };
- }
-
-
-}
-
-
-#endif // ANIMATIONFACTORY_H
diff --git a/src/animationsettings.cpp b/src/animationsettings.cpp
new file mode 100644
index 0000000..a76bc97
--- /dev/null
+++ b/src/animationsettings.cpp
@@ -0,0 +1,29 @@
+/*
+ Copyright (c) 2007 Paolo Capriotti
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+*/
+
+#include "animationsettings.h"
+#include "mastersettings.h"
+
+AnimationSettings::AnimationSettings() {
+ reload();
+}
+
+void AnimationSettings::reload() {
+ Settings s = settings().group("animations");
+
+ enabled = s.flag("enabled", true);
+ maxSequence =
+ s.group("sequence").flag("enabled", true)
+ ? s.group("sequence")["max"].value()
+ : 0;
+ movement = s["movement"].flag("enabled", true);
+ explode = s["explode"].flag("enabled", true);
+ fading = s["fading"].flag("enabled", true);
+ transform = s["transform"].flag("enabled", true);
+}
diff --git a/src/graphicalapi.cpp b/src/animationsettings.h
similarity index 54%
copy from src/graphicalapi.cpp
copy to src/animationsettings.h
index 374cb61..fb19f75 100644
--- a/src/graphicalapi.cpp
+++ b/src/animationsettings.h
@@ -1,6 +1,5 @@
/*
Copyright (c) 2007 Paolo Capriotti
- (c) 2007 Maurizio Monge
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -8,7 +7,20 @@
(at your option) any later version.
*/
-#include "graphicalapi.h"
+#ifndef ANIMATIONSETTINGS_H
+#define ANIMATIONSETTINGS_H
-GraphicalAPI::~GraphicalAPI() { }
+struct AnimationSettings {
+ bool enabled;
+
+ int maxSequence;
+ bool movement;
+ bool explode;
+ bool fading;
+ bool transform;
+
+ AnimationSettings();
+ void reload();
+};
+#endif // ANIMATIONSETTINGS_H
diff --git a/src/board.cpp b/src/chessboard.cpp
similarity index 80%
rename from src/board.cpp
rename to src/chessboard.cpp
index 793a071..292b029 100644
--- a/src/board.cpp
+++ b/src/chessboard.cpp
@@ -14,14 +14,16 @@
#include
#include
+#include
+#include
+
#include "mastersettings.h"
-#include "board.h"
+#include "chessboard.h"
#include "sprite.h"
#include "animation.h"
#include "pointconverter.h"
#include "entities/userentity.h"
#include "mainanimation.h"
-#include "premove.h"
#include "constrainedtext.h"
using namespace boost;
@@ -30,7 +32,9 @@ using namespace boost;
class BoardTags : public std::map > > {
};
-Board::Board(const AnimationSettings& animSettings, KGameCanvasAbstract* parent)
+ChessBoard::ChessBoard(Variant* variant,
+ const AnimationSettings& animSettings,
+ KGameCanvasAbstract* parent)
: ClickableCanvas(parent)
, m_flipped(false)
, m_square_size(0)
@@ -39,7 +43,7 @@ Board::Board(const AnimationSettings& animSettings, KGameCanvasAbstract* parent)
, m_hinting_pos(Point::invalid())
, selection(Point::invalid())
, lastSelection(Point::invalid())
-, m_dropped_pool(-1)
+, m_dropped_pool(0)
, m_dropped_index(-1)
, m_anim_settings(animSettings) {
@@ -59,10 +63,12 @@ Board::Board(const AnimationSettings& animSettings, KGameCanvasAbstract* parent)
m_pieces_group = new KGameCanvasGroup(this);
m_pieces_group->show();
+ m_namer = requestComponent(variant, "namer");
+
settingsChanged();
}
-Board::~Board() {
+ChessBoard::~ChessBoard() {
delete m_pieces_group;
while(!m_canvas_background->items()->isEmpty())
@@ -76,7 +82,7 @@ Board::~Board() {
delete m_main_animation;
}
-void Board::settingsChanged() {
+void ChessBoard::settingsChanged() {
Settings s_anim = settings().group("animations");
int speed = (s_anim["speed"] | 16);
int smoothness = (s_anim["smoothness"] | 16);
@@ -89,7 +95,7 @@ void Board::settingsChanged() {
recreateBorder();
}
-void Board::updateBackground() {
+void ChessBoard::updateBackground() {
while(!m_canvas_background->items()->isEmpty())
delete m_canvas_background->items()->first();
@@ -112,11 +118,11 @@ void Board::updateBackground() {
}
}
-void Board::enqueue(const shared_ptr& anim) {
+void ChessBoard::enqueue(const shared_ptr& anim) {
m_main_animation->addAnimation(anim);
}
-void Board::adjustSprite(const Point& p, bool immediate) {
+void ChessBoard::adjustSprite(const Point& p, bool immediate) {
SpritePtr sprite = m_sprites[p].sprite();
if(!sprite)
@@ -129,7 +135,7 @@ void Board::adjustSprite(const Point& p, bool immediate) {
);
}
-boost::shared_ptr Board::addTag(const QString& name, Point pt, bool over) {
+boost::shared_ptr ChessBoard::addTag(const QString& name, Point pt, bool over) {
if(!m_sprites.valid(pt))
return boost::shared_ptr();
@@ -147,15 +153,15 @@ boost::shared_ptr Board::addTag(const QString& name, Point pt
return item;
}
-void Board::clearTags(const QString& name) {
+void ChessBoard::clearTags(const QString& name) {
m_tags->erase(name);
}
-void Board::clearTags() {
+void ChessBoard::clearTags() {
m_tags->clear();
}
-void Board::setTags(const QString& name, Point p1, Point p2, Point p3,
+void ChessBoard::setTags(const QString& name, Point p1, Point p2, Point p3,
Point p4, Point p5, Point p6 ) {
//TODO: maybe this could be optimized a bit
clearTags(name);
@@ -167,7 +173,7 @@ void Board::setTags(const QString& name, Point p1, Point p2, Point p3,
addTag(name, p6);
}
-void Board::recreateBorder() {
+void ChessBoard::recreateBorder() {
m_border_text.clear();
while(!m_canvas_border_text->items()->isEmpty())
delete m_canvas_border_text->items()->first();
@@ -207,7 +213,7 @@ void Board::recreateBorder() {
updateBorder();
}
-void Board::updateBorder() {
+void ChessBoard::updateBorder() {
while(!m_canvas_border->items()->isEmpty())
delete m_canvas_border->items()->first();
@@ -256,37 +262,37 @@ void Board::updateBorder() {
}
}
-void Board::createGrid(Point p, const QStringList& border_coords) {
+void ChessBoard::createGrid(Point p, const QStringList& border_coords) {
m_border_coords = border_coords;
m_sprites = PieceGrid(p.x,p.y);
recreateBorder();
}
-QPixmap Board::loadSprite(const QString& id) {
+QPixmap ChessBoard::loadSprite(const QString& id) {
return m_loader.piecePixmap(id, m_flipped);
}
-QRect Board::computeRect(Point p) const {
+QRect ChessBoard::computeRect(Point p) const {
QPoint realPoint = converter()->toReal(p);
return squareRect(realPoint.x(), realPoint.y());
}
-QRect Board::squareRect(int x, int y) const {
+QRect ChessBoard::squareRect(int x, int y) const {
return QRect(x, y, m_square_size, m_square_size);
}
-QRegion Board::computeRegion(Point p) const {
+QRegion ChessBoard::computeRegion(Point p) const {
return QRegion(computeRect(p));
}
// selection
-void Board::setSelection(const Point& p) {
+void ChessBoard::setSelection(const Point& p) {
lastSelection = selection;
selection = p;
setTags("selection", p);
}
-void Board::cancelSelection() {
+void ChessBoard::cancelSelection() {
lastSelection = selection;
selection = Point::invalid();
clearTags("selection");
@@ -294,29 +300,19 @@ void Board::cancelSelection() {
// premove
-void Board::setPremove(const NormalUserMove& premove) {
- m_premove_from = premove.from;
- m_premove_to = premove.to;
+void ChessBoard::setPremove(const Move& premove) {
+ m_premove_from = premove.src();
+ m_premove_to = premove.dst();
setTags("premove", m_premove_from, m_premove_to);
}
-void Board::setPremove(const DropUserMove& premove) {
- m_premove_from = Point::invalid();
- m_premove_to = premove.to;
- setTags("premove", m_premove_to);
-}
-
-void Board::setPremove(const Premove& premove) {
- setPremove(premove.toUserMove());
-}
-
-void Board::cancelPremove() {
+void ChessBoard::cancelPremove() {
m_premove_from = Point::invalid();
m_premove_to = Point::invalid();
clearTags("premove");
}
-void Board::updateSprites() {
+void ChessBoard::updateSprites() {
// adjust piece positions
for (Point i = m_sprites.first(); i <= m_sprites.last(); i = m_sprites.next(i)) {
boost::shared_ptr p = m_sprites[i].sprite();
@@ -329,7 +325,7 @@ void Board::updateSprites() {
}
}
-void Board::updateTags() {
+void ChessBoard::updateTags() {
if(!m_square_size)
return;
@@ -342,11 +338,10 @@ void Board::updateTags() {
}
-bool Board::doMove(const NormalUserMove& m) {
- if (m_entity.lock()->oneClickMoves() || m_entity.lock()->validTurn(m.from) == Moving) {
- AbstractMove::Ptr mv = m_entity.lock()->testMove(m);
- if (mv) {
- m_entity.lock()->executeMove(mv);
+bool ChessBoard::doMove(Move& m) {
+ if (m_entity.lock()->oneClickMoves() || m_entity.lock()->validTurn(m.src()) == Moving) {
+ if (m_entity.lock()->testMove(m)) {
+ m_entity.lock()->executeMove(m);
return true;
}
}
@@ -358,7 +353,7 @@ bool Board::doMove(const NormalUserMove& m) {
}
-void Board::onResize(int new_size, int border_size, int border_text_near,
+void ChessBoard::onResize(int new_size, int border_size, int border_text_near,
int border_text_far, bool force_reload) {
if(m_square_size == new_size && !force_reload)
return;
@@ -390,7 +385,7 @@ void Board::onResize(int new_size, int border_size, int border_text_near,
updateBorder();
}
-void Board::onMousePress(const QPoint& pos, int button) {
+void ChessBoard::onMousePress(const QPoint& pos, int button) {
Point point = converter()->toLogical(pos);
if (!m_sprites.valid(point))
return;
@@ -399,7 +394,7 @@ void Board::onMousePress(const QPoint& pos, int button) {
if (button == Qt::LeftButton) {
if (m_entity.lock()->oneClickMoves()) {
- NormalUserMove m = m_entity.lock()->createMove(Point::invalid(), point);
+ Move m(Point::invalid(), point);
doMove(m);
}
else {
@@ -416,7 +411,7 @@ void Board::onMousePress(const QPoint& pos, int button) {
else if (selection != Point::invalid()) {
piece = m_sprites[selection].sprite();
Q_ASSERT(piece);
- NormalUserMove m = m_entity.lock()->createMove(selection, point);
+ Move m(selection, point);
switch(m_entity.lock()->validTurn(selection)) {
@@ -454,7 +449,7 @@ void Board::onMousePress(const QPoint& pos, int button) {
//END right click
}
-void Board::onMouseRelease(const QPoint& pos, int button) {
+void ChessBoard::onMouseRelease(const QPoint& pos, int button) {
Point point = converter()->toLogical(pos);
//BEGIN left click
@@ -478,12 +473,12 @@ void Board::onMouseRelease(const QPoint& pos, int button) {
}
else {
- NormalUserMove m = m_entity.lock()->createMove(m_drag_info->from, point);
+ Point dst = point;
if (!m_sprites.valid(point))
- m.to = Point::invalid();
-
- switch(m_entity.lock()->validTurn(m_drag_info->from)) {
+ dst = Point::invalid();
+ Move m(m_drag_info->from, dst);
+ switch (m_entity.lock()->validTurn(m.src())) {
case Moving:
if (doMove(m))
moved = true;
@@ -520,7 +515,7 @@ void Board::onMouseRelease(const QPoint& pos, int button) {
//END left button
}
-void Board::onMouseMove(const QPoint& pos, int /*button*/) {
+void ChessBoard::onMouseMove(const QPoint& pos, int /*button*/) {
Point point = converter()->toLogical(pos);
if (m_drag_info) {
@@ -536,10 +531,10 @@ void Board::onMouseMove(const QPoint& pos, int /*button*/) {
m_drag_info->sprite->moveTo(pos - QPoint(m_square_size / 2, m_square_size / 2) );
// highlight valid moves
- NormalUserMove move = m_entity.lock()->createMove(m_drag_info->from, point);
+ Move move(m_drag_info->from, point);
bool valid = m_sprites.valid(point);
if (valid) {
- InteractionType action = m_entity.lock()->validTurn(m_drag_info->from);
+ InteractionType action = m_entity.lock()->validTurn(move.src());
if (action == Moving)
valid = m_entity.lock()->testMove(move);
}
@@ -553,11 +548,11 @@ void Board::onMouseMove(const QPoint& pos, int /*button*/) {
if(point == m_hinting_pos)
return;
- AbstractPiece::Ptr hint;
+ Piece hint;
if (m_sprites.valid(point)) {
- if (AbstractMove::Ptr move = m_entity.lock()->testMove(
- m_entity.lock()->createMove(Point::invalid(), point))) {
+ Move move(Point::invalid(), point);
+ if (m_entity.lock()->testMove(move)) {
// set move hint
hint = m_entity.lock()->moveHint(move);
}
@@ -567,29 +562,31 @@ void Board::onMouseMove(const QPoint& pos, int /*button*/) {
}
}
-void Board::onPositionChanged() {
+void ChessBoard::onPositionChanged() {
if (m_entity.lock() && m_entity.lock()->oneClickMoves() && m_sprites.valid(m_hinting_pos)) {
- AbstractPiece::Ptr hint;
+ Piece hint;
- if (AbstractMove::Ptr move = m_entity.lock()->testMove(
- m_entity.lock()->createMove(Point::invalid(), m_hinting_pos))) {
+ Move move(Point::invalid(), m_hinting_pos);
+ if (m_entity.lock()->testMove(move)) {
// set move hint
hint = m_entity.lock()->moveHint(move);
}
- updateHinting(m_hinting_pos, hint);
+ updateHinting(move.dst(), hint);
}
}
-void Board::onMouseLeave() {
- updateHinting(Point::invalid(), AbstractPiece::Ptr());
+void ChessBoard::onMouseLeave() {
+ updateHinting(Point::invalid(), Piece());
}
-void Board::updateHinting(Point pt, AbstractPiece::Ptr piece) {
+void ChessBoard::updateHinting(Point pt, Piece piece) {
if(!m_sprites.valid(pt))
- piece = AbstractPiece::Ptr();
+ piece = Piece();
+
- if(!piece || !m_sprites.valid(pt)) {
+ QString piece_name = m_namer->name(piece);
+ if(piece != Piece() || !m_sprites.valid(pt)) {
if(m_hinting.sprite()) {
if(1 /*BROKEN m_anim_fade*/)
enqueue( boost::shared_ptr(new FadeAnimation(m_hinting.sprite(),
@@ -603,9 +600,9 @@ void Board::updateHinting(Point pt, AbstractPiece::Ptr piece) {
}
else {
if(pt == m_hinting_pos) {
- if(!(piece->name() == m_hinting.name())) {
- m_hinting = NamedSprite(piece->name(), m_hinting.sprite());
- m_hinting.sprite()->setPixmap(loadSprite(piece->name()));
+ if (piece_name != m_hinting.name()) {
+ m_hinting = NamedSprite(piece_name, m_hinting.sprite());
+ m_hinting.sprite()->setPixmap(loadSprite(piece_name));
}
}
else {
@@ -617,14 +614,14 @@ void Board::updateHinting(Point pt, AbstractPiece::Ptr piece) {
enqueue( boost::shared_ptr(new CaptureAnimation(m_hinting.sprite())) );
}
- QPixmap pix = loadSprite(piece->name());
+ QPixmap pix = loadSprite(piece_name);
SpritePtr sprite(new Sprite(pix, piecesGroup(), converter()->toReal(pt)));
sprite->setOpacity(160);
sprite->raise();
sprite->show();
m_hinting_pos = pt;
- m_hinting = NamedSprite(piece->name(), sprite);
+ m_hinting = NamedSprite(piece_name, sprite);
/*if(m_anim_fade)
enqueue( boost::shared_ptr(new FadeAnimation(m_hinting.sprite(),
@@ -637,14 +634,14 @@ void Board::updateHinting(Point pt, AbstractPiece::Ptr piece) {
}
}
-void Board::reset() {
+void ChessBoard::reset() {
clearTags();
cancelSelection();
cancelPremove();
m_main_animation->stop();
}
-void Board::flip(bool flipped)
+void ChessBoard::flip(bool flipped)
{
if (m_flipped != flipped) {
m_flipped = flipped;
@@ -663,15 +660,14 @@ void Board::flip(bool flipped)
}
}
-void Board::draggingOn(int pool, int index, const QPoint& point) {
+void ChessBoard::draggingOn(const IColor* pool, int index, const QPoint& point) {
Point to = converter()->toLogical(point);
if (m_sprites.valid(to))
- switch(m_entity.lock()->validTurn(pool)) {
+ switch (m_entity.lock()->validTurn(pool)) {
case Moving: {
- DropUserMove m = m_entity.lock()->createDrop(pool, index, to);
- AbstractMove::Ptr mv = m_entity.lock()->testMove(m);
- if (mv) {
+ Move m(pool, index, to);
+ if (m_entity.lock()->testMove(m)) {
setTags("validmove", to);
return;
}
@@ -689,7 +685,7 @@ void Board::draggingOn(int pool, int index, const QPoint& point) {
clearTags("validmove");
}
-bool Board::dropOn(int pool, int index, const QPoint& point) {
+bool ChessBoard::dropOn(const IColor* pool, int index, const QPoint& point) {
Point to = converter()->toLogical(point);
if (!m_sprites.valid(to))
@@ -697,20 +693,19 @@ bool Board::dropOn(int pool, int index, const QPoint& point) {
clearTags("validmove");
- switch(m_entity.lock()->validTurn(pool)) {
+ switch (m_entity.lock()->validTurn(pool)) {
case Moving: {
- DropUserMove m = m_entity.lock()->createDrop(pool, index, to);
- AbstractMove::Ptr mv = m_entity.lock()->testMove(m);
- if (mv) {
- m_entity.lock()->executeMove(mv);
+ Move m(pool, index, to);
+ if (m_entity.lock()->testMove(m)) {
+ m_entity.lock()->executeMove(m);
return true;
}
break;
}
case Premoving: {
- DropUserMove m = m_entity.lock()->createDrop(pool, index, to);
+ Move m(pool, index, to);
if (m_entity.lock()->testPremove(m)) {
m_entity.lock()->addPremove(m);
setPremove(m);
diff --git a/src/board.h b/src/chessboard.h
similarity index 92%
rename from src/board.h
rename to src/chessboard.h
index 9eafaed..7f4084c 100644
--- a/src/board.h
+++ b/src/chessboard.h
@@ -8,16 +8,20 @@
(at your option) any later version.
*/
-#ifndef BOARD_H
-#define BOARD_H
+#ifndef CHESSBOARD_H
+#define CHESSBOARD_H
#include
#include
-
#include
#include
+#include
#include
-#include "kgamecanvas.h"
+
+#include
+#include
+#include
+
#include "entities/userentity.h"
#include "common.h"
#include "grid.h"
@@ -26,15 +30,17 @@
#include "pointconverter.h"
#include "pixmaploader.h"
#include "clickablecanvas.h"
-#include
-class DragInfo;
class Animation;
-class UserEntity;
-class ConstrainedText;
class AnimationSettings;
-
class BoardTags;
+class ConstrainedText;
+class DragInfo;
+class IColor;
+class INamer;
+class UserEntity;
+class Variant;
+
typedef boost::shared_ptr BoardTagsPtr;
/**
@@ -45,7 +51,7 @@ typedef boost::shared_ptr BoardTagsPtr;
* You can set custom tags for each square.
* @sa Table, @sa PiecePool, @sa Sprite
*/
-class Board : public QObject, public ClickableCanvas, protected PointConverter {
+class ChessBoard : public QObject, public ClickableCanvas, protected PointConverter {
Q_OBJECT
public:
@@ -150,10 +156,12 @@ private:
QStringList m_border_coords;
- int m_dropped_pool;
+ const IColor* m_dropped_pool;
int m_dropped_index;
const AnimationSettings& m_anim_settings;
+
+ INamer* m_namer;
/** the text items for the border */
std::vector m_border_text;
@@ -167,7 +175,7 @@ private:
/** this internal function creates a new border, if needed */
void recreateBorder();
- void updateHinting(Point pt, AbstractPiece::Ptr piece);
+ void updateHinting(Point pt, Piece piece);
/** this internal function updates the sprites after the board has been resized */
void updateSprites();
@@ -175,9 +183,7 @@ private:
/** this internal function updates the tags after the board has been resized */
void updateTags();
- void setPremove(const NormalUserMove& move);
- void setPremove(const DropUserMove& move);
- void setPremove(const class Premove& move);
+ void setPremove(const Move& move);
void updatePremove();
void setSelection(const Point& p);
@@ -186,12 +192,12 @@ private:
QRect squareRect(int x, int y) const;
/** this function tries to notify the move to the entity */
- bool doMove(const NormalUserMove&);
+ bool doMove(Move&);
public:
/** constructor, requires the canvas parent */
- Board(const AnimationSettings& animSettings, KGameCanvasAbstract* parent);
- ~Board();
+ ChessBoard(Variant* variant, const AnimationSettings& animSettings, KGameCanvasAbstract* parent);
+ ~ChessBoard();
/** set the board flipping */
void flip(bool flipped);
@@ -271,10 +277,10 @@ public:
/** Notifies to the board that a certain piece is being dragged over the board */
- void draggingOn(int pool, int index, const QPoint& p);
+ void draggingOn(const IColor* pool, int index, const QPoint& p);
/** Executes a drop. This function id typically called by by a PiecePool */
- bool dropOn(int pool, int index, const QPoint& point);
+ bool dropOn(const IColor* pool, int index, const QPoint& point);
/** mouse release event */
virtual void onMouseRelease(const QPoint& pos, int button);
@@ -305,4 +311,4 @@ Q_SIGNALS:
void error(ErrorCode code);
};
-#endif //BOARD_H
+#endif // CHESSBOARD_H
diff --git a/src/chesstable.cpp b/src/chesstable.cpp
index c7f13aa..3e32334 100644
--- a/src/chesstable.cpp
+++ b/src/chesstable.cpp
@@ -12,6 +12,10 @@
#include
#include
#include
+
+#include
+#include
+
#include "chesstable.h"
#include "game.h"
#include "gameinfo.h"
@@ -24,7 +28,7 @@
using namespace boost;
-ChessTable::ChessTable(QWidget* parent)
+ChessTable::ChessTable(Variant* variant, QWidget* parent)
: KGameCanvasWidget(parent)
, m_wallpaper(NULL)
, m_current(NULL)
@@ -34,7 +38,7 @@ ChessTable::ChessTable(QWidget* parent)
setMouseTracking(true);
// create m_board
- m_board = new Board(m_anim_settings, this);
+ m_board = new ChessBoard(variant, m_anim_settings, this);
m_board->show();
// create move list
@@ -52,8 +56,11 @@ ChessTable::ChessTable(QWidget* parent)
// m_info->show();
// create pools
- for(int i=0;i<2;i++) {
- m_pools[i] = new PiecePool(i, m_board, m_anim_settings, this);
+ // FIXME what to do for more than 2 players?
+ for (int i = 0; i < 2; i++) {
+ const IColor* color = requestComponent(
+ variant, "player/" + QString::number(i));
+ m_pools[i] = new PiecePool(color, m_board, m_anim_settings, this);
m_pools[i]->show();
}
diff --git a/src/chesstable.h b/src/chesstable.h
index 50a3be5..c74ed3c 100644
--- a/src/chesstable.h
+++ b/src/chesstable.h
@@ -11,13 +11,11 @@
#ifndef CHESSTABLE_H
#define CHESSTABLE_H
-#include
-
-#include "kgamecanvas.h"
+#include
+#include "animationsettings.h"
#include "positioninfo.h"
-#include "board.h"
+#include "chessboard.h"
#include "common.h"
-#include "animationfactory.h"
class PiecePool;
class Player;
@@ -35,7 +33,7 @@ class ChessTable : public KGameCanvasWidget {
KGameCanvasTiledPixmap* m_wallpaper;
Clock* m_clocks[2];
- Board* m_board;
+ ChessBoard* m_board;
PiecePool* m_pools[2];
MoveList::Table* m_movelist;
InfoDisplay* m_info;
@@ -50,10 +48,10 @@ class ChessTable : public KGameCanvasWidget {
AnimationSettings m_anim_settings;
public:
- ChessTable(QWidget* parent = 0);
+ explicit ChessTable(Variant* variant, QWidget* parent = 0);
~ChessTable();
- inline Board* board() const { return m_board; }
+ inline ChessBoard* board() const { return m_board; }
inline PiecePool* pool(int index) const { return m_pools[index]; }
inline MoveList::Table* moveListTable() const { return m_movelist; }
inline Clock* clock(int index) const { return m_clocks[index]; }
diff --git a/src/controllers/abstract.h b/src/controllers/abstract.h
index 8e7b7cc..e08904c 100644
--- a/src/controllers/abstract.h
+++ b/src/controllers/abstract.h
@@ -12,17 +12,18 @@
#define CONTROLLER_H
#include
-#include
+#include
+#include
#include "common.h"
#include "entitytoken.h"
-#include "fwd.h"
+class ActionCollection;
class ChessTable;
-class UserEntity;
class Engine;
+class IColor;
class PGN;
-class ActionCollection;
class UI;
+class UserEntity;
/**
* @b Controller is the base abstract class for all controllers in Tagua.
@@ -90,7 +91,7 @@ public:
* @return current position, or a null shared_ptr if no current position
* concept is defined for this controller.
*/
- virtual PositionPtr currentPosition() const { return PositionPtr(); }
+ virtual StatePtr currentPosition() const { return StatePtr(); }
/**
* Change turn. Used for example in edit position mode.
@@ -164,7 +165,8 @@ public:
* @return a token which uniquely identifies the engine entity
* and can be used to remove it from the entity list.
*/
- virtual EntityToken addPlayingEngine(int /*side*/, const boost::shared_ptr&) { return EntityToken(); }
+ virtual EntityToken addPlayingEngine(const IColor* /*side*/,
+ const boost::shared_ptr&) { return EntityToken(); }
/**
* Remove an entity from the controller list.
diff --git a/src/controllers/editgame.cpp b/src/controllers/editgame.cpp
index 45b4174..2077827 100644
--- a/src/controllers/editgame.cpp
+++ b/src/controllers/editgame.cpp
@@ -10,6 +10,14 @@
#include "editgame.h"
+#include
+
+#include
+#include
+#include
+#include
+#include
+
#include "graphicalgame.h"
#include "graphicalsystem.h"
#include "xboardengine.h"
@@ -42,7 +50,7 @@ public:
if (index.totalNumMoves() >= 2)
m_view->run();
- m_view->changeClock(m_game->position(index)->turn());
+ m_view->changeClock(m_game->position(index)->turn()->index());
}
virtual void notifyBack() { }
virtual void notifyForward() { }
@@ -71,22 +79,23 @@ public:
};
EditGameController::EditGameController(ChessTable* view,
- const VariantPtr& variant,
- AbstractPosition::Ptr startingPosition)
+ Variant* variant,
+ const StatePtr& startingPosition)
: Controller(view) , m_variant(variant) {
- AbstractPosition::Ptr position;
- if (!startingPosition) {
- position = m_variant->createPosition();
- position->setup();
+ StatePtr state = startingPosition;
+ if (!state) {
+ IStateFactory* factory = requestComponent(
+ m_variant, "state_factory");
+ state = StatePtr(factory->createState());
+ state->setup();
}
- else position = startingPosition;
- m_graphical = shared_ptr(new GraphicalSystem(m_view, position, m_variant));
+ m_graphical = shared_ptr(new GraphicalSystem(m_view, state, m_variant));
m_game = shared_ptr(new GraphicalGame(m_graphical.get(),
m_view->moveListTable()));
- m_game->reset(position);
+ m_game->reset(state);
m_entity = shared_ptr(new GameEntity(m_variant, m_game, m_view->board(), &m_agents));
m_entity->enableEditingTools(true);
@@ -94,17 +103,18 @@ EditGameController::EditGameController(ChessTable* view,
m_graphical->setup(m_entity);
m_game->setEntity(m_entity);
-
- init(AbstractPosition::Ptr());
+ init(state);
}
EditGameController::~EditGameController() { }
-void EditGameController::init(AbstractPosition::Ptr startingPosition) {
- m_players[0] = m_entity;
- m_players[1] = m_entity;
- m_entity->turnTest().setSimplePolicy(0, true);
- m_entity->turnTest().setSimplePolicy(1, true);
+void EditGameController::init(const StatePtr& startingPosition) {
+ QList colors = m_variant->repository()->listComponents("player");
+ foreach (Component* color, colors) {
+ IColor* c = requestInterface(color);
+ m_players[c] = m_entity;
+ m_entity->turnTest().setSimplePolicy(c, true);
+ }
if (startingPosition) {
// TODO update to the starting position
@@ -121,21 +131,17 @@ void EditGameController::init(AbstractPosition::Ptr startingPosition) {
}
ActionCollection* EditGameController::variantActions() const {
- return m_variant->actions();
+ return 0; // FIXME restore variant actions
+ // return m_variant->actions();
}
QString EditGameController::variant() const {
- PositionPtr pos = m_game->position();
- if (pos)
- return pos->variant();
- else
- return QString();
+ return m_variant->name();
}
void EditGameController::onNavigation() { }
-EntityToken EditGameController::addPlayingEngine(int side, const shared_ptr& engine) {
- Q_ASSERT(side == 0 || side == 1);
+EntityToken EditGameController::addPlayingEngine(const IColor* side, const shared_ptr& engine) {
if (!engine)
return EntityToken();
@@ -159,28 +165,15 @@ EntityToken EditGameController::addPlayingEngine(int side, const shared_ptr& engine) {
-// Q_ASSERT(engine.use_count() == 1);
-// shared_ptr entity(new EngineEntity(m_variant, m_game, -1, engine, &m_agents));
-// m_agents.addAgent(entity);
-// EntityToken res(m_entities.insert(entity).first);
-//
-// engine->setNotifier(entity);
-// engine->start();
-// engine->setBoard(m_game->position(), 0, 0);
-// engine->startAnalysis();
-//
-// return res;
-// }
-
void EditGameController::removeEntity(const EntityToken& token) {
shared_ptr entity = token.entity();
if (entity) {
// check players
- for (int i = 0; i < 2; i++) {
- if (entity == m_players[i]) {
- m_players[i] = m_entity;
- m_entity->turnTest().setSimplePolicy(i, true);
+ for (Players::iterator it = m_players.begin(), end = m_players.end();
+ it != end; ++it) {
+ if (entity == it->second) {
+ it->second = m_entity;
+ m_entity->turnTest().setSimplePolicy(it->first, true);
}
}
@@ -193,8 +186,8 @@ void EditGameController::removeEntity(const EntityToken& token) {
std::cout << "there are " << m_entities.size() << " entities left" << std::endl;
}
-bool EditGameController::addICSPlayer(int side, int game_number, const shared_ptr& connection) {
- Q_ASSERT(side == 0 || side == 1);
+bool EditGameController::addICSPlayer(const IColor* side, int game_number,
+ const shared_ptr& connection) {
if (m_players[side]->canDetach()) {
shared_ptr entity(new ICSEntity(m_variant, m_game,
side, game_number, connection, &m_agents));
@@ -207,7 +200,8 @@ bool EditGameController::addICSPlayer(int side, int game_number, const shared_pt
connection->setListener(game_number, entity);
entity->setupTurnTest(m_entity->turnTest());
- m_view->flip(m_players[1] == m_entity); // flip if we're black!
+ // FIXME: flip if we are black when playing in ICS
+// m_view->flip(m_players[1] == m_entity); // flip if we're black!
m_agents.addAgent(m_clock_agent);
}
@@ -225,43 +219,45 @@ bool EditGameController::addICSPlayer(int side, int game_number, const shared_pt
}
bool EditGameController::setExaminationMode(int game_number, const shared_ptr& connection) {
- std::cout << "[controller " << this << "] setting examination mode" << std::endl;
- if (m_players[0]->canDetach() &&
- m_players[1]->canDetach()) {
+ kDebug() << "setting examination mode";
+
+ if (detachAllPlayerEntities()) {
shared_ptr entity(new ExaminationEntity(m_variant, m_game,
game_number, connection, &m_agents));
if (entity->attach()) {
m_entity = entity;
m_view->setEntity(entity);
m_agents.addAgent(entity);
- m_players[0] = entity;
- m_players[1] = entity;
-
+ for (Players::iterator it = m_players.begin(), end = m_players.end();
+ it != end; ++it) {
+ it->second = entity;
+ }
+
connection->setListener(game_number, entity);
m_view->flip(false);
m_entity->turnTest().clear();
return true;
}
- else
- std::cout << "** could not attach examination entity **" << std::endl;
+ else {
+ kWarning() << "Could not attach examination entity";
+ }
}
- else
- std::cout << "** could not detach entity **" << std::endl;
return false;
}
bool EditGameController::setObserveMode(int game_number, const shared_ptr& connection) {
- if (m_players[0]->canDetach() &&
- m_players[1]->canDetach()) {
+ if (detachAllPlayerEntities()) {
shared_ptr entity(new ObservingEntity(m_variant, m_game,
game_number, connection, &m_agents));
if (entity->attach()) {
m_agents.addAgent(entity);
- m_players[0] = entity;
- m_players[1] = entity;
+ for (Players::iterator it = m_players.begin(), end = m_players.end();
+ it != end; ++it) {
+ it->second = entity;
+ }
connection->setListener(game_number, entity);
m_view->flip(false);
@@ -269,10 +265,10 @@ bool EditGameController::setObserveMode(int game_number, const shared_ptrdetach();
- m_players[0]->detach();
- m_players[1]->detach();
+ detachAllPlayerEntities();
foreach (shared_ptr entity, m_entities)
entity->detach();
@@ -308,11 +303,12 @@ shared_ptr EditGameController::end() {
}
// return to edit game mode
- m_players[0] = m_entity;
- m_players[1] = m_entity;
- m_entity->turnTest().setSimplePolicy(0, true);
- m_entity->turnTest().setSimplePolicy(1, true);
-
+ for (Players::iterator it = m_players.begin(), end = m_players.end();
+ it != end; ++it) {
+ it->second = m_entity;
+ m_entity->turnTest().setSimplePolicy(it->first, true);
+ }
+
return Controller::end();
}
@@ -328,3 +324,16 @@ void EditGameController::setUI(UI& ui) {
void EditGameController::activate() {
m_game->onActionStateChange();
}
+
+
+bool EditGameController::detachAllPlayerEntities() {
+ for (Players::iterator it = m_players.begin(), end = m_players.end();
+ it != end; ++it) {
+ if (!it->second->canDetach()) {
+ kWarning() << "Could not detach entity" << it->second.get();
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/src/controllers/editgame.h b/src/controllers/editgame.h
index 54437cd..9290989 100644
--- a/src/controllers/editgame.h
+++ b/src/controllers/editgame.h
@@ -11,18 +11,22 @@
#ifndef EDITGAMECONTROLLER_H
#define EDITGAMECONTROLLER_H
+#include