Implementation of IActionManager meant to be used on any context where the user has control over the game. Expected flow for this class is creating it, loading the actions config file, updating it each frame and checking the state of the actions at any time.
More...
#include <ActionManager.h>
|
| | ActionManager (std::unique_ptr< InputManager > inputManager) |
| bool | LoadActions (std::vector< char > data) override |
| | Loads a list of actions from a JSON string data.
|
| bool | LoadActionsFromFile (const std::string &path) override |
| | Loads a file from the system (without using the PackCatalog) and calls LoadActions with its content.
|
| bool | HasAction (const std::string &actionName) const override |
| | Checks if there is a action with the provided name in the list.
|
| void | Update (const float &delta) override |
| | Updates the internal input manager. Check InputManager.
|
| bool | Performed (const std::string &actionName) const override |
| | Checks if an action has been performed this frame.
|
| float | Value (const std::string &actionName) const override |
| | Gets the analog value of an action.
|
| Vector2f | CompoundValue (const std::string &action1, const std::string &action2) const override |
| | Utility method to get two values at the same time. Useful to get values on vertical and horizontal axis at the same time, for example.
|
Implementation of IActionManager meant to be used on any context where the user has control over the game. Expected flow for this class is creating it, loading the actions config file, updating it each frame and checking the state of the actions at any time.
Actions are a set of PerformableAction, which defines when an action is considered as performed and how it gets its value.
Related and important classes or structures:
Ownership:
- Owns the input manager.
- Owns a set of actions, loaded from the data JSON.
Guarantees:
- An updated state of each action each frame, accessible via polling (Performed, Value, CompoundValue)
Non responsible:
- Dispatching events when an action is performed.
Thread safety:
- Polling data is thread safe, as it doesn't modify the class.
- Update is not thread safe.
◆ ActionManager()
| Mochi::Input::ActionManager::ActionManager |
( |
std::unique_ptr< InputManager > | inputManager | ) |
|
- Parameters
-
| inputManager | A unique pointer to the input manager. Reference will be moved by this class to take ownership of the unique pointer. |
◆ CompoundValue()
| Vector2f Mochi::Input::ActionManager::CompoundValue |
( |
const std::string & | action1, |
|
|
const std::string & | action2 ) const |
|
overridevirtual |
Utility method to get two values at the same time. Useful to get values on vertical and horizontal axis at the same time, for example.
- Parameters
-
| action1 | First action to check. |
| action2 | Second action to check. |
- Returns
- Vector with the two resulting values.
Implements Mochi::Input::IActionManager.
◆ HasAction()
| bool Mochi::Input::ActionManager::HasAction |
( |
const std::string & | actionName | ) |
const |
|
overridevirtual |
Checks if there is a action with the provided name in the list.
- Parameters
-
| actionName | The name of the action to check. |
- Returns
- True if the action exists, false otherwise.
Implements Mochi::Input::IActionManager.
◆ LoadActions()
| bool Mochi::Input::ActionManager::LoadActions |
( |
std::vector< char > | data | ) |
|
|
overridevirtual |
Loads a list of actions from a JSON string data.
- Exceptions
-
- Parameters
-
| data | The string JSON with the actions data. |
- Returns
- True if loaded correctly.
Implements Mochi::Input::IActionManager.
◆ LoadActionsFromFile()
| bool Mochi::Input::ActionManager::LoadActionsFromFile |
( |
const std::string & | path | ) |
|
|
overridevirtual |
Loads a file from the system (without using the PackCatalog) and calls LoadActions with its content.
- Parameters
-
| path | The path to the file. |
- Returns
- True if loaded correctly.
Implements Mochi::Input::IActionManager.
◆ Performed()
| bool Mochi::Input::ActionManager::Performed |
( |
const std::string & | actionName | ) |
const |
|
overridevirtual |
Checks if an action has been performed this frame.
- Parameters
-
| actionName | The name of the action. |
- Returns
- True if the action has been performed this frame. An analog action is true if its value is different from 0.
Implements Mochi::Input::IActionManager.
◆ Update()
| void Mochi::Input::ActionManager::Update |
( |
const float & | delta | ) |
|
|
overridevirtual |
◆ Value()
| float Mochi::Input::ActionManager::Value |
( |
const std::string & | actionName | ) |
const |
|
overridevirtual |
Gets the analog value of an action.
- Parameters
-
| actionName | The name of the action. |
- Returns
- The analog value of the action.
Implements Mochi::Input::IActionManager.
The documentation for this class was generated from the following files: