HoverRace  2.0
Rules.h
Go to the documentation of this file.
1 
2 // Rules.h
3 //
4 // Copyright (c) 2013, 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <luabind/object.hpp>
25 
26 #include "../../engine/Model/GameOptions.h"
27 
28 namespace HoverRace {
29  namespace Client {
30  class Rulebook;
31  }
32  namespace Model {
33  class TrackEntry;
34  }
35 }
36 
37 namespace HoverRace {
38 namespace Client {
39 
44 class Rules
45 {
46 public:
47  Rules(std::shared_ptr<const Rulebook> rulebook =
48  std::shared_ptr<const Rulebook>());
49 
50 public:
51  std::shared_ptr<const Rulebook> GetRulebook() const { return rulebook; }
52  void SetRulebook(std::shared_ptr<const Rulebook> rulebook);
53 
54  std::shared_ptr<const Model::TrackEntry> GetTrackEntry() const { return trackEntry; }
55  void SetTrackEntry(std::shared_ptr<const Model::TrackEntry> trackEntry) { this->trackEntry = std::move(trackEntry); }
56 
58  luabind::object &GetRules() { return rules; }
59 
60  // Temporary; will be removed once all logic is moved into Lua.
61  int GetLaps() const
62  {
63  try {
64  return luabind::object_cast<int>(rules["laps"]);
65  } catch (luabind::cast_failed&) {
66  return 1;
67  }
68  }
69  void SetLaps(int laps) { rules["laps"] = laps; }
70  const Model::GameOptions &GetGameOpts() const { return gameOpts; }
71  void SetGameOpts(const Model::GameOptions &gameOpts) { this->gameOpts = gameOpts; }
72 
73 private:
74  std::shared_ptr<const Rulebook> rulebook;
75  std::shared_ptr<const Model::TrackEntry> trackEntry;
76 
77  luabind::object rules;
78 
80 };
81 
82 } // namespace Client
83 } // namespace HoverRace
const Model::GameOptions & GetGameOpts() const
Definition: Rules.h:70
luabind::object rules
Definition: Rules.h:77
void SetLaps(int laps)
Definition: Rules.h:69
std::shared_ptr< const Rulebook > rulebook
Definition: Rules.h:74
luabind::object & GetRules()
Retrieve the the Lua view of the rules.
Definition: Rules.h:58
int GetLaps() const
Definition: Rules.h:61
Model::GameOptions gameOpts
Definition: Rules.h:79
Definition: GameOptions.h:41
void SetTrackEntry(std::shared_ptr< const Model::TrackEntry > trackEntry)
Definition: Rules.h:55
The options and settings for a single game session.
Definition: Rules.h:44
Definition: Announcement.h:24
void SetGameOpts(const Model::GameOptions &gameOpts)
Definition: Rules.h:71
std::shared_ptr< const Model::TrackEntry > GetTrackEntry() const
Definition: Rules.h:54
std::shared_ptr< const Rulebook > GetRulebook() const
Definition: Rules.h:51
std::shared_ptr< const Model::TrackEntry > trackEntry
Definition: Rules.h:75