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: RepeatDefKey-repeat timings, for held keys and held buttons alike.
chord: ChordDefHow button chords fire (optional in the file).
stick: StickDefHow far a stick is pushed to count as a direction.
crank: CrankDefHow far a crank is wound for one notch (optional in the file).
Implementations§
Source§impl<A> KeymapDef<A>where
A: ActionSet,
impl<A> KeymapDef<A>where
A: ActionSet,
Sourcepub fn bindings(
&self,
layout: Layout,
group: <A as ActionSet>::Group,
) -> Option<BTreeMap<Chord, A>>
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).
Sourcepub fn chords(&self, layout: Layout, action: A) -> &[Chord]
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.
action’s default controller buttons and button chords, in file
order; empty if the action is missing (only in a definition built by
hand).
Sourcepub fn for_playdate(self) -> KeymapDef<A>
pub fn for_playdate(self) -> KeymapDef<A>
This keymap as a Playdate uses it: its playdate
table as the default buttons.
The default buttons of target id (its profile’s id), if the file
gives that target a table of its own (targets).
Sourcepub fn for_target(self, id: &str) -> KeymapDef<A>
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.
Sourcepub fn has_layout(&self, layout: Layout) -> bool
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).
Sourcepub fn layout_ids(&self) -> impl Iterator<Item = Layout>
pub fn layout_ids(&self) -> impl Iterator<Item = Layout>
The layouts in file order: the order the layout picker lists them.
Sourcepub fn first_layout(&self) -> Option<Layout>
pub fn first_layout(&self) -> Option<Layout>
The first layout the file lists: the one a screen falls back on while none is chosen.
Sourcepub fn layout_text(&self, layout: Layout) -> Option<&str>
pub fn layout_text(&self, layout: Layout) -> Option<&str>
The text key of layout’s name, if the keymap has it.
Sourcepub fn from_source(
file: &str,
source: &str,
) -> Result<KeymapDef<A>, Vec<ContentError>>
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.