Files
alchemist-accessibility/accessibility/patches/console.lua
T

47 lines
1.4 KiB
Lua
Raw Normal View History

-- Patch: modules/console.lua
--
-- console.print is the single chokepoint for every log message the game produces
-- (combat, interaction, flavour, status). Wrapping it captures all of them.
--
-- The wrapper must return the original's results verbatim and must not alter what
-- the game draws.
local history = require("accessibility.history")
local speech = require("accessibility.speech")
return function()
local console = require("modules.console")
local realPrint = console.print
if not realPrint then
error("modules.console has no print function -- game structure changed")
end
console.print = function(message, colorTemplate)
-- Game first, so a bug on our side cannot swallow a message the player
-- would otherwise see on screen.
local result = realPrint(message, colorTemplate)
pcall(function()
local text = history.append(message, colorTemplate)
if text then
-- Queued, not interrupting: several messages can land in one turn
-- and speech.flush joins them in order at end of frame.
speech.say(text, false)
end
end)
return result
end
-- console.clear is called on new game / level reset. Keep our history aligned
-- so review doesn't read back messages from a previous playthrough.
local realClear = console.clear
if realClear then
console.clear = function(...)
pcall(history.clear)
return realClear(...)
end
end
end