ae52be591b
Adds a new script module exposing Input.bind/value/lastValue/isDown/
wasDown/pressed/released, InputBind.* (the inputbind_t action enum),
and InputButton.* (every named button in the compiled platform's
INPUT_BUTTON_DATA table, e.g. InputButton.SELECT on PSP).
Renames the PLATFORM global to Platform.current for consistency with
Time/Console/Input.
Uppercases every INPUT_BUTTON_DATA .name across inputlinux.c/
inputpsp.c/inputdolphin.c to match the InputButton.* JS constants
(inputButtonGetByName was already case-insensitive, so this doesn't
change matching behavior).
Moves the default key/button-to-action bindings out of
src/duskrpg/input/inputbindmap.h (deleted) and into
assets/scripts/input.js, branching on Platform.current instead of the
old per-platform #ifdefs. Wired in via require('./input.js') from
init.js.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
89 lines
3.2 KiB
JavaScript
89 lines
3.2 KiB
JavaScript
// Copyright (c) 2026 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
// Default input bindings, ported from the old
|
|
// src/duskrpg/input/inputbindmap.h (removed) -- one INPUT_BIND_MAP per
|
|
// compile-time target became one branch here on Platform.current.
|
|
|
|
function bindAll(pairs) {
|
|
for(var i = 0; i < pairs.length; i++) {
|
|
Input.bind(pairs[i][0], pairs[i][1]);
|
|
}
|
|
}
|
|
|
|
if(Platform.current === 'linux' || Platform.current === 'knulli') {
|
|
bindAll([
|
|
// Keyboard
|
|
[InputButton.W, InputBind.UP],
|
|
[InputButton.S, InputBind.DOWN],
|
|
[InputButton.A, InputBind.LEFT],
|
|
[InputButton.D, InputBind.RIGHT],
|
|
[InputButton.LEFT, InputBind.LEFT],
|
|
[InputButton.RIGHT, InputBind.RIGHT],
|
|
[InputButton.UP, InputBind.UP],
|
|
[InputButton.DOWN, InputBind.DOWN],
|
|
[InputButton.ENTER, InputBind.ACCEPT],
|
|
[InputButton.E, InputBind.ACCEPT],
|
|
[InputButton.SPACE, InputBind.ACCEPT],
|
|
[InputButton.TAB, InputBind.CANCEL],
|
|
[InputButton.Q, InputBind.CANCEL],
|
|
[InputButton.ESCAPE, InputBind.RAGEQUIT],
|
|
[InputButton.ENTER, InputBind.PAUSE],
|
|
['`', InputBind.CONSOLE],
|
|
|
|
// Gamepad
|
|
[InputButton.GAMEPAD_UP, InputBind.UP],
|
|
[InputButton.GAMEPAD_DOWN, InputBind.DOWN],
|
|
[InputButton.GAMEPAD_LEFT, InputBind.LEFT],
|
|
[InputButton.GAMEPAD_RIGHT, InputBind.RIGHT],
|
|
[InputButton.GAMEPAD_A, InputBind.ACCEPT],
|
|
[InputButton.GAMEPAD_B, InputBind.CANCEL],
|
|
[InputButton.GAMEPAD_BACK, InputBind.RAGEQUIT],
|
|
[InputButton.GAMEPAD_START, InputBind.PAUSE],
|
|
[InputButton.GAMEPAD_LSTICK_UP, InputBind.UP],
|
|
[InputButton.GAMEPAD_LSTICK_DOWN, InputBind.DOWN],
|
|
[InputButton.GAMEPAD_LSTICK_LEFT, InputBind.LEFT],
|
|
[InputButton.GAMEPAD_LSTICK_RIGHT, InputBind.RIGHT],
|
|
|
|
// Mouse
|
|
[InputButton.MOUSE_X, InputBind.POINTERX],
|
|
[InputButton.MOUSE_Y, InputBind.POINTERY],
|
|
]);
|
|
} else if(Platform.current === 'psp') {
|
|
bindAll([
|
|
[InputButton.UP, InputBind.UP],
|
|
[InputButton.DOWN, InputBind.DOWN],
|
|
[InputButton.LEFT, InputBind.LEFT],
|
|
[InputButton.RIGHT, InputBind.RIGHT],
|
|
[InputButton.ACCEPT, InputBind.ACCEPT],
|
|
[InputButton.CANCEL, InputBind.CANCEL],
|
|
[InputButton.TRIANGLE, InputBind.CONSOLE],
|
|
[InputButton.SELECT, InputBind.RAGEQUIT],
|
|
[InputButton.START, InputBind.PAUSE],
|
|
[InputButton.LSTICK_UP, InputBind.UP],
|
|
[InputButton.LSTICK_DOWN, InputBind.DOWN],
|
|
[InputButton.LSTICK_LEFT, InputBind.LEFT],
|
|
[InputButton.LSTICK_RIGHT, InputBind.RIGHT],
|
|
]);
|
|
} else if(Platform.current === 'gamecube' || Platform.current === 'wii') {
|
|
// GameCube and Wii share the same pad layout for now.
|
|
// TODO: Wiimote, USB Keyboard, probably more.
|
|
bindAll([
|
|
[InputButton.UP, InputBind.UP],
|
|
[InputButton.DOWN, InputBind.DOWN],
|
|
[InputButton.LEFT, InputBind.LEFT],
|
|
[InputButton.RIGHT, InputBind.RIGHT],
|
|
[InputButton.LSTICK_UP, InputBind.UP],
|
|
[InputButton.LSTICK_DOWN, InputBind.DOWN],
|
|
[InputButton.LSTICK_LEFT, InputBind.LEFT],
|
|
[InputButton.LSTICK_RIGHT, InputBind.RIGHT],
|
|
[InputButton.A, InputBind.ACCEPT],
|
|
[InputButton.B, InputBind.CANCEL],
|
|
[InputButton.Z, InputBind.CONSOLE],
|
|
[InputButton.START, InputBind.RAGEQUIT],
|
|
[InputButton.START, InputBind.PAUSE],
|
|
]);
|
|
}
|