forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-save.lua
63 lines (55 loc) · 1.9 KB
/
load-save.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- load a save non-interactively - intended to be run on startup
local gui = require 'gui'
local folder_name = ({...})[1] or qerror("No folder name given")
local loadgame_screen = dfhack.gui.getViewscreenByType(df.viewscreen_loadgamest, 0)
if not loadgame_screen then
local title_screen = dfhack.gui.getViewscreenByType(df.viewscreen_titlest, 0)
if not title_screen then
qerror("Can't find title or load game screen")
end
local found = false
for idx, item in ipairs(title_screen.menu_line_id) do
if item == df.viewscreen_titlest.T_menu_line_id.Continue then
found = true
title_screen.sel_menu_line = idx
break
end
end
if not found then
qerror("Can't find 'Continue Playing' option")
end
gui.simulateInput(title_screen, 'SELECT')
end
loadgame_screen = dfhack.gui.getViewscreenByType(df.viewscreen_loadgamest, 0) or
qerror("Can't find load game screen")
local found = false
for idx, save in ipairs(loadgame_screen.saves) do
if save.folder_name == folder_name then
found = true
loadgame_screen.sel_idx = idx
break
end
end
if not found then
qerror("Can't find save: " .. folder_name)
end
--[[
If gui/load-screen is active, it will be inserted later this frame and prevent
the viewscreen_loadgamest from working. To work around this, SELECT is fed to
the screen one frame later.
]]
function triggerLoad(loadgame_screen)
-- Get rid of child screens (e.g. gui/load-screen)
if loadgame_screen.child then
local child = loadgame_screen.child
while child.child do
child = child.child
end
while child ~= loadgame_screen do
child = child.parent
dfhack.screen.dismiss(child.child)
end
end
gui.simulateInput(loadgame_screen, 'SELECT')
end
dfhack.timeout(1, 'frames', function() triggerLoad(loadgame_screen) end)