Game-file footprint unchanged: still one line in main.lua.
Wall tones: stop the previous tone per direction before playing the new one.
The tones are 2.33s mono; steps land far faster than that and up to four
directions sound at once, so overlapping them stacked into a continuous drone
instead of reading as a per-step cue. Cutting the old tone also means the
distance/volume you hear always reflects where you are standing now.
ingame_dialogue descriptor: speaks speaker and message on a node change, but
only the response on a selection change -- re-reading the whole speech every
time you move between responses would be unusable.
Two more bugs found by the testbed:
4. Nested states.switch announced in reverse. ingame.open() sees
world.pendingDialogue and switches straight to ingame_dialogue; because we
announce after realSwitch returns, the inner announcement fired first and the
outer one interrupted and clobbered it, so entering a conversation said
'Game' rather than 'Conversation'. Now we stay quiet if we are no longer the
current state.
5. The game already numbers response text ('1. (Continue)'), matching the number
key that picks it, so our own numbering produced '1. 1. (Continue)'.
9/9 testbed checks, history unit tests passing.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
260 lines
7.3 KiB
Lua
260 lines
7.3 KiB
Lua
-- testbed.lua — drives the game by code so mod behaviour can be verified without
|
|
-- a human at the keyboard.
|
|
--
|
|
-- Enable with: lovec.exe . --a11y-test
|
|
--
|
|
-- Key events go through love.event.push, so input travels the exact same path as
|
|
-- a human keypress (love.keypressed -> states.keypressed -> our wrapper -> the
|
|
-- game's handler). Nothing is stubbed.
|
|
--
|
|
-- The scenario is a coroutine: it yields to wait for frames, so it can *read* the
|
|
-- game's actual focus and navigate accordingly rather than counting keypresses
|
|
-- blind. Blind counting drifts the moment an option is disabled or a screen
|
|
-- inserts itself.
|
|
|
|
local menus = require("accessibility.menus")
|
|
|
|
local testbed = {}
|
|
|
|
local co
|
|
local waitFrames = 0
|
|
local finished = false
|
|
local failures = 0
|
|
local checks = 0
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Primitives (called from inside the scenario coroutine)
|
|
--------------------------------------------------------------------------------
|
|
|
|
local function wait(frames)
|
|
for _ = 1, frames or 1 do
|
|
coroutine.yield()
|
|
end
|
|
end
|
|
|
|
local function currentState()
|
|
local ok, states = pcall(require, "states")
|
|
if not ok then
|
|
return "?"
|
|
end
|
|
return states.getCurrent()
|
|
end
|
|
|
|
local function focusText()
|
|
local ok, text = pcall(menus.readFocus, currentState())
|
|
if not ok then
|
|
return nil
|
|
end
|
|
return text
|
|
end
|
|
|
|
-- Presses a key and waits long enough for the event to be pumped, handled, and
|
|
-- for our end-of-frame speech flush to run.
|
|
local function press(scancode, note)
|
|
local before = focusText()
|
|
print(string.format("[testbed] (%s) press %-8s focus_before=%s %s",
|
|
currentState(), scancode, before and ('"' .. before .. '"') or "nil", note or ""))
|
|
|
|
love.event.push("keypressed", scancode, scancode, false)
|
|
love.event.push("keyreleased", scancode, scancode)
|
|
|
|
wait(6)
|
|
|
|
local after = focusText()
|
|
print(string.format("[testbed] -> state=%s focus_after=%s",
|
|
currentState(), after and ('"' .. after .. '"') or "nil"))
|
|
end
|
|
|
|
local function typeText(text)
|
|
print(string.format("[testbed] (%s) type %q", currentState(), text))
|
|
for char in text:gmatch(".") do
|
|
love.event.push("textinput", char)
|
|
wait(3)
|
|
end
|
|
wait(3)
|
|
end
|
|
|
|
local function check(label, condition, detail)
|
|
checks = checks + 1
|
|
if not condition then
|
|
failures = failures + 1
|
|
end
|
|
print(string.format("[testbed] %s %s%s",
|
|
condition and "PASS" or "FAIL", label, detail and (" -- " .. detail) or ""))
|
|
end
|
|
|
|
local function waitForState(stateName, maxFrames)
|
|
local waited = 0
|
|
while currentState() ~= stateName and waited < (maxFrames or 300) do
|
|
wait(1)
|
|
waited = waited + 1
|
|
end
|
|
return currentState() == stateName
|
|
end
|
|
|
|
-- Navigate a list menu to the option whose spoken text matches `pattern`, by
|
|
-- pressing down and reading focus each time. Robust to disabled options and to
|
|
-- the list changing length between versions.
|
|
local function selectByText(pattern, maxSteps)
|
|
for _ = 1, maxSteps or 15 do
|
|
local text = focusText()
|
|
if text and text:lower():find(pattern:lower(), 1, true) then
|
|
return true
|
|
end
|
|
press("down", "searching for '" .. pattern .. "'")
|
|
end
|
|
return false
|
|
end
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- The scenario
|
|
--------------------------------------------------------------------------------
|
|
|
|
local function scenario()
|
|
wait(30) -- let the main menu settle
|
|
|
|
check("reached main menu", currentState() == "main_menu", "got " .. currentState())
|
|
|
|
-- Regression guard for the bug where love.keypressed was still bound to the
|
|
-- pre-wrapper states.keypressed, so arrow keys announced nothing.
|
|
local before = focusText()
|
|
press("down", "first arrow key after startup")
|
|
local after = focusText()
|
|
check("first arrow key changes focus", before ~= after,
|
|
string.format("before=%s after=%s", tostring(before), tostring(after)))
|
|
|
|
press("up", "back up")
|
|
|
|
check("found New game", selectByText("New game"), "menu navigation by text")
|
|
press("return", "confirm New game")
|
|
|
|
check("reached new_game", waitForState("new_game"), "got " .. currentState())
|
|
|
|
typeText("Tester")
|
|
local nameFocus = focusText()
|
|
check("name field reads back typed text",
|
|
nameFocus ~= nil and nameFocus:find("Tester") ~= nil,
|
|
"focus=" .. tostring(nameFocus))
|
|
|
|
press("return", "confirm name")
|
|
wait(30)
|
|
|
|
-- Intro sequence: narration / dialogue / message screens vary, so just advance
|
|
-- until we land in gameplay.
|
|
local sawDialogue = false
|
|
local dialogueText
|
|
|
|
for i = 1, 20 do
|
|
if currentState() == "ingame" then
|
|
break
|
|
end
|
|
if currentState() == "ingame_dialogue" and not sawDialogue then
|
|
sawDialogue = true
|
|
dialogueText = focusText()
|
|
-- Exercise response navigation before advancing.
|
|
press("down", "dialogue: next response")
|
|
press("up", "dialogue: previous response")
|
|
end
|
|
press("return", "advancing intro (" .. currentState() .. ") " .. i)
|
|
wait(10)
|
|
end
|
|
|
|
check("dialogue was described", sawDialogue and dialogueText ~= nil,
|
|
"text=" .. tostring(dialogueText))
|
|
|
|
check("reached gameplay", currentState() == "ingame", "got " .. currentState())
|
|
|
|
if currentState() == "ingame" then
|
|
-- Movement drives console messages and wall tones.
|
|
press("right", "move east")
|
|
press("right", "move east")
|
|
press("down", "move south")
|
|
press("left", "move west")
|
|
press("up", "move north")
|
|
|
|
-- Try a wider set of directions: the start position may be walled in, and a
|
|
-- blocked move produces no console output.
|
|
for _, dir in ipairs({"up", "left", "down", "right", "up", "right", "down", "left"}) do
|
|
press(dir, "probing movement")
|
|
end
|
|
|
|
-- Direct smoke test of the console.print patch.
|
|
--
|
|
-- Plain movement is silent in this game (actions/move.lua only prints when
|
|
-- the move FAILS -- bound, immobilized), so walking around proves nothing
|
|
-- about the wrapper. Drive console.print itself instead.
|
|
local history = require("accessibility.history")
|
|
local console = require("modules.console")
|
|
local baseline = history.count()
|
|
|
|
console.print("Accessibility smoke test message.")
|
|
wait(3)
|
|
check("console.print reaches history", history.count() == baseline + 1,
|
|
"count " .. baseline .. " -> " .. history.count())
|
|
|
|
-- The game folds a repeated identical message into "(x2)"; we must match.
|
|
console.print("Accessibility smoke test message.")
|
|
wait(3)
|
|
check("repeat folds instead of appending", history.count() == baseline + 1,
|
|
"count = " .. history.count())
|
|
|
|
-- Console review keys.
|
|
press("[", "review previous")
|
|
press("]", "review next")
|
|
press("\\", "repeat current")
|
|
end
|
|
|
|
print(string.format("[testbed] === %d checks, %d failures ===", checks, failures))
|
|
end
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Driver
|
|
--------------------------------------------------------------------------------
|
|
|
|
function testbed.start()
|
|
co = coroutine.create(scenario)
|
|
print("[testbed] starting scenario")
|
|
end
|
|
|
|
function testbed.update()
|
|
if finished or not co then
|
|
return
|
|
end
|
|
|
|
if waitFrames > 0 then
|
|
waitFrames = waitFrames - 1
|
|
return
|
|
end
|
|
|
|
local ok, err = coroutine.resume(co)
|
|
|
|
if not ok then
|
|
print("[testbed] scenario ERROR: " .. tostring(err))
|
|
finished = true
|
|
love.event.quit()
|
|
return
|
|
end
|
|
|
|
if coroutine.status(co) == "dead" then
|
|
finished = true
|
|
print("[testbed] scenario complete, quitting")
|
|
love.event.quit()
|
|
end
|
|
end
|
|
|
|
function testbed.isEnabled()
|
|
if not arg then
|
|
return false
|
|
end
|
|
|
|
for _, value in ipairs(arg) do
|
|
if value == "--a11y-test" then
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
return testbed
|