An action the player can hold without holding a key, such as fire.
More...
#include <aegis2d/platform/latched_action.hpp>
|
| | LatchedAction (ActionId action, bool enabled=false) noexcept |
| | Follows an action of an ActionMap.
|
| |
| ActionId | action () const noexcept |
| | Action followed.
|
| |
| void | set_enabled (bool enabled) noexcept |
| | Turns the option on or off; either way the action is released.
|
| |
| bool | enabled () const noexcept |
| | Tells whether the option is on.
|
| |
| bool | update (const ActionMap &actions, const Keyboard &keyboard) |
| | Reads the frame and tells whether the action counts as held.
|
| |
| bool | update (const ActionMap &actions, const Keyboard &keyboard, const Gamepad &gamepad) |
| | Reads the frame on the keyboard and the gamepad, as update(const ActionMap&,
const Keyboard&) does on the keyboard: a press of a key or a button of the action switches it.
|
| |
| bool | held () const noexcept |
| | Whether the action counts as held.
|
| |
| void | release () noexcept |
| | Releases a latched action, for example when the player dies or the game pauses.
|
| |
| void | save (core::Config &settings, std::string_view path) const |
| | Writes whether the option is on into the player's settings.
|
| |
| void | load (const core::Config &settings, std::string_view path) |
| | Reads whether the option is on, as written by save().
|
| |
An action the player can hold without holding a key, such as fire.
Players who cannot hold a key down (limited strength, tremor, a switch or a mouth stick) turn this option on: the first press of the action holds it, the next press releases it. With the option off, the action is held while its key is, as usual. The client sends the result in its ecs::PlayerInput, so the server fires at the weapon's rate for as long as the action is held:
auto_fire.
load(settings,
"accessibility.auto_fire");
...
window.poll_events();
◆ LatchedAction()
| aegis2d::platform::LatchedAction::LatchedAction |
( |
ActionId |
action, |
|
|
bool |
enabled = false |
|
) |
| |
|
explicitnoexcept |
Follows an action of an ActionMap.
- Parameters
-
| action | Action to latch, declared in the ActionMap given to update(). |
| enabled | Whether the option is on at first. |
◆ action()
| ActionId aegis2d::platform::LatchedAction::action |
( |
| ) |
const |
|
noexcept |
Action followed.
- Returns
- The action given to the constructor.
◆ enabled()
| bool aegis2d::platform::LatchedAction::enabled |
( |
| ) |
const |
|
noexcept |
Tells whether the option is on.
- Returns
- The last value given to the constructor or to set_enabled().
◆ held()
| bool aegis2d::platform::LatchedAction::held |
( |
| ) |
const |
|
noexcept |
Whether the action counts as held.
- Returns
- The result of the last update();
false before the first one.
◆ load()
| void aegis2d::platform::LatchedAction::load |
( |
const core::Config & |
settings, |
|
|
std::string_view |
path |
|
) |
| |
Reads whether the option is on, as written by save().
A missing value keeps the option as it is; a value that is not a boolean is logged as a warning and ignored. The action is released.
- Parameters
-
◆ release()
| void aegis2d::platform::LatchedAction::release |
( |
| ) |
|
|
noexcept |
Releases a latched action, for example when the player dies or the game pauses.
◆ save()
| void aegis2d::platform::LatchedAction::save |
( |
core::Config & |
settings, |
|
|
std::string_view |
path |
|
) |
| const |
Writes whether the option is on into the player's settings.
- Parameters
-
| settings | Settings to update, then saved with core::Config::save(). |
| path | Dotted path of the value, such as "accessibility.auto_fire". |
◆ set_enabled()
| void aegis2d::platform::LatchedAction::set_enabled |
( |
bool |
enabled | ) |
|
|
noexcept |
Turns the option on or off; either way the action is released.
- Parameters
-
| enabled | true for hold-free, false to hold the key as usual. |
◆ update() [1/2]
| bool aegis2d::platform::LatchedAction::update |
( |
const ActionMap & |
actions, |
|
|
const Keyboard & |
keyboard |
|
) |
| |
Reads the frame and tells whether the action counts as held.
Call it once per frame, after Window::poll_events(). With the option on, each frame in which the action is pressed (ActionMap::pressed()) switches it between held and released.
- Parameters
-
- Returns
- Whether the action is held this frame, as held() then returns.
- Exceptions
-
| std::out_of_range | if the action is not declared in actions. |
◆ update() [2/2]
| bool aegis2d::platform::LatchedAction::update |
( |
const ActionMap & |
actions, |
|
|
const Keyboard & |
keyboard, |
|
|
const Gamepad & |
gamepad |
|
) |
| |
Reads the frame on the keyboard and the gamepad, as update(const ActionMap&,
const Keyboard&) does on the keyboard: a press of a key or a button of the action switches it.
- Parameters
-
- Returns
- Whether the action is held this frame, as held() then returns.
- Exceptions
-
| std::out_of_range | if the action is not declared in actions. |
The documentation for this class was generated from the following file: