Peoplemon  0.1.0
Peoplemon 3 game source documentation
Controllable.cpp
Go to the documentation of this file.
2 
5 
6 namespace core
7 {
8 namespace system
9 {
11 : ecs(owner.engine().ecs()) {}
12 
13 bool Controllable::setEntityLocked(bl::ecs::Entity e, bool l, bool p) {
14  component::Controllable* c = ecs.getComponent<component::Controllable>(e);
15  if (c) {
16  BL_LOG_INFO << "Locked entity " << e;
17  c->setLocked(l, p);
18  return true;
19  }
20  else {
21  BL_LOG_ERROR << "Failed to lock entity: " << e;
22  }
23  return false;
24 }
25 
26 bool Controllable::resetEntityLock(bl::ecs::Entity e) {
27  component::Controllable* c = ecs.getComponent<component::Controllable>(e);
28  if (c) {
29  c->resetLock();
30  return true;
31  }
32  return false;
33 }
34 
35 void Controllable::setAllLocks(bool l, bool p) {
36  ecs.getAllComponents<component::Controllable>().forEach(
37  [l, p](bl::ecs::Entity, component::Controllable& c) { c.setLocked(l, p); });
38 }
39 
41  ecs.getAllComponents<component::Controllable>().forEach(
42  [](bl::ecs::Entity, component::Controllable& c) { c.resetLock(); });
43 }
44 
45 } // namespace system
46 } // namespace core
Core classes and functionality for both the editor and game.
Adding this component to an entity allows it to be controlled.
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 setEntityLocked(bl::ecs::Entity entity, bool locked, bool preserve=true)
Set the give entity to be locked or unlocked.
Controllable(Systems &owner)
Construct a new Controllable systems.
bool resetEntityLock(bl::ecs::Entity entity)
Resets the given entity's lock state to the last remembered value.
void resetAllLocks()
Resets all controllable entity locks to the last stored state.
void setAllLocks(bool locked, bool preserve=true)
Sets the lock state for all controllable entities.
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47