Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ur_controller.hpp
Go to the documentation of this file.
1
10
16
17#ifndef ZOAPPURCONTROLLER_H
18#define ZOAPPURCONTROLLER_H
19
20#define GLM_ENABLE_EXPERIMENTAL
21#include <glm/gtx/string_cast.hpp>
22
23#include "toymaker/sim_system.hpp"
24
26
28
34class UrController: public ToyMaker::SimObjectAspect<UrController> {
35public:
40 UrController(): SimObjectAspect<UrController>{0} {}
41
47 inline static std::string getSimObjectAspectTypeName() { return "UrController"; }
48
55 static std::shared_ptr<BaseSimObjectAspect> create(const nlohmann::json& jsonAspectProperties);
56
62 std::shared_ptr<BaseSimObjectAspect> clone() const override;
63
69 inline const GameOfUrModel& getModel() const { return mModel; }
70
79 std::unique_ptr<UrPlayerControls> createControls();
80
81private:
87
94 uint8_t mControlsCreated {0};
95
100 std::string mSceneManagerPath {};
101
108 std::map<std::string, bool> mViewUpdated {};
109
116 bool viewUpdatesComplete() const;
117
118
124 void onViewSubscribed(const std::string& subscriber);
125
133 void onLaunchPieceAttempted(PlayerID player, PieceIdentity piece, glm::u8vec2 launchLocation=glm::u8vec2{0,0});
134
141 void onMoveBoardPieceAttempted(PlayerID player, PieceIdentity piece);
142
148 void onNextTurnAttempted(PlayerID player);
149
155 void onDiceRollAttempted(PlayerID player);
156
162 void onViewUpdatesCompleted(const std::string& viewName);
163
168 void onActivated() override;
169
170public:
175 ToyMaker::Signal<> mSigControllerReady { *this, "ControllerReady" };
176
182 *this, "ViewSubscribedObserved",
183 [this](const std::string& viewName) {this->onViewSubscribed(viewName);}
184 };
185
191
197
203
209
215
220 ToyMaker::Signal<> mSigViewUpdateStarted { *this, "ViewUpdateStarted" };
221
227 *this, "ViewUpdateCompletedObserved",
228 [this](const std::string& viewName) { this->onViewUpdatesCompleted(viewName); }
229 };
230
236friend class UrPlayerControls;
237};
238
247public:
253 inline PlayerID getPlayer() const { return mPlayer; }
254
261 void attemptLaunchPiece(PieceTypeID pieceType, glm::u8vec2 launchLocation=glm::u8vec2{0,0});
262
268 void attemptMoveBoardPiece(PieceIdentity piece);
269
274 void attemptNextTurn();
275
280 void attemptDiceRoll();
281
287 inline const GameOfUrModel& getModel() { return mUrController.getModel(); }
288private:
296 inline static std::unique_ptr<UrPlayerControls> create(PlayerID player, UrController& urController) {
297 return std::unique_ptr<UrPlayerControls>(new UrPlayerControls{ player, urController });
298 }
299
305 UrPlayerControls(PlayerID player, UrController& urController): mPlayer{ player }, mUrController { urController } {}
306
312
317 UrController& mUrController;
318
319friend class UrController;
320};
321
322#endif
The class containing the interface to the data model for the whole game (Game of Ur).
The data model representing one instance of Game of Ur.
Definition model.hpp:337
A SignalObserver object, which can subscribe to Signals matching its data signature and receive signa...
Definition signals.hpp:412
A Signal object, designed to emit signals matching some data signature to be received by all the Sign...
Definition signals.hpp:323
An object containing closely related methods and data, and exposing object lifecycle and application ...
Definition sim_system.hpp:956
ToyMaker::Signal< DiceData > mSigDiceUpdated
Signal emitted when the game data model reports a change in the state of its dice.
Definition ur_controller.hpp:208
void onDiceRollAttempted(PlayerID player)
Attempts to roll the dice.
Definition ur_controller.cpp:153
void onViewSubscribed(const std::string &subscriber)
Adds a view which is interested in receiving information about events regarding changes in the state ...
Definition ur_controller.cpp:28
std::map< std::string, bool > mViewUpdated
Flags corresponding with various views subscribed with this object.
Definition ur_controller.hpp:108
GameOfUrModel mModel
The game data model this aspect is an interface to.
Definition ur_controller.hpp:86
ToyMaker::Signal mSigControllerReady
Signal emitted by this object when it is ready to be interacted with by other objects.
Definition ur_controller.hpp:175
static std::string getSimObjectAspectTypeName()
Gets the aspect type string associated with this object.
Definition ur_controller.hpp:47
void onLaunchPieceAttempted(PlayerID player, PieceIdentity piece, glm::u8vec2 launchLocation=glm::u8vec2{0, 0})
Attempts to launch a game piece to the board.
Definition ur_controller.cpp:71
ToyMaker::Signal< PlayerData > mSigPlayerUpdated
Signal emitted when information associated with a player changes.
Definition ur_controller.hpp:202
ToyMaker::Signal< MoveResultData > mSigMoveMade
Signal emitted when the game data model reports a move successfully executed.
Definition ur_controller.hpp:214
void onNextTurnAttempted(PlayerID player)
Attempts to end the current turn and move to the next one.
Definition ur_controller.cpp:128
ToyMaker::Signal< GameScoreData > mSigScoreUpdated
Signal emitted when the game data model reports a change in score.
Definition ur_controller.hpp:196
ToyMaker::Signal mSigViewUpdateStarted
Signal emitted when this controller begins waiting for view updates related to the latest game state ...
Definition ur_controller.hpp:220
std::unique_ptr< UrPlayerControls > createControls()
Creates an instance of UrPlayerControls, which exposes methods which allow (controlled) interaction w...
Definition ur_controller.cpp:66
ToyMaker::SignalObserver< const std::string & > mObserveViewSubscribed
Observer to a signal emitted by views interested in events broadcasted by this object.
Definition ur_controller.hpp:181
void onMoveBoardPieceAttempted(PlayerID player, PieceIdentity piece)
Attempts to move a piece present on the board according to the current roll.
Definition ur_controller.cpp:92
static std::shared_ptr< BaseSimObjectAspect > create(const nlohmann::json &jsonAspectProperties)
Creates an UrController based on its JSON description.
Definition ur_controller.cpp:9
UrController()
Constructs a new UrController aspect.
Definition ur_controller.hpp:40
const GameOfUrModel & getModel() const
Gets a const reference to the underlying data model of this object.
Definition ur_controller.hpp:69
ToyMaker::Signal< GamePhaseData > mSigMovePrompted
Signal emitted when the controller expects a player to act, either via the game UI or some other sour...
Definition ur_controller.hpp:235
std::shared_ptr< BaseSimObjectAspect > clone() const override
Constructs an UrController object using this one as its blueprint.
Definition ur_controller.cpp:15
bool viewUpdatesComplete() const
Returns whether all the views connected with this controller have reported completion of their update...
Definition ur_controller.cpp:21
void onViewUpdatesCompleted(const std::string &viewName)
The callback, invoked by a subscribed view, where the view reports that it has completed all view cha...
Definition ur_controller.cpp:32
void onActivated() override
Initializes the game data model.
Definition ur_controller.cpp:51
std::string mSceneManagerPath
The path to the scene manager, responsible for navigating between the different game screens in this ...
Definition ur_controller.hpp:100
ToyMaker::Signal< GamePhaseData > mSigPhaseUpdated
Signal emitted when a the game data model reports a change to its phase.
Definition ur_controller.hpp:190
uint8_t mControlsCreated
The number of controls connected with this object created over its lifetime.
Definition ur_controller.hpp:94
ToyMaker::SignalObserver< const std::string & > mObserveViewUpdateCompleted
Observer which receives signals from its subscribed views when they report their updates are complete...
Definition ur_controller.hpp:226
The definition for the object that acts as the interface between the game controller and any systems ...
Definition ur_controller.hpp:246
void attemptDiceRoll()
Attempts to roll the dice.
Definition ur_controller.cpp:166
PlayerID getPlayer() const
Gets the ID of the player associated with this object.
Definition ur_controller.hpp:253
const GameOfUrModel & getModel()
Gets a constant reference to the underlying data model used by UrController.
Definition ur_controller.hpp:287
static std::unique_ptr< UrPlayerControls > create(PlayerID player, UrController &urController)
Creates an instance of UrPlayerControls.
Definition ur_controller.hpp:296
PlayerID mPlayer
The ID of the player to whom these controls belong.
Definition ur_controller.hpp:311
UrController & mUrController
The reference to the game controller connected with these controls.
Definition ur_controller.hpp:317
UrPlayerControls(PlayerID player, UrController &urController)
Constructs a new UrPlayerControls object.
Definition ur_controller.hpp:305
void attemptLaunchPiece(PieceTypeID pieceType, glm::u8vec2 launchLocation=glm::u8vec2{0, 0})
Attempts to launch a game piece to some location on the game board.
Definition ur_controller.cpp:169
void attemptNextTurn()
Attempts to end the current turn and begin the next one.
Definition ur_controller.cpp:176
void attemptMoveBoardPiece(PieceIdentity piece)
Attempts to move a piece already on the board to a new location based on the current dice roll.
Definition ur_controller.cpp:173
PieceTypeID
Enum listing the different types of pieces present in the game.
Definition piece_type_id.hpp:22
PlayerID
The two players playing the game, as known to GameOfUrModel.
Definition model.hpp:40
Data uniquely identifying a piece used in the game.
Definition piece.hpp:29