pub struct PlayerKeys<A: ActionSet> { /* private fields */ }Expand description
Every layout’s player bindings and the controller buttons, saved under whatever name the game stores them under. A layout the player hasn’t changed has no entry and uses its defaults, and so do the buttons. Each layout keeps its own keys; the buttons are shared by every layout.
Implementations§
Source§impl<A: ActionSet> PlayerKeys<A>
impl<A: ActionSet> PlayerKeys<A>
Sourcepub fn bindings(&self, def: &KeymapDef<A>, layout: Layout) -> LayoutBindings<A>
pub fn bindings(&self, def: &KeymapDef<A>, layout: Layout) -> LayoutBindings<A>
layout’s bindings: the player’s, or the defaults if they haven’t
changed that layout.
Sourcepub fn pad_bindings(&self, def: &KeymapDef<A>) -> PadBindings<A>
pub fn pad_bindings(&self, def: &KeymapDef<A>) -> PadBindings<A>
The controller buttons: the player’s, or the defaults if they haven’t changed them. The same whatever the layout.
Sourcepub fn keymap(&self, def: &KeymapDef<A>, layout: Layout) -> Keymap<A>
pub fn keymap(&self, def: &KeymapDef<A>, layout: Layout) -> Keymap<A>
The keymap for layout with the player’s keys and buttons.
Sourcepub fn layout_picker_keymap(&self, def: &KeymapDef<A>) -> Keymap<A>
pub fn layout_picker_keymap(&self, def: &KeymapDef<A>) -> Keymap<A>
The keymap before any layout is chosen (Keymap::layout_picker),
with the player’s buttons: someone playing only with a controller
never picks a layout.
Sourcepub fn set_pad(&mut self, def: &KeymapDef<A>, bindings: PadBindings<A>)
pub fn set_pad(&mut self, def: &KeymapDef<A>, bindings: PadBindings<A>)
Replaces the controller buttons. Buttons equal to the defaults are
stored as “no entry”, as in set.
Sourcepub fn is_custom_pad(&self) -> bool
pub fn is_custom_pad(&self) -> bool
Whether the player has changed the controller buttons.
Sourcepub fn set(
&mut self,
def: &KeymapDef<A>,
layout: Layout,
bindings: LayoutBindings<A>,
)
pub fn set( &mut self, def: &KeymapDef<A>, layout: Layout, bindings: LayoutBindings<A>, )
Replaces layout’s bindings; the other layout is untouched.
Bindings equal to the defaults are stored as “no entry”, so a later
change to the default keys reaches a player who restored them.
Sourcepub fn to_ron(&self) -> String
pub fn to_ron(&self) -> String
The saved form (RON): every changed layout with all its actions’
slots, e.g. "Confirm": [Some("f"), Some("Enter"), None], and the
buttons the same way under pad if changed, e.g. "Confirm": [Some("South"), None, None], a button chord as "South+East"
(ticket 1034: saved bindings without chords read as before).
Sourcepub fn from_ron(text: &str, def: &KeymapDef<A>) -> (Self, Vec<String>)
pub fn from_ron(text: &str, def: &KeymapDef<A>) -> (Self, Vec<String>)
Reads the saved form, repairing rather than failing, and returns the result with a warning for everything it had to fix:
- unreadable text or an unknown version: defaults for every layout and for the buttons;
- version 1 (keys only): the default buttons;
- layouts the keymap doesn’t have, unknown actions, unreadable chords or buttons and extra slots are dropped;
- reserved chords are dropped;
- a chord in two stored slots of one group’s actions stays in
the first (in
ActionSet::ALLand slot order); a default slot of that group holding a stored chord is emptied (the key moves, as withLayoutBindings::bind); - an action the layout doesn’t list keeps its default slots;
- a layout left with a required action unmapped goes back to its defaults;
- the buttons are repaired by the same rules as one layout’s keys.
Trait Implementations§
Source§impl<A: Clone + ActionSet> Clone for PlayerKeys<A>
impl<A: Clone + ActionSet> Clone for PlayerKeys<A>
Source§fn clone(&self) -> PlayerKeys<A>
fn clone(&self) -> PlayerKeys<A>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more