Skip to main content

PlayerKeys

Struct PlayerKeys 

Source
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>

Source

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.

Source

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.

Source

pub fn keymap(&self, def: &KeymapDef<A>, layout: Layout) -> Keymap<A>

The keymap for layout with the player’s keys and buttons.

Source

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.

Source

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.

Source

pub fn is_custom_pad(&self) -> bool

Whether the player has changed the controller buttons.

Source

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.

Source

pub fn is_custom(&self, layout: Layout) -> bool

Whether the player has changed layout’s keys.

Source

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).

Source

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::ALL and slot order); a default slot of that group holding a stored chord is emptied (the key moves, as with LayoutBindings::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>

Source§

fn clone(&self) -> PlayerKeys<A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Debug + ActionSet> Debug for PlayerKeys<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: ActionSet> Default for PlayerKeys<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: Eq + ActionSet> Eq for PlayerKeys<A>

Source§

impl<A: PartialEq + ActionSet> PartialEq for PlayerKeys<A>

Source§

fn eq(&self, other: &PlayerKeys<A>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<A: PartialEq + ActionSet> StructuralPartialEq for PlayerKeys<A>

Auto Trait Implementations§

§

impl<A> Freeze for PlayerKeys<A>

§

impl<A> RefUnwindSafe for PlayerKeys<A>
where A: RefUnwindSafe,

§

impl<A> Send for PlayerKeys<A>
where A: Send,

§

impl<A> Sync for PlayerKeys<A>
where A: Sync,

§

impl<A> Unpin for PlayerKeys<A>

§

impl<A> UnsafeUnpin for PlayerKeys<A>

§

impl<A> UnwindSafe for PlayerKeys<A>
where A: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.