Peoplemon  0.1.0
Peoplemon 3 game source documentation
SaveGame.cpp
Go to the documentation of this file.
2 
4 #include <Core/Properties.hpp>
5 #include <Core/Resources.hpp>
6 
7 namespace game
8 {
9 namespace state
10 {
11 bl::engine::State::Ptr SaveGame::create(core::system::Systems& s) {
12  return bl::engine::State::Ptr(new SaveGame(s));
13 }
14 
15 SaveGame::SaveGame(core::system::Systems& s)
16 : State(s, bl::engine::StateMask::Menu) {
17  bgndTxtr = s.engine().renderer().texturePool().getOrLoadTexture(
18  bl::util::FileUtil::joinPath(core::Properties::MenuImagePath(), "savegame.png"));
19  background.create(s.engine(), bgndTxtr);
20  background.getTransform().setDepth(bl::cam::OverlayCamera::MaxDepth); // ensure behind HUD
21 }
22 
23 const char* SaveGame::name() const { return "SaveGame"; }
24 
25 void SaveGame::activate(bl::engine::Engine& engine) {
26  background.addToScene(engine.renderer().getObserver().pushScene<bl::rc::Overlay>(),
27  bl::rc::UpdateSpeed::Static);
28 
29  const auto cb = std::bind(&SaveGame::onFinish, this);
31  systems.hud().displayMessage(systems.player().state().name + " saved the game!", cb);
32  }
33  else { systems.hud().displayMessage("Failed to save the game, good luck :(", cb); }
34 }
35 
36 void SaveGame::deactivate(bl::engine::Engine& engine) {
37  engine.renderer().getObserver().popScene();
38 }
39 
40 void SaveGame::update(bl::engine::Engine&, float, float) {}
41 
42 void SaveGame::onFinish() { systems.engine().popState(); }
43 
44 } // namespace state
45 } // namespace game
Parent namespace for all functionality unique to the game.
static bool saveGame(const std::string &name)
Saves the game. Fires an event::GameSaveInitializing event for systems to add their data to the save ...
Definition: GameSave.cpp:62
std::string name
Definition: State.hpp:42
static const std::string & MenuImagePath()
Definition: Properties.cpp:303
void displayMessage(const std::string &message, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Messages are queued in order that they arrive.
Definition: HUD.cpp:92
player::State & state()
Returns the state of the player.
Definition: Player.cpp:154
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Definition: Systems.cpp:35
Player & player()
Returns the player system.
Definition: Systems.cpp:59
HUD & hud()
Returns the HUD.
Definition: Systems.cpp:69
Basic engine state for when the game is saved.
Definition: SaveGame.hpp:16
virtual void activate(bl::engine::Engine &engine) override
Activates the state.
Definition: SaveGame.cpp:25
virtual const char * name() const override
Returns "SaveGame".
Definition: SaveGame.cpp:23
virtual void update(bl::engine::Engine &engine, float dt, float) override
Updates the state and menus and whatnot.
Definition: SaveGame.cpp:40
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates the save game state.
Definition: SaveGame.cpp:11
virtual void deactivate(bl::engine::Engine &engine) override
Deactivates the state.
Definition: SaveGame.cpp:36
Parent to all game states. Provides some commonly required data like core game systems.
Definition: State.hpp:29
core::system::Systems & systems
Definition: State.hpp:66