|
| 1 | +/* |
| 2 | +Toolbox Aid |
| 3 | +David Quesenberry |
| 4 | +04/16/2026 |
| 5 | +Phase17OverlayInputEdgeCases.test.mjs |
| 6 | +*/ |
| 7 | +import assert from 'node:assert/strict'; |
| 8 | +import { |
| 9 | + getOverlayRuntimeCycleInputCodes, |
| 10 | + getOverlayRuntimeToggleInputCodes, |
| 11 | +} from '../../samples/phase-17/shared/overlayCycleInput.js'; |
| 12 | +import { |
| 13 | + createOverlayGameplayRuntime, |
| 14 | + getOverlayGameplayRuntimeInteractionSnapshot, |
| 15 | + stepOverlayGameplayRuntimeControls, |
| 16 | +} from '../../samples/phase-17/shared/overlayGameplayRuntime.js'; |
| 17 | + |
| 18 | +function makeInput(keys = []) { |
| 19 | + const down = new Set(keys); |
| 20 | + return { |
| 21 | + isDown(code) { |
| 22 | + return down.has(code); |
| 23 | + }, |
| 24 | + }; |
| 25 | +} |
| 26 | + |
| 27 | +function stepControls(runtime, keys = [], dtSeconds = 0.02) { |
| 28 | + return stepOverlayGameplayRuntimeControls(runtime, makeInput(keys), { dtSeconds }); |
| 29 | +} |
| 30 | + |
| 31 | +function assertInputFloodAndStuckStateHandling() { |
| 32 | + const runtime = createOverlayGameplayRuntime({ |
| 33 | + runtimeExtensions: [ |
| 34 | + { onStep() {} }, |
| 35 | + { onStep() {} }, |
| 36 | + { onStep() {} }, |
| 37 | + ], |
| 38 | + }); |
| 39 | + |
| 40 | + const runtimeCycleKeys = getOverlayRuntimeCycleInputCodes(); |
| 41 | + const runtimeToggleKeys = getOverlayRuntimeToggleInputCodes(); |
| 42 | + |
| 43 | + const firstCycle = stepControls(runtime, runtimeCycleKeys, 0.02); |
| 44 | + assert.equal(firstCycle, true, 'First explicit runtime cycle action should trigger.'); |
| 45 | + assert.equal(runtime.interactionIndex, 1, 'First runtime cycle action should advance index once.'); |
| 46 | + |
| 47 | + stepControls(runtime, [], 0.005); |
| 48 | + const immediateCycleAfterAction = stepControls(runtime, runtimeCycleKeys, 0.005); |
| 49 | + assert.equal(immediateCycleAfterAction, false, 'Cooldown should prevent immediate re-trigger after action jitter.'); |
| 50 | + |
| 51 | + for (let i = 0; i < 40; i += 1) { |
| 52 | + const cycled = stepControls(runtime, runtimeCycleKeys, 0.01); |
| 53 | + assert.equal(cycled, false, 'Held runtime cycle input should not flood repeated actions.'); |
| 54 | + } |
| 55 | + assert.equal(runtime.interactionIndex, 1, 'Held runtime cycle input should keep index stable.'); |
| 56 | + |
| 57 | + stepControls(runtime, [], 0.02); |
| 58 | + const cycleAfterRelease = stepControls(runtime, runtimeCycleKeys, 0.02); |
| 59 | + assert.equal(cycleAfterRelease, true, 'Cycle should resume after release once cooldown has elapsed.'); |
| 60 | + assert.equal(runtime.interactionIndex, 2, 'Cycle after release should advance index once.'); |
| 61 | + |
| 62 | + stepControls(runtime, [], 0.05); |
| 63 | + const firstToggle = stepControls(runtime, runtimeToggleKeys, 0.02); |
| 64 | + assert.equal(firstToggle, true, 'First explicit runtime toggle should trigger.'); |
| 65 | + assert.equal(runtime.interactionVisible, false, 'First runtime toggle should hide overlay runtime.'); |
| 66 | + |
| 67 | + let repeatedToggleCount = 0; |
| 68 | + for (let i = 0; i < 120; i += 1) { |
| 69 | + if (stepControls(runtime, runtimeToggleKeys, 0.02)) { |
| 70 | + repeatedToggleCount += 1; |
| 71 | + } |
| 72 | + } |
| 73 | + assert.equal(repeatedToggleCount, 0, 'Held toggle input should not repeatedly fire and flood actions.'); |
| 74 | + assert.equal(runtime.interactionVisible, false, 'Held toggle input should keep visibility stable.'); |
| 75 | + |
| 76 | + const snapshotBeforeRelease = getOverlayGameplayRuntimeInteractionSnapshot(runtime); |
| 77 | + assert.equal(snapshotBeforeRelease.suppressUntilRelease, true, 'Long held explicit input should enter suppress-until-release mode.'); |
| 78 | + |
| 79 | + stepControls(runtime, [], 0.02); |
| 80 | + const toggleAfterRelease = stepControls(runtime, runtimeToggleKeys, 0.02); |
| 81 | + assert.equal(toggleAfterRelease, true, 'Released stuck input should recover and allow next explicit action.'); |
| 82 | + assert.equal(runtime.interactionVisible, true, 'Recovered toggle action should restore visibility.'); |
| 83 | +} |
| 84 | + |
| 85 | +export function run() { |
| 86 | + assertInputFloodAndStuckStateHandling(); |
| 87 | +} |
0 commit comments