forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quicksave.lua
57 lines (44 loc) · 1.25 KB
/
quicksave.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
-- Makes the game immediately save the state.
--[====[
quicksave
=========
If called in dwarf mode, makes DF immediately saves the game by setting a flag
normally used in seasonal auto-save.
]====]
local gui = require("gui")
--luacheck: defclass={run:bool}
QuicksaveOverlay = defclass(QuicksaveOverlay, gui.Screen)
function QuicksaveOverlay:render()
if not self.run then
self.run = true
save()
self:renderParent()
self:dismiss()
end
end
if not dfhack.isMapLoaded() then
qerror("World and map aren't loaded.")
end
if not dfhack.world.isFortressMode() then
qerror('This script can only be used in fortress mode')
end
local ui_main = df.global.ui.main
local flags4 = df.global.d_init.flags4
local function restore_autobackup()
if ui_main.autosave_request and dfhack.isMapLoaded() then
dfhack.timeout(10, 'frames', restore_autobackup)
else
flags4.AUTOBACKUP = true
end
end
function save()
-- Request auto-save
ui_main.autosave_request = true
-- And since it will overwrite the backup, disable it temporarily
if flags4.AUTOBACKUP then
flags4.AUTOBACKUP = false
restore_autobackup()
end
print 'The game should save the state now.'
end
QuicksaveOverlay():show()