Phase 1: console history, review keys, and wall tones

Game-file footprint unchanged: still one line in main.lua.

Console (Q4: speak everything queued, cancelled by explicit action):
- history.lua keeps our own unbounded history, since the game's console buffer
  expires entries after 3s. Mirrors the game's (xN) coalescing so what is heard
  matches what is on screen. The review cursor holds position while new lines
  arrive rather than being yanked to the tail mid-read.
- patches/console.lua wraps console.print, calling the real one first so a bug
  on our side cannot swallow a message the player would otherwise see.
- Any keypress reaching the game silences the pending speech backlog.

Hotkeys: [ and ] review, Shift+[/] jump to ends, \ repeat, Shift+\ copy.
Chosen from scancodes the game does not bind. Note keybindings.getCommand()
ignores modifiers, so Ctrl+Up would read to the game as a movement -- our keys
are consumed and never overlay a game-claimed scancode.

Wall tones (Q5: on step, 3D-positioned, radius 5):
- Direction and distance are deliberately decoupled. The listener sits at the
  camera 4 units above the plane under an inverse distance model, so placing a
  tone at the wall's real position would make distant walls quieter (the
  opposite of the request) and collapse the stereo pan. Instead the source sits
  at a fixed radius in the wall's direction at listener height, and volume is
  computed explicitly from distance.
- Step detection polls player coordinates rather than hooking movement, so it
  covers walking, pathing, portals and pushes for free.
- Respects FoV/rememberedFoV; never leaks unseen geometry.

tests/test_history.lua: 16 assertions, all passing, pure Lua.

Not yet verified in actual play -- needs a human at the keyboard.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Accessibility Mod
2026-08-01 20:38:28 +02:00
co-authored by Claude Opus 5
parent ff402e64c9
commit fe872be683
7 changed files with 765 additions and 4 deletions
+130
View File
@@ -0,0 +1,130 @@
-- hotkeys.lua — the mod's global key layer.
--
-- Sits in front of states.keypressed. Keys we own are handled and CONSUMED (the
-- game never sees them); everything else falls straight through.
--
-- Consuming matters more than it looks. keybindings.getCommand() dispatches on
-- scancode alone and ignores modifiers, checking held modifiers separately via
-- isCommandDown. So Ctrl+Up is seen by the game as plain "up" — a movement — with
-- moveCamera held. If we bound anything to Ctrl+Up and passed it through, the
-- player would move. Hence: our keys are chosen from scancodes the game does not
-- bind at all, and we still consume them.
--
-- Keys the game claims by default (do not use):
-- . 0-9 ` a b backspace c d delete down e escape f g i j kp1-kp9 kpenter
-- lalt lctrl left lshift mouse3 q r ralt rctrl return right rshift s space
-- t tab up x y z
--
-- Note Ctrl = moveCamera and Shift = repeatAction/adjustByFive are HELD modifiers
-- in game. Combining them with an unbound scancode (e.g. Ctrl+PageUp) is safe,
-- because the game maps the scancode to no command and does nothing.
local speech = require("accessibility.speech")
local history = require("accessibility.history")
local hotkeys = {}
--------------------------------------------------------------------------------
-- Where our keys must stay out of the way
--------------------------------------------------------------------------------
-- States that accept free text. Swallowing "[" while the player is naming a
-- character or typing in the developer console would be a real bug.
local textEntryStates = {
ingame_say = true,
new_game = true,
keybindings_menu = true, -- captures raw keys for rebinding
}
local function isTextEntryState()
local ok, states = pcall(require, "states")
if not ok then
return false
end
return textEntryStates[states.getCurrent()] == true
end
--------------------------------------------------------------------------------
-- Modifier helpers
--------------------------------------------------------------------------------
local function ctrlDown()
return love.keyboard.isScancodeDown("lctrl", "rctrl")
end
local function shiftDown()
return love.keyboard.isScancodeDown("lshift", "rshift")
end
--------------------------------------------------------------------------------
-- Bindings
--
-- Each entry: scancode -> { {mods, action}, ... }, checked in order.
-- mods: "ctrl", "shift", or nil for "no modifier required".
--------------------------------------------------------------------------------
local bindings = {}
local function bind(scancode, mods, action)
bindings[scancode] = bindings[scancode] or {}
table.insert(bindings[scancode], {mods = mods, action = action})
end
-- Console review
bind("[", nil, history.reviewPrevious)
bind("]", nil, history.reviewNext)
bind("[", "shift", history.reviewFirst)
bind("]", "shift", history.reviewLast)
bind("\\", nil, history.repeatCurrent)
bind("\\", "shift", history.copyCurrent)
function hotkeys.bind(scancode, mods, action)
bind(scancode, mods, action)
end
local function matches(entry)
if entry.mods == "ctrl" then
return ctrlDown()
elseif entry.mods == "shift" then
return shiftDown()
end
-- No modifier required: reject if one is held, so Shift+[ doesn't also fire [.
return not ctrlDown() and not shiftDown()
end
--------------------------------------------------------------------------------
-- Dispatch
--------------------------------------------------------------------------------
-- Returns true if the key was ours and should NOT reach the game.
function hotkeys.keypressed(_key, scancode)
if isTextEntryState() then
return false
end
local candidates = bindings[scancode]
if not candidates then
return false
end
for _, entry in ipairs(candidates) do
if matches(entry) then
local ok, err = pcall(entry.action)
if not ok then
print("[accessibility] hotkey '" .. tostring(scancode) .. "' error: " .. tostring(err))
end
return true
end
end
return false
end
-- Any key that reaches the game is an explicit player action, so it cancels the
-- pending speech backlog. Whatever that action produces is then spoken fresh.
-- This is the "speak everything queued, unless explicitly stopped" policy.
function hotkeys.onGameKey()
speech.silence()
end
return hotkeys