Peoplemon  0.1.0
Peoplemon 3 game source documentation
PlayerControlled.cpp
Go to the documentation of this file.
2 
5 
6 namespace core
7 {
8 namespace component
9 {
11 : systems(s)
12 , controllable(controllable)
13 , started(false) {}
14 
16  if (!started) {
17  systems.engine().inputSystem().getActor().addListener(*this);
18  started = true;
19  }
20 }
21 
23  started = false;
24  systems.engine().inputSystem().getActor().removeListener(*this);
25 }
26 
27 bool PlayerControlled::observe(const bl::input::Actor& actor, unsigned int ctrl,
28  bl::input::DispatchType, bool fromEvent) {
29  if (controllable.isLocked()) return true;
30  if (ctrl == input::Control::Interact && !fromEvent) return true;
31 
32  switch (ctrl) {
34  if (fromEvent) {
35  bl::event::Dispatcher::dispatch<event::StateChange>(
37  }
38  break;
39 
41  break;
42 
43  default:
44  controllable.processControl(static_cast<input::EntityControl>(ctrl),
45  actor.controlActive(input::Control::Sprint));
46  break;
47  }
48  return true;
49 }
50 
51 } // namespace component
52 } // namespace core
Core classes and functionality for both the editor and game.
std::underlying_type_t< Control::EntityControl > EntityControl
Helper typedef to avoid too much casting boilerplate.
Definition: Control.hpp:44
Adding this component to an entity allows it to be controlled.
bool processControl(input::EntityControl command, bool sprint=false, bool overrideLock=false)
Processes the given command and manipulates the entity accordingly.
bool isLocked() const
Returns whether or not this component is locked.
PlayerControlled(system::Systems &systems, Controllable &controllable)
Construct a new Player Controlled component and immediately start taking player input....
void start()
Activate this listener and receive player input. Does not have effect if already activated but anothe...
virtual bool observe(const bl::input::Actor &, unsigned int ctrl, bl::input::DispatchType, bool) override
Forwards the player input to the underlying entity.
void stop()
Stops listening to player input.
@ GamePaused
The game should pause.
Definition: StateChange.hpp:19
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