-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathprerelease-warning.lua
161 lines (136 loc) · 4.76 KB
/
prerelease-warning.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
-- Shows the warning about missing configuration file.
--[====[
gui/prerelease-warning
======================
Shows a warning on world load for pre-release builds.
With no arguments passed, the warning is shown unless the "do not show again"
option has been selected. With the ``force`` argument, the warning is always
shown.
]====]
local gui = require 'gui'
local dlg = require 'gui.dialogs'
local json = require 'json'
local utils = require 'utils'
local force = ({...})[1] == 'force'
local config = json.open('dfhack-config/prerelease-warning.json')
if config.data.hide and not force then
return
end
if not dfhack.isPrerelease() and not force then
qerror('not a prerelease build')
end
-- Don't fire during worldgen
if dfhack.internal.getAddress('gametype') and df.global.gametype == df.game_type.NONE and not force then
return
end
local state = dfhack.getDFHackRelease():lower():match('[a-z]+')
if not utils.invert{'alpha', 'beta', 'rc', 'r'}[state] then
dfhack.printerr('warning: unknown release state: ' .. state)
state = 'unknown'
end
message = ({
alpha = {
'Warning',
COLOR_YELLOW,
'This is an alpha build of DFHack. Some structures are likely', NEWLINE,
'to be incorrect, resulting in crashes or save corruption', NEWLINE,
{pen=COLOR_LIGHTRED, text='Make backups of your saves often!'}
},
beta = {
'Warning',
COLOR_YELLOW,
'This is a beta release of DFHack. It is more stable than an', NEWLINE,
'alpha release, but bugs are still possible, possibly including', NEWLINE,
'crashes and save corruption.', NEWLINE,
'Make backups of your saves beforehand to be safe.'
},
rc = {
'Notice',
COLOR_YELLOW,
'This is a DFHack release candidate. It is fairly stable but', NEWLINE,
'likely contains newer features that are not fully-tested.', NEWLINE,
'Crashes are unlikely, but always make backups of your saves', NEWLINE,
'to be safe.'
},
r = {
'Error',
COLOR_LIGHTRED,
'This release is flagged as a prerelease but named as a', NEWLINE,
'stable release.', NEWLINE,
{pen=COLOR_LIGHTMAGENTA, text='Please report this to the DFHack team or a pack maintainer.'}
},
unknown = {
'Error',
COLOR_LIGHTMAGENTA,
'Unknown prerelease DFHack build. This should never happen!', NEWLINE,
'Please report this to the DFHack team or a pack maintainer.'
}
})[state]
title = table.remove(message, 1)
color = table.remove(message, 1)
pack_message = [[
This should not be enabled by default in a pack.
If you are seeing this message and did not enable/install DFHack
yourself, please report this to your pack's maintainer.]]
path = dfhack.getHackPath():lower()
if #pack_message > 0 and (path:find('lnp') or path:find('starter') or path:find('newb') or path:find('lazy') or path:find('pack')) then
for _, v in pairs(utils.split_string(pack_message, '\n')) do
table.insert(message, NEWLINE)
table.insert(message, {text=v, pen=COLOR_LIGHTMAGENTA})
end
end
for _, v in pairs(utils.split_string([[
REMINDER: Please report any issues you encounter while
using this DFHack build on GitHub (github.com/dfhack/dfhack/issues)
or the Bay12 forums (dfhack.org/bay12).]], '\n')) do
table.insert(message, NEWLINE)
table.insert(message, {text=v, pen=COLOR_LIGHTCYAN})
end
nightly_message = [[
You appear to be using a nightly build of DFHack. If you
experience problems, check dfhack.org/builds for updates.]]
if dfhack.getDFHackBuildID() ~= '' then
for _, v in pairs(utils.split_string(nightly_message, '\n')) do
table.insert(message, NEWLINE)
table.insert(message, {text=v, pen=COLOR_LIGHTGREEN})
end
end
dfhack.print('\n')
for k,v in ipairs(message) do
if type(v) == 'table' then
dfhack.color(v.pen)
dfhack.print(v.text)
else
dfhack.color(color)
dfhack.print(v)
end
end
dfhack.color(COLOR_RESET)
dfhack.print('\n\n')
WarningBox = defclass(nil, dlg.MessageBox)
function WarningBox:getWantedFrameSize()
local w, h = WarningBox.super.getWantedFrameSize(self)
return w, h + 2
end
function WarningBox:onRenderFrame(dc,rect)
WarningBox.super.onRenderFrame(self,dc,rect)
dc:pen(COLOR_WHITE):key_pen(COLOR_LIGHTRED)
:seek(rect.x1 + 2, rect.y2 - 2)
:key('CUSTOM_D'):string(': Do not show again')
:advance(10)
:key('LEAVESCREEN'):string('/')
:key('SELECT'):string(': Dismiss')
end
function WarningBox:onInput(keys)
if keys.CUSTOM_D then
config.data.hide = true
config:write()
keys.LEAVESCREEN = true
end
WarningBox.super.onInput(self, keys)
end
WarningBox{
frame_title = title,
text = message,
text_pen = color
}:show()