Peoplemon  0.1.0
Peoplemon 3 game source documentation
Controllable.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Logging.hpp>
5 
6 namespace core
7 {
8 namespace component
9 {
10 Controllable::Controllable(system::Systems& systems, bl::ecs::Entity owner)
11 : owner(owner)
12 , systems(systems)
13 , locked(false)
14 , wasLocked(false) {}
15 
16 bool Controllable::processControl(input::EntityControl ctrl, bool sprint, bool ignoreLock) {
17  if (locked && !ignoreLock) return false;
18 
19  switch (ctrl) {
21  return systems.movement().moveEntity(owner, bl::tmap::Direction::Up, sprint);
23  return systems.movement().moveEntity(owner, bl::tmap::Direction::Right, sprint);
25  return systems.movement().moveEntity(owner, bl::tmap::Direction::Down, sprint);
27  return systems.movement().moveEntity(owner, bl::tmap::Direction::Left, sprint);
28 
29  case input::Control::Pause: // handled in PlayerControlled
31  return false;
32 
34  return systems.interaction().interact(owner);
35 
37  return false;
38 
39  default:
40  BL_LOG_WARN << "Unknown control: " << static_cast<int>(ctrl);
41  return false;
42  }
43 }
44 
45 void Controllable::setLocked(bool l, bool p) {
46  if (p) wasLocked = locked;
47  locked = l;
48 }
49 
50 void Controllable::resetLock() { locked = wasLocked; }
51 
52 bool Controllable::isLocked() const { return locked; }
53 
54 } // namespace component
55 } // 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
void setLocked(bool lock, bool preserve=true)
Locks the controllable and prevents any commands from being processed. Optionally remembers the previ...
void resetLock()
Resets the lock state back to the last preserved state.
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.
Controllable(system::Systems &systems, bl::ecs::Entity owner)
Construct a new Controllable component.
bool interact(bl::ecs::Entity interactor)
Performs an interation on behalf of the given entity.
Definition: Interaction.cpp:35
bool moveEntity(bl::ecs::Entity entity, bl::tmap::Direction direction, bool fast)
Moves an entity in the given direction using either its fast or slow speed.
Definition: Movement.cpp:27
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
Movement & movement()
Returns a reference to the movement system.
Definition: Systems.cpp:51
Interaction & interaction()
Returns the interaction system.
Definition: Systems.cpp:67