40 lines
994 B
Lua
40 lines
994 B
Lua
--@ module = true
|
|
-- 观测模式:把界面焦点变化持续追加到 dfannals-observe.log。
|
|
-- 用途:发现"新建世界 → 进入 legends → 导出"之间的真实界面序列。
|
|
|
|
local repeatUtil = require('repeat-util')
|
|
|
|
local LOG = 'dfannals-observe.log'
|
|
local last = nil
|
|
local ticks = 0
|
|
|
|
local function focus_string()
|
|
local ok, focus = pcall(dfhack.gui.getCurFocus)
|
|
if not ok or not focus then return '?' end
|
|
return table.concat(focus, '/')
|
|
end
|
|
|
|
function tick()
|
|
ticks = ticks + 1
|
|
local fs = focus_string()
|
|
if fs ~= last then
|
|
last = fs
|
|
local f = io.open(LOG, 'a')
|
|
if f then
|
|
f:write(string.format('%s\t%s\n', os.date('%H:%M:%S'), fs))
|
|
f:close()
|
|
end
|
|
end
|
|
end
|
|
|
|
function start()
|
|
repeatUtil.scheduleEvery('dfannals-observe', 10, tick)
|
|
local f = io.open(LOG, 'a')
|
|
if f then
|
|
f:write('--- observe start ' .. os.date('%Y-%m-%d %H:%M:%S') .. '\n')
|
|
f:close()
|
|
end
|
|
end
|
|
|
|
start()
|