--@ module = true -- 把当前界面状态写入 dfannals-probe.txt,供 WSL 侧读取。 -- 用法(在 WSL 里):"Dwarf Fortress.exe" 所在目录的 dfhack-run.exe dfannals/probe local function safe_type(obj) if not obj then return '?' end local ok, t = pcall(function() return obj._type end) if ok and t then return tostring(t) end return '?' end local function viewstack() local out = {} local scr = dfhack.gui.getCurViewscreen() local depth = 0 while scr and depth < 15 do out[#out + 1] = string.format('[%d] %s', depth, safe_type(scr)) local ok, parent = pcall(function() return scr.parent end) if not ok then break end scr = parent depth = depth + 1 end return out end local function world_info() local lines = {} local ok, folder = pcall(dfhack.world.ReadWorldFolder) lines[#lines + 1] = 'world_folder=' .. (ok and tostring(folder) or '?') local ok2, year = pcall(dfhack.world.ReadCurrentYear) lines[#lines + 1] = 'current_year=' .. (ok2 and tostring(year) or '?') local ok3, legends = pcall(dfhack.world.isLegends) lines[#lines + 1] = 'is_legends=' .. (ok3 and tostring(legends) or '?') local ok4, fort = pcall(dfhack.world.isFortressMode) lines[#lines + 1] = 'is_fortress=' .. (ok4 and tostring(fort) or '?') local ok5, name = pcall(function() return dfhack.translation.translateName(df.global.world.world_data.name) end) lines[#lines + 1] = 'world_name=' .. (ok5 and tostring(name) or '?') return lines end function dump() local lines = {} local ok, focus = pcall(dfhack.gui.getCurFocus) lines[#lines + 1] = 'focus=' .. ((ok and focus) and table.concat(focus, '/') or '?') for _, l in ipairs(world_info()) do lines[#lines + 1] = l end lines[#lines + 1] = 'viewstack:' for _, l in ipairs(viewstack()) do lines[#lines + 1] = ' ' .. l end local f = io.open('dfannals-probe.txt', 'w') if f then f:write(table.concat(lines, '\n') .. '\n') f:close() end end dump()