Skip to main content

KeymapDef

Struct KeymapDef 

Source
pub struct KeymapDef<A>
where A: ActionSet,
{ pub layouts: BTreeMap<Layout, BTreeMap<A, Vec<Chord>>>, pub layout_names: Vec<(Layout, String)>, pub layout_picker: BTreeMap<Chord, A>, pub pad: BTreeMap<A, Vec<ButtonChord>>, pub playdate: BTreeMap<A, Vec<ButtonChord>>, pub targets: BTreeMap<String, BTreeMap<A, Vec<ButtonChord>>>, pub repeat: RepeatDef, pub chord: ChordDef, pub stick: StickDef, pub crank: CrankDef, }
Expand description

The validated keymap: every Layout’s default keys, the layout picker’s bindings, the default controller buttons, plus the key-repeat timings and stick thresholds they share.

Fields§

§layouts: BTreeMap<Layout, BTreeMap<A, Vec<Chord>>>

Layout → its default keys. After from_source every layout the file lists is present, with every action.

§layout_names: Vec<(Layout, String)>

The layouts in the order the file lists them (the order the layout picker shows them), each with the text key of its name.

§layout_picker: BTreeMap<Chord, A>

The keys that work before any layout is chosen (the layout picker). Actions not listed are unbound there.

§pad: BTreeMap<A, Vec<ButtonChord>>

The default controller buttons, the same in every layout and the layout picker. After from_source every action is present.

§playdate: BTreeMap<A, Vec<ButtonChord>>

The default buttons of a Playdate (game ADR-0070, ticket 1034), whose only buttons are the D-pad, A and B: the file’s playdate table, or a copy of pad for a file without one. A game running on a Playdate uses it in place of pad (for_playdate). The same as targets["playdate"] when the file has one.

§targets: BTreeMap<String, BTreeMap<A, Vec<ButtonChord>>>

The default buttons on a target, by its profile’s id (shuyi_assets::target, ADR-0008 §3): the file’s targets table, with its playdate table as "playdate". A target in it plays with its own table in place of pad (for_target), and shuyi check --target checks the target’s controls on it.

§repeat: RepeatDef

Key-repeat timings, for held keys and held buttons alike.

§chord: ChordDef

How button chords fire (optional in the file).

§stick: StickDef

How far a stick is pushed to count as a direction.

§crank: CrankDef

How far a crank is wound for one notch (optional in the file).

Implementations§

Source§

impl<A> KeymapDef<A>
where A: ActionSet,

Source

pub fn bindings( &self, layout: Layout, group: <A as ActionSet>::Group, ) -> Option<BTreeMap<Chord, A>>

layout’s default bindings of the actions in group, as a chord lookup (None if the keymap has no such layout).

Source

pub fn chords(&self, layout: Layout, action: A) -> &[Chord]

action’s default chords in layout, in file order; empty if the layout or action is missing.

Source

pub fn buttons(&self, action: A) -> &[ButtonChord]

action’s default controller buttons and button chords, in file order; empty if the action is missing (only in a definition built by hand).

Source

pub fn for_playdate(self) -> KeymapDef<A>

This keymap as a Playdate uses it: its playdate table as the default buttons.

Source

pub fn target_buttons(&self, id: &str) -> Option<&BTreeMap<A, Vec<ButtonChord>>>

The default buttons of target id (its profile’s id), if the file gives that target a table of its own (targets).

Source

pub fn for_target(self, id: &str) -> KeymapDef<A>

This keymap as target id uses it: the target’s own table as the default buttons, if it has one, else pad.

Source

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

Whether the keymap has layout (a name from saved settings may name one it no longer has).

Source

pub fn layout_ids(&self) -> impl Iterator<Item = Layout>

The layouts in file order: the order the layout picker lists them.

Source

pub fn first_layout(&self) -> Option<Layout>

The first layout the file lists: the one a screen falls back on while none is chosen.

Source

pub fn layout_text(&self, layout: Layout) -> Option<&str>

The text key of layout’s name, if the keymap has it.

Source

pub fn from_source( file: &str, source: &str, ) -> Result<KeymapDef<A>, Vec<ContentError>>

Parses and validates keymap source, attributing errors to file. Reports a file with no layouts, a bad or repeated layout id, and within each layout every unknown action, unparsable chord, chord bound more than once, reserved chord, action with more than SLOTS chords and missing action (prefixed with the layout’s id), the same for the layout_picker section (except that unlisted actions are unbound there, and an action may have more than SLOTS chords: the picker isn’t rebindable), and for the pad and playdate sections and each table of targets (buttons and button chords instead of key chords, every action listed, none on an action that can’t be rebound, no system menu item in a chord), plus a bad target id, a Playdate table given both ways, bad repeat timing, stick thresholds and crank notch size.

Trait Implementations§

Source§

impl<A> AssetKind for KeymapDef<A>
where A: ActionSet,

Source§

const NAME: &'static str = "keymap"

What messages call the kind, in lowercase words: "image", "palette".
Source§

impl<A> Clone for KeymapDef<A>
where A: Clone + ActionSet,

Source§

fn clone(&self) -> KeymapDef<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 for KeymapDef<A>
where A: Debug + ActionSet,

Source§

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

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

impl<A> Default for KeymapDef<A>
where A: ActionSet,

Source§

fn default() -> KeymapDef<A>

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

impl<'de, A> Deserialize<'de> for KeymapDef<A>
where A: ActionSet + Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<KeymapDef<A>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<A> Eq for KeymapDef<A>
where A: Eq + ActionSet,

Source§

impl<A> PartialEq for KeymapDef<A>
where A: PartialEq + ActionSet,

Source§

fn eq(&self, other: &KeymapDef<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> Serialize for KeymapDef<A>
where A: ActionSet + Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<A> StructuralPartialEq for KeymapDef<A>
where A: PartialEq + ActionSet,

Auto Trait Implementations§

§

impl<A> Freeze for KeymapDef<A>

§

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

§

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

§

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

§

impl<A> Unpin for KeymapDef<A>

§

impl<A> UnsafeUnpin for KeymapDef<A>

§

impl<A> UnwindSafe for KeymapDef<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<K> Bakeable for K

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.