mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-22 16:46:10 -08:00
feat(controller): add hold + press combos to main bindings (#328)
* feat(controller): add hold + press combos to main bindings Main Alt+C actions can now be learned as combos such as L1 + D-pad right. A combo fires on each press while its hold button is down, and claims its press input so token move and popup scroll ignore it until it is released. A plain action on a hold button fires on release, unless another bound button was pressed during the hold. The save path needed two changes for combos to persist. The IPC validator rebuilt bindings field by field and dropped `hold`, so Alt+C showed a combo from its local copy until the next reload turned it back into a plain button. Validator and config resolver now share one parser. Saves also replace the controller section, since the deep merge in patchRawConfig kept the old `hold` when a combo was rebound to one button. Also fixes Learn on the (D-pad) rows, which threw after cancel() cleared the capture target. * test(launcher): wait for content in background child test The test polled for the fake app's output files to exist, but the shell creates a redirect target before writing to it. A poll landing in that gap read an empty env file and failed with '' !== '1', as seen once in CI. Wait until both files have content instead. * fix(controller): keep a diagonal push from learning as a combo Learn took the first axis of a diagonal stick push as the hold and the second as the press, saving a combo that one axis could never trigger. This reached main Alt+C rows when they moved to combo capture. Axes crossing the threshold in the same poll as the first input now count as one movement. A second axis moved in a later poll still records a combo. * fix(controller): only treat simultaneous axes as one movement The diagonal push guard also blocked an axis activated in the same poll as a button, so L1 plus a stick direction could not record the stick until it was released and moved again. Apply the guard only when the first input is an axis, so that input pair records as a combo again.
This commit is contained in:
1 parent
79e5535823
commit
b31ddce627
30 files changed
+1078
-295
No files matched your search
@@ -39,6 +39,44 @@ test('a button on the D-pad clashes with a D-pad row that is still on', () => {
|
||||
);
|
||||
});
|
||||
|
||||
const L1_DPAD_RIGHT = {
|
||||
kind: 'button',
|
||||
buttonIndex: 15,
|
||||
hold: { kind: 'button', buttonIndex: 4 },
|
||||
} as const;
|
||||
|
||||
test('a combo does not clash with its hold or press used elsewhere on their own', () => {
|
||||
// L1 is Play Current Audio by default; the D-pad is still on Token Move.
|
||||
assert.deepEqual(issuesWith({ nextAudio: L1_DPAD_RIGHT }), {});
|
||||
});
|
||||
|
||||
test('two actions on the same combo both warn', () => {
|
||||
assert.deepEqual(issuesWith({ nextAudio: L1_DPAD_RIGHT, nextEntry: L1_DPAD_RIGHT }), {
|
||||
nextAudio: 'Same as Next Entry',
|
||||
nextEntry: 'Same as Next Audio',
|
||||
});
|
||||
});
|
||||
|
||||
test('a combo holding and pressing the same button warns', () => {
|
||||
assert.deepEqual(
|
||||
issuesWith({
|
||||
nextEntry: { kind: 'button', buttonIndex: 7, hold: { kind: 'button', buttonIndex: 7 } },
|
||||
}),
|
||||
{ nextEntry: 'Hold and press are the same button' },
|
||||
);
|
||||
});
|
||||
|
||||
test('the secondary subtitle hold warns on a hold button, since it cannot wait for release', () => {
|
||||
assert.deepEqual(
|
||||
issuesWith({
|
||||
playCurrentAudio: { kind: 'none' },
|
||||
nextAudio: L1_DPAD_RIGHT,
|
||||
holdSecondarySub: { kind: 'button', buttonIndex: 4 },
|
||||
}),
|
||||
{ holdSecondarySub: 'Also the hold button of Next Audio' },
|
||||
);
|
||||
});
|
||||
|
||||
test('a D-pad reported as a hat axis also counts as the D-pad', () => {
|
||||
assert.deepEqual(
|
||||
issuesWith({ previousEntry: { kind: 'axis', axisIndex: 7, direction: 'negative' } }),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { controllerReviewInputSourceKey } from '../../shared/controller-review';
|
||||
import { DPAD_AXIS_INDEX, DPAD_BUTTON_INDEX } from '../handlers/gamepad-controller.js';
|
||||
import type {
|
||||
ControllerDpadFallback,
|
||||
@@ -31,10 +32,14 @@ const buttonKey = (buttonIndex: number) => `button:${buttonIndex}`;
|
||||
const axisKey = (axisIndex: number, direction: 'negative' | 'positive') =>
|
||||
`axis:${axisIndex}:${direction}`;
|
||||
|
||||
/**
|
||||
* A combo counts as one input, apart from its hold and press alone: a plain action on the hold
|
||||
* button waits for release, and a combo keeps its press away from plain actions and stick rows.
|
||||
*/
|
||||
function discreteInputs(binding: ResolvedControllerDiscreteBinding): string[] {
|
||||
if (binding.kind === 'none') return [];
|
||||
if ('buttonIndex' in binding) return [buttonKey(binding.buttonIndex)];
|
||||
return [axisKey(binding.axisIndex, binding.direction)];
|
||||
const press = controllerReviewInputSourceKey(binding);
|
||||
return [binding.hold ? `${controllerReviewInputSourceKey(binding.hold)}+${press}` : press];
|
||||
}
|
||||
|
||||
function stickInputs(binding: ResolvedControllerAxisBinding): string[] {
|
||||
@@ -74,6 +79,8 @@ export function findControllerBindingIssues(
|
||||
definitions: readonly ControllerBindingIssueDefinition[],
|
||||
bindings: ControllerBindings,
|
||||
): Partial<Record<string, string>> {
|
||||
const issues: Partial<Record<string, string>> = {};
|
||||
const holdActions = new Map<string, string>();
|
||||
const rows: { key: string; label: string; inputs: string[] }[] = [];
|
||||
for (const definition of definitions) {
|
||||
if (INACTIVE_BINDINGS.has(definition.id)) continue;
|
||||
@@ -92,15 +99,30 @@ export function findControllerBindingIssues(
|
||||
inputs: dpadInputs(axisBinding.kind === 'none' ? 'none' : axisBinding.dpadFallback),
|
||||
});
|
||||
} else {
|
||||
const discreteBinding = binding as ResolvedControllerDiscreteBinding;
|
||||
rows.push({
|
||||
key: definition.id,
|
||||
label: definition.label,
|
||||
inputs: discreteInputs(binding as ResolvedControllerDiscreteBinding),
|
||||
inputs: discreteInputs(discreteBinding),
|
||||
});
|
||||
if (discreteBinding.kind !== 'none' && discreteBinding.hold) {
|
||||
const holdKey = controllerReviewInputSourceKey(discreteBinding.hold);
|
||||
if (holdKey === controllerReviewInputSourceKey(discreteBinding)) {
|
||||
issues[definition.id] = 'Hold and press are the same button';
|
||||
} else if (!holdActions.has(holdKey)) {
|
||||
holdActions.set(holdKey, definition.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const issues: Partial<Record<string, string>> = {};
|
||||
// Everything else on a hold button can wait for release. This one shows while held.
|
||||
const secondaryHold = bindings.holdSecondarySub;
|
||||
if (secondaryHold.kind !== 'none' && !secondaryHold.hold) {
|
||||
const comboLabel = holdActions.get(controllerReviewInputSourceKey(secondaryHold));
|
||||
if (comboLabel) issues.holdSecondarySub = `Also the hold button of ${comboLabel}`;
|
||||
}
|
||||
|
||||
for (const row of rows) {
|
||||
const inputs = new Set(row.inputs);
|
||||
const clashes = rows
|
||||
|
||||
@@ -216,7 +216,7 @@ test('controller config form expands the learning row with a listening edit pane
|
||||
assert.equal(panel.classList.contains('controller-config-edit-panel'), true);
|
||||
|
||||
const hint = findOne(panel, 'controller-config-edit-hint');
|
||||
assert.equal(hint.textContent, 'Press a button, trigger, or move a stick…');
|
||||
assert.equal(hint.textContent, 'Press a button, or hold one and press another for a combo…');
|
||||
assert.equal(hint.classList.contains('learning'), true);
|
||||
assert.equal(findOne(panel, 'btn-learn').textContent, 'Listening…');
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ export type ControllerScreenLearning = {
|
||||
};
|
||||
import type {
|
||||
ControllerDpadFallback,
|
||||
ControllerRawInput,
|
||||
ResolvedControllerAxisBinding,
|
||||
ResolvedControllerConfig,
|
||||
ResolvedControllerDiscreteBinding,
|
||||
@@ -296,22 +297,25 @@ export function getFriendlyAxisName(axisIndex: number, mapping?: ControllerMappi
|
||||
return names[axisIndex] ?? `Axis ${axisIndex}`;
|
||||
}
|
||||
|
||||
function formatInputSummary(input: ControllerRawInput): string {
|
||||
return input.kind === 'button'
|
||||
? `Button ${input.buttonIndex}`
|
||||
: `Axis ${input.axisIndex} ${input.direction === 'positive' ? '+' : '-'}`;
|
||||
}
|
||||
|
||||
export function formatControllerBindingSummary(
|
||||
binding: ResolvedControllerDiscreteBinding | ResolvedControllerAxisBinding,
|
||||
): string {
|
||||
if (binding.kind === 'none') {
|
||||
return 'Disabled';
|
||||
}
|
||||
if ('direction' in binding) {
|
||||
return `Axis ${binding.axisIndex} ${binding.direction === 'positive' ? '+' : '-'}`;
|
||||
if ('dpadFallback' in binding) {
|
||||
return binding.dpadFallback === 'none'
|
||||
? `Axis ${binding.axisIndex}`
|
||||
: `Axis ${binding.axisIndex} + D-pad ${binding.dpadFallback}`;
|
||||
}
|
||||
if ('buttonIndex' in binding) {
|
||||
return `Button ${binding.buttonIndex}`;
|
||||
}
|
||||
if (binding.dpadFallback === 'none') {
|
||||
return `Axis ${binding.axisIndex}`;
|
||||
}
|
||||
return `Axis ${binding.axisIndex} + D-pad ${binding.dpadFallback}`;
|
||||
const press = formatInputSummary(binding);
|
||||
return binding.hold ? `${formatInputSummary(binding.hold)} + ${press}` : press;
|
||||
}
|
||||
|
||||
function formatFriendlyStickLabel(
|
||||
@@ -322,20 +326,36 @@ function formatFriendlyStickLabel(
|
||||
return getFriendlyAxisName(binding.axisIndex, mapping);
|
||||
}
|
||||
|
||||
export function formatFriendlyInputLabel(
|
||||
input: ControllerRawInput,
|
||||
mapping: ControllerMapping,
|
||||
faceButtonLabels: FaceButtonLabels,
|
||||
): string {
|
||||
if (input.kind === 'button') {
|
||||
return getFriendlyButtonName(input.buttonIndex, mapping, faceButtonLabels);
|
||||
}
|
||||
const name = getFriendlyAxisName(input.axisIndex, mapping);
|
||||
return `${name} ${input.direction === 'positive' ? '+' : '\u2212'}`;
|
||||
}
|
||||
|
||||
function formatFriendlyBindingLabel(
|
||||
binding: ResolvedControllerDiscreteBinding | ResolvedControllerAxisBinding,
|
||||
mapping: ControllerMapping,
|
||||
faceButtonLabels: FaceButtonLabels,
|
||||
): string {
|
||||
if (binding.kind === 'none') return 'None';
|
||||
if ('direction' in binding) {
|
||||
const name = getFriendlyAxisName(binding.axisIndex, mapping);
|
||||
return `${name} ${binding.direction === 'positive' ? '+' : '\u2212'}`;
|
||||
}
|
||||
if ('buttonIndex' in binding) {
|
||||
return getFriendlyButtonName(binding.buttonIndex, mapping, faceButtonLabels);
|
||||
}
|
||||
return getFriendlyAxisName(binding.axisIndex, mapping);
|
||||
if ('dpadFallback' in binding) return getFriendlyAxisName(binding.axisIndex, mapping);
|
||||
const press = formatFriendlyInputLabel(binding, mapping, faceButtonLabels);
|
||||
return binding.hold
|
||||
? `${formatFriendlyInputLabel(binding.hold, mapping, faceButtonLabels)} + ${press}`
|
||||
: press;
|
||||
}
|
||||
|
||||
/** What Alt+C asks for while learning a binding that can be a combo. */
|
||||
function formatComboLearnHint(holdLabel: string | null): string {
|
||||
return holdLabel
|
||||
? `Holding ${holdLabel}: press another button for a combo, or let go to use ${holdLabel} alone\u2026`
|
||||
: 'Press a button, or hold one and press another for a combo\u2026';
|
||||
}
|
||||
|
||||
/** Unique key for expanded rows. Stick rows use the action id, dpad rows append ':dpad'. */
|
||||
@@ -345,6 +365,8 @@ export function createControllerConfigForm(options: {
|
||||
container: HTMLElement;
|
||||
getBindings: () => ResolvedControllerConfig['bindings'];
|
||||
getLearningActionId: () => ControllerBindingActionId | null;
|
||||
/** The hold button pressed so far while learning a discrete action, if any. */
|
||||
getLearningHoldLabel?: () => string | null;
|
||||
getDpadLearningActionId: () => ControllerBindingActionId | null;
|
||||
onLearn: (actionId: ControllerBindingActionId, bindingType: 'discrete' | 'axis') => void;
|
||||
onClear: (actionId: ControllerBindingActionId) => void;
|
||||
@@ -539,11 +561,7 @@ export function createControllerConfigForm(options: {
|
||||
options.container.appendChild(row);
|
||||
|
||||
if (isExpanded) {
|
||||
const hint = !isLearning
|
||||
? `Currently: ${current}`
|
||||
: holdLabel
|
||||
? `Holding ${holdLabel}: press another button for a combo, or let go to use ${holdLabel} alone\u2026`
|
||||
: 'Press a button, or hold one and press another for a combo\u2026';
|
||||
const hint = isLearning ? formatComboLearnHint(holdLabel) : `Currently: ${current}`;
|
||||
const panel = createEditPanel(rowKey, hint, isLearning, {
|
||||
onLearn: learn,
|
||||
onClear: (e) => {
|
||||
@@ -565,14 +583,17 @@ export function createControllerConfigForm(options: {
|
||||
const rowKey = definition.id as string;
|
||||
const isExpanded = expandedRowKey === rowKey;
|
||||
const isLearning = learningActionId === definition.id;
|
||||
const holdLabel = isLearning ? (options.getLearningHoldLabel?.() ?? null) : null;
|
||||
|
||||
const row = createRow(
|
||||
definition.label,
|
||||
formatFriendlyBindingLabel(
|
||||
binding,
|
||||
options.getControllerMapping?.(),
|
||||
options.getFaceButtonLabels?.(),
|
||||
),
|
||||
holdLabel
|
||||
? `${holdLabel} + \u2026`
|
||||
: formatFriendlyBindingLabel(
|
||||
binding,
|
||||
options.getControllerMapping?.(),
|
||||
options.getFaceButtonLabels?.(),
|
||||
),
|
||||
binding.kind === 'none',
|
||||
isExpanded,
|
||||
`Learn ${definition.label}`,
|
||||
@@ -596,7 +617,7 @@ export function createControllerConfigForm(options: {
|
||||
|
||||
if (isExpanded) {
|
||||
const hint = isLearning
|
||||
? 'Press a button, trigger, or move a stick\u2026'
|
||||
? formatComboLearnHint(holdLabel)
|
||||
: `Currently: ${formatControllerBindingSummary(binding)}`;
|
||||
const panel = createEditPanel(rowKey, hint, isLearning, {
|
||||
onLearn: (e) => {
|
||||
|
||||
@@ -294,6 +294,9 @@ test('controller select modal learn mode captures fresh button input and persist
|
||||
}));
|
||||
state.controllerRawButtons[11] = { value: 1, pressed: true, touched: true };
|
||||
modal.updateDevices();
|
||||
// A lone button is only final once released: it could still become a combo's hold.
|
||||
state.controllerRawButtons[11] = { value: 0, pressed: false, touched: false };
|
||||
modal.updateDevices();
|
||||
|
||||
await Promise.resolve();
|
||||
|
||||
@@ -423,6 +426,9 @@ test('controller select modal binding badge starts learn mode and persists bindi
|
||||
}));
|
||||
state.controllerRawButtons[11] = { value: 1, pressed: true, touched: true };
|
||||
modal.updateDevices();
|
||||
// A lone button is only final once released: it could still become a combo's hold.
|
||||
state.controllerRawButtons[11] = { value: 0, pressed: false, touched: false };
|
||||
modal.updateDevices();
|
||||
|
||||
await Promise.resolve();
|
||||
|
||||
@@ -543,6 +549,9 @@ test('controller select modal edit control starts learn mode and persists bindin
|
||||
}));
|
||||
state.controllerRawButtons[11] = { value: 1, pressed: true, touched: true };
|
||||
modal.updateDevices();
|
||||
// A lone button is only final once released: it could still become a combo's hold.
|
||||
state.controllerRawButtons[11] = { value: 0, pressed: false, touched: false };
|
||||
modal.updateDevices();
|
||||
|
||||
await Promise.resolve();
|
||||
|
||||
@@ -736,6 +745,68 @@ test('controller select modal learns a review combo and saves it to the controll
|
||||
}
|
||||
});
|
||||
|
||||
test('controller select modal learns a combo for a main action', async () => {
|
||||
const domHandle = installFakeDom();
|
||||
const saved: unknown[] = [];
|
||||
|
||||
Object.defineProperty(globalThis, 'window', {
|
||||
configurable: true,
|
||||
value: {
|
||||
focus: () => {},
|
||||
electronAPI: {
|
||||
saveControllerConfig: async (update: unknown) => {
|
||||
saved.push(update);
|
||||
},
|
||||
notifyOverlayModalClosed: () => {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const { state, dom } = buildContext();
|
||||
const modal = createControllerSelectModal({ state, dom } as never, {
|
||||
modalStateReader: { isAnyModalOpen: () => false },
|
||||
syncSettingsModalSubtitleSuppression: () => {},
|
||||
notifyControllerDisabled: () => {},
|
||||
});
|
||||
modal.wireDomEvents();
|
||||
modal.openControllerSelectModal();
|
||||
|
||||
const firstBadge = () => dom.controllerConfigList.children[1].children[1].children[0];
|
||||
firstBadge().dispatch('click');
|
||||
|
||||
const buttons = (pressed: number[]) =>
|
||||
Array.from({ length: 17 }, (_, index) => ({
|
||||
value: pressed.includes(index) ? 1 : 0,
|
||||
pressed: pressed.includes(index),
|
||||
touched: pressed.includes(index),
|
||||
}));
|
||||
|
||||
// Hold L1, then press D-pad right.
|
||||
state.controllerRawButtons = buttons([4]);
|
||||
modal.updateDevices();
|
||||
assert.equal(firstBadge().textContent, 'LB / L1 + \u2026');
|
||||
state.controllerRawButtons = buttons([4, 15]);
|
||||
modal.updateDevices();
|
||||
|
||||
// Let the save finish so the row re-renders with the saved combo.
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
const binding = {
|
||||
kind: 'button',
|
||||
buttonIndex: 15,
|
||||
hold: { kind: 'button', buttonIndex: 4 },
|
||||
};
|
||||
assert.deepEqual(saved.at(-1), {
|
||||
profiles: { 'pad-1': { bindings: { toggleLookup: binding } } },
|
||||
});
|
||||
assert.deepEqual(state.controllerConfig?.profiles['pad-1']?.bindings.toggleLookup, binding);
|
||||
assert.equal(firstBadge().textContent, 'LB / L1 + D-pad Right');
|
||||
} finally {
|
||||
domHandle.restore();
|
||||
}
|
||||
});
|
||||
|
||||
function findAllByClass(root: any, className: string, found: any[] = []): any[] {
|
||||
for (const child of root.children ?? []) {
|
||||
if (
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { ModalStateReader, RendererContext } from '../context';
|
||||
import { resolveControllerConfigForGamepad } from '../controller-profile-config.js';
|
||||
import { createControllerBindingCapture } from '../handlers/controller-binding-capture.js';
|
||||
import { createControllerComboCapture } from '../handlers/controller-combo-capture.js';
|
||||
import {
|
||||
createControllerComboCapture,
|
||||
type ControllerCapturedCombo,
|
||||
} from '../handlers/controller-combo-capture.js';
|
||||
import {
|
||||
CONTROLLER_FACE_BUTTON_STYLES,
|
||||
formatControllerReviewInput,
|
||||
@@ -18,11 +21,14 @@ import {
|
||||
} from '../../shared/controller-screens';
|
||||
import {
|
||||
createControllerConfigForm,
|
||||
formatFriendlyInputLabel,
|
||||
getControllerBindingDefinition,
|
||||
getDefaultControllerBinding,
|
||||
getDefaultDpadFallback,
|
||||
} from './controller-config-form.js';
|
||||
|
||||
import type { ControllerDpadFallback, ControllerRawInput } from '../../types';
|
||||
|
||||
const PRESS_TO_EDIT_STATUS = 'Press any button on your controller to edit its bindings.';
|
||||
|
||||
/** `8BitDo Ultimate Wireless Controller (STANDARD GAMEPAD Vendor: …)` → the name part. */
|
||||
@@ -75,12 +81,15 @@ export function createControllerSelectModal(
|
||||
let learningActionId: ControllerBindingKey | null = null;
|
||||
let dpadLearningActionId: ControllerBindingKey | null = null;
|
||||
let bindingCapture: ReturnType<typeof createControllerBindingCapture> | null = null;
|
||||
let screenLearning: {
|
||||
screen: ControllerScreenDefinition;
|
||||
actionId: string;
|
||||
type ComboLearning = {
|
||||
capture: ReturnType<typeof createControllerComboCapture>;
|
||||
holdLabel: string | null;
|
||||
} | null = null;
|
||||
};
|
||||
/** Set with `learningActionId` while learning a discrete row. */
|
||||
let discreteLearning: ComboLearning | null = null;
|
||||
let screenLearning:
|
||||
| (ComboLearning & { screen: ControllerScreenDefinition; actionId: string })
|
||||
| null = null;
|
||||
|
||||
/** The controller the overlay reports in use, fetched when the window opens. */
|
||||
let overlayActiveControllerId: string | null = null;
|
||||
@@ -161,6 +170,36 @@ export function createControllerSelectModal(
|
||||
screenLearning = null;
|
||||
}
|
||||
|
||||
function startComboLearning(): ComboLearning {
|
||||
const config = ctx.state.controllerConfig;
|
||||
const capture = createControllerComboCapture({
|
||||
triggerDeadzone: config?.triggerDeadzone ?? 0.5,
|
||||
stickDeadzone: config?.stickDeadzone ?? 0.2,
|
||||
});
|
||||
capture.arm({ axes: ctx.state.controllerRawAxes, buttons: ctx.state.controllerRawButtons });
|
||||
return { capture, holdLabel: null };
|
||||
}
|
||||
|
||||
/** Advances a combo capture, showing the hold button so far; returns the finished combo. */
|
||||
function pollComboLearning(
|
||||
learning: ComboLearning,
|
||||
formatHold: (input: ControllerRawInput) => string,
|
||||
): ControllerCapturedCombo | null {
|
||||
const state = learning.capture.poll({
|
||||
axes: ctx.state.controllerRawAxes,
|
||||
buttons: ctx.state.controllerRawButtons,
|
||||
});
|
||||
if (state.status === 'done') return state.binding;
|
||||
if (state.status === 'holding') {
|
||||
const holdLabel = formatHold(state.hold);
|
||||
if (holdLabel !== learning.holdLabel) {
|
||||
learning.holdLabel = holdLabel;
|
||||
controllerConfigForm.render();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function actionLabel(screen: ControllerScreenDefinition, actionId: string): string {
|
||||
return getControllerScreenAction(screen, actionId).label;
|
||||
}
|
||||
@@ -203,6 +242,7 @@ export function createControllerSelectModal(
|
||||
}));
|
||||
},
|
||||
getScreenInputContext,
|
||||
getLearningHoldLabel: () => discreteLearning?.holdLabel ?? null,
|
||||
getScreenLearning: () =>
|
||||
screenLearning
|
||||
? {
|
||||
@@ -216,14 +256,9 @@ export function createControllerSelectModal(
|
||||
learningActionId = null;
|
||||
dpadLearningActionId = null;
|
||||
bindingCapture = null;
|
||||
const config = ctx.state.controllerConfig;
|
||||
const capture = createControllerComboCapture({
|
||||
triggerDeadzone: config?.triggerDeadzone ?? 0.5,
|
||||
stickDeadzone: config?.stickDeadzone ?? 0.2,
|
||||
});
|
||||
capture.arm({ axes: ctx.state.controllerRawAxes, buttons: ctx.state.controllerRawButtons });
|
||||
discreteLearning = null;
|
||||
const screen = getControllerScreen(screenId);
|
||||
screenLearning = { screen, actionId, capture, holdLabel: null };
|
||||
screenLearning = { ...startComboLearning(), screen, actionId };
|
||||
controllerConfigForm.render();
|
||||
setStatus(
|
||||
`Press a button for ${actionLabel(screen, actionId)}, or hold one and press another for a combo.`,
|
||||
@@ -264,6 +299,17 @@ export function createControllerSelectModal(
|
||||
if (!definition) return;
|
||||
dpadLearningActionId = null;
|
||||
cancelScreenLearning();
|
||||
learningActionId = actionId;
|
||||
if (bindingType === 'discrete') {
|
||||
bindingCapture = null;
|
||||
discreteLearning = startComboLearning();
|
||||
controllerConfigForm.render();
|
||||
setStatus(
|
||||
`Press a button for ${definition.label}, or hold one and press another for a combo.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
discreteLearning = null;
|
||||
const config = ctx.state.controllerConfig;
|
||||
bindingCapture = createControllerBindingCapture({
|
||||
triggerDeadzone: config?.triggerDeadzone ?? 0.5,
|
||||
@@ -275,22 +321,12 @@ export function createControllerSelectModal(
|
||||
? currentBinding.dpadFallback
|
||||
: 'none';
|
||||
bindingCapture.arm(
|
||||
bindingType === 'axis'
|
||||
? {
|
||||
actionId,
|
||||
bindingType: 'axis',
|
||||
dpadFallback: currentDpadFallback,
|
||||
}
|
||||
: {
|
||||
actionId,
|
||||
bindingType: 'discrete',
|
||||
},
|
||||
{ actionId, bindingType: 'axis', dpadFallback: currentDpadFallback },
|
||||
{
|
||||
axes: ctx.state.controllerRawAxes,
|
||||
buttons: ctx.state.controllerRawButtons,
|
||||
},
|
||||
);
|
||||
learningActionId = actionId;
|
||||
controllerConfigForm.render();
|
||||
setStatus(`Waiting for input for ${definition.label}.`);
|
||||
},
|
||||
@@ -307,6 +343,7 @@ export function createControllerSelectModal(
|
||||
const definition = getControllerBindingDefinition(actionId);
|
||||
if (!definition) return;
|
||||
learningActionId = null;
|
||||
discreteLearning = null;
|
||||
cancelScreenLearning();
|
||||
const config = ctx.state.controllerConfig;
|
||||
bindingCapture = createControllerBindingCapture({
|
||||
@@ -564,6 +601,7 @@ export function createControllerSelectModal(
|
||||
learningActionId = null;
|
||||
dpadLearningActionId = null;
|
||||
bindingCapture = null;
|
||||
discreteLearning = null;
|
||||
controllerConfigForm.render();
|
||||
setStatus(`${definition?.label ?? actionId} updated.`);
|
||||
} catch (error) {
|
||||
@@ -592,7 +630,7 @@ export function createControllerSelectModal(
|
||||
|
||||
async function saveDpadFallback(
|
||||
actionId: ControllerBindingKey,
|
||||
dpadFallback: import('../../types').ControllerDpadFallback,
|
||||
dpadFallback: ControllerDpadFallback,
|
||||
): Promise<void> {
|
||||
const definition = getControllerBindingDefinition(actionId);
|
||||
const currentBinding = getSelectedControllerConfig()?.bindings[actionId];
|
||||
@@ -665,25 +703,31 @@ export function createControllerSelectModal(
|
||||
}
|
||||
}
|
||||
|
||||
if (discreteLearning && learningActionId) {
|
||||
const actionId = learningActionId;
|
||||
const combo = pollComboLearning(discreteLearning, (input) =>
|
||||
formatFriendlyInputLabel(
|
||||
input,
|
||||
getSelectedController()?.mapping,
|
||||
getSelectedControllerConfig()?.faceButtonLabels,
|
||||
),
|
||||
);
|
||||
if (combo) {
|
||||
discreteLearning = null;
|
||||
void saveBinding(actionId, combo.hold ? { ...combo.press, hold: combo.hold } : combo.press);
|
||||
}
|
||||
}
|
||||
|
||||
if (screenLearning) {
|
||||
const learning = screenLearning;
|
||||
const state = learning.capture.poll({
|
||||
axes: ctx.state.controllerRawAxes,
|
||||
buttons: ctx.state.controllerRawButtons,
|
||||
});
|
||||
if (state.status === 'holding') {
|
||||
const holdLabel = formatControllerReviewInput(state.hold, getScreenInputContext(), {
|
||||
dpadPrefix: true,
|
||||
});
|
||||
if (holdLabel !== learning.holdLabel) {
|
||||
learning.holdLabel = holdLabel;
|
||||
controllerConfigForm.render();
|
||||
}
|
||||
} else if (state.status === 'done') {
|
||||
const combo = pollComboLearning(learning, (input) =>
|
||||
formatControllerReviewInput(input, getScreenInputContext(), { dpadPrefix: true }),
|
||||
);
|
||||
if (combo) {
|
||||
screenLearning = null;
|
||||
void saveScreenBindings(
|
||||
learning.screen,
|
||||
{ [learning.actionId]: state.binding },
|
||||
{ [learning.actionId]: combo },
|
||||
`${actionLabel(learning.screen, learning.actionId)} updated.`,
|
||||
);
|
||||
}
|
||||
@@ -741,6 +785,7 @@ export function createControllerSelectModal(
|
||||
learningActionId = null;
|
||||
dpadLearningActionId = null;
|
||||
bindingCapture = null;
|
||||
discreteLearning = null;
|
||||
cancelScreenLearning();
|
||||
ctx.state.controllerSelectModalOpen = false;
|
||||
ctx.state.controllerSelectGamepadId = null;
|
||||
@@ -760,6 +805,7 @@ export function createControllerSelectModal(
|
||||
learningActionId = null;
|
||||
dpadLearningActionId = null;
|
||||
bindingCapture = null;
|
||||
discreteLearning = null;
|
||||
cancelScreenLearning();
|
||||
controllerConfigForm.render();
|
||||
setStatus('Controller learn mode cancelled.');
|
||||
|
||||
Reference in new issue
Block a user