-
Notifications
You must be signed in to change notification settings - Fork 2
/
diseasedesc_stats.lua
256 lines (207 loc) · 8.47 KB
/
diseasedesc_stats.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
--
-- Please see the LICENSE.md file included with this distribution for attribution and copyright information.
--
function onInit()
update()
end
-- This function takes the Save DC related information and combines them into a single string that can be displayed once the window is locked.
function generateOnsetString()
local sOnset = ''
if onset_unit.getValue() ~= '' then sOnset = onset_interval.getValue() end
if onset_unit.getValue() ~= '' then sOnset = sOnset .. ' ' .. onset_unit.getValue() else sOnset = '' end
return sOnset
end
-- This function takes the Save DC related information and combines them into a single string that can be displayed once the window is locked.
function generateDurationString()
local sDur = ''
if duration_unit.getValue() ~= '' then sDur = duration_interval.getValue() end
if duration_unit.getValue() ~= '' then sDur = sDur .. ' ' .. duration_unit.getValue() else sDur = '' end
return sDur
end
--- This function rounds nNum to nDecimalPlaces (or to a whole number)
function round(nNum, nDecimalPlaces)
if not nNum then return 0; end
local nMult = 10^(nDecimalPlaces or 0)
return math.floor(nNum * nMult + 0.5) / nMult
end
-- This function takes the Save DC related information and combines them into a single string that can be displayed once the window is locked.
function generateFrequencyString()
local sFreq = ''
if freq_unit.getValue() ~= '' then sFreq = round(freq_interval.getValue(), 1) end
if freq_unit.getValue() ~= '' then sFreq = sFreq .. freq_unit.getValue() else sFreq = '' end
return sFreq
end
-- This function takes the Save DC related information and combines them into a single string that can be displayed once the window is locked.
function generateSaveString()
local sSave = ''
local nSaveDc = savedc.getValue()
local sSaveType = savetype.getValue()
if nSaveDc ~= 0 then sSave = 'DC ' .. nSaveDc end
if sSaveType ~= '' then sSave = sSave .. ' ' .. sSaveType end
local sFreq = generateFrequencyString()
if sSave == '' then sSave = sFreq elseif sFreq ~= '' then sSave = sSave .. ' ' .. sFreq end
local sDur = generateDurationString()
if sSave == '' then sSave = sDur elseif duration_interval.getValue() > 0 then sSave = sSave .. ' ' .. Interface.getString("disease_savestring_for") .. ' ' .. sDur end
local sOnset = generateOnsetString()
if sSave ~= '' and onset_interval.getValue() > 0 then sSave = sSave .. ' ' .. Interface.getString("disease_savestring_after") .. ' ' .. sOnset end
if sSave == '' then sSave = Interface.getString("disease_savestring_none") end
save_string.setValue(sSave)
end
-- This function sets the visibility and editability of various fields on the malady sheet when it is unlocked.
function ifLocked(sType)
local sSubtype = ''
if subtype.getValue() and subtype.getValue() ~= '' then
sSubtype = ' (' .. subtype.getValue() .. ')'
end
type_biglabel.setValue('[' .. type.getValue() .. sSubtype .. ']')
generateSaveString()
save_string.setVisible(true)
savetype.setVisible(false)
savedc_label.setVisible(false)
savedc.setVisible(false)
associated_npc_name.setVisible(false)
associated_npc_name_label.setVisible(false)
if getDatabaseNode().getParent().getName() ~= 'disease'
and getDatabaseNode().getChild('...').getName() ~= 'reference' then
saveroll.setVisible(true)
else
saveroll.setVisible(false)
end
duration_label.setVisible(false)
duration_interval.setVisible(false)
duration_unit.setVisible(false)
duration_dice.setVisible(false)
if sType ~= 'disease' then
if poison_effect_primary.getValue() == '' then
poison_effect_primary.setVisible(true)
poison_effect_primary_label.setVisible(true)
end
if poison_effect_secondary.getValue() == '' then
poison_effect_secondary.setVisible(true)
poison_effect_secondary_label.setVisible(true)
end
else
raisesave.setVisible(false)
increaseduration.setVisible(false)
disease_effect.setVisible(true)
poison_effect_primary.setVisible(false)
poison_effect_primary_label.setVisible(false)
poison_effect_secondary.setVisible(false)
poison_effect_secondary_label.setVisible(false)
end
if sType == 'poison' then
disease_effect.setVisible(false)
if save_string.getValue() and save_string.getValue() ~= 'none'
and getDatabaseNode().getParent().getName() ~= 'disease'
and getDatabaseNode().getChild('...').getName() ~= 'reference' then
raisesave.setVisible(true)
else
raisesave.setVisible(false)
end
if duration_interval.getValue() and duration_interval.getValue() > 0 and getDatabaseNode().getParent().getName() ~= 'disease' and getDatabaseNode().getChild('...').getName() ~= 'reference' then
increaseduration.setVisible(true)
else
increaseduration.setVisible(false)
end
end
if disease_effect.getValue() == '\n<p></p>' and poison_effect_primary.getValue() == '' and poison_effect_primary.getValue() == '' then
section_effect_label.setVisible(false)
end
if description.getValue() == '\n<p></p>' then section_description_label.setVisible(false) end
onset_label.setVisible(false)
onset_unit.setVisible(false)
onset_dice.setVisible(false)
onset_interval.setVisible(false)
button_settime.setVisible(false)
freq_label.setVisible(false)
freq_unit.setVisible(false)
freq_dice.setVisible(false)
freq_interval.setVisible(false)
type_biglabel.setVisible(true)
type.setVisible(false)
type_label.setVisible(false)
subtype.setVisible(false)
subtype_label.setVisible(false)
if savesreq.getValue() ~= 0 then
savecount_seperator.setVisible(true)
isconsecutive.setVisible(true)
else
savecount_seperator.setVisible(false)
isconsecutive.setVisible(false)
end
end
-- This function sets the visibility and editability of various fields on the malady sheet when it is locked.
function ifUnlocked(sType)
save_string.setVisible(false)
savetype.setVisible(true)
savedc_label.setVisible(true)
savedc.setVisible(true)
saveroll.setVisible(false)
associated_npc_name.setVisible(true)
associated_npc_name_label.setVisible(true)
raisesave.setVisible(false)
increaseduration.setVisible(false)
duration_label.setVisible(true)
duration_interval.setVisible(true)
duration_unit.setVisible(true)
if sType ~= 'disease' then
if getDatabaseNode().getParent().getName() == 'disease' or getDatabaseNode().getChild('...').getName() == 'reference' then
duration_dice.setVisible(true)
else
duration_dice.setVisible(false)
end
poison_effect_primary.setVisible(true)
poison_effect_primary_label.setVisible(true)
poison_effect_secondary.setVisible(true)
poison_effect_secondary_label.setVisible(true)
else
duration_dice.setVisible(false)
disease_effect.setVisible(true)
poison_effect_primary.setVisible(false)
poison_effect_primary_label.setVisible(false)
poison_effect_secondary.setVisible(false)
poison_effect_secondary_label.setVisible(false)
end
if sType == 'poison' then disease_effect.setVisible(false) end
if sType ~= 'poison' then disease_effect.setVisible(true) end
section_effect_label.setVisible(true)
section_description_label.setVisible(true)
onset_label.setVisible(true)
onset_unit.setVisible(true)
onset_interval.setVisible(true)
if getDatabaseNode().getParent().getName() == 'disease' or getDatabaseNode().getChild('...').getName() == 'reference' then
onset_dice.setVisible(true)
else
onset_dice.setVisible(false)
end
button_settime.setVisible(false)
if TimeManager_Disabled and getDatabaseNode().getParent().getName() ~= 'disease' and getDatabaseNode().getChild('...').getName() ~= 'reference' then
button_settime.setVisible(true)
end
freq_label.setVisible(true)
freq_unit.setVisible(true)
freq_interval.setVisible(true)
if getDatabaseNode().getParent().getName() == 'disease' or getDatabaseNode().getChild('...').getName() == 'reference' then
freq_dice.setVisible(true)
else
freq_dice.setVisible(false)
end
type_biglabel.setVisible(false)
type.setVisible(true)
type_label.setVisible(true)
subtype.setVisible(true)
subtype_label.setVisible(true)
savecount_seperator.setVisible(true)
isconsecutive.setVisible(true)
end
function update()
local bReadOnly = WindowManager.getReadOnlyState(getDatabaseNode())
local sType = string.lower(type.getValue())
if bReadOnly then ifLocked(sType) else ifUnlocked(sType) end
savesreq.update(bReadOnly, bForceHide, 'cure_label')
savecount_consec.update(false, bForceHide, 'cure_label', savesreq)
if sType ~= 'poison' then disease_effect.update(bReadOnly) end
if sType ~= 'disease' then poison_effect_primary.update(bReadOnly) end
if sType ~= 'disease' then poison_effect_secondary.update(bReadOnly) end
description.update(bReadOnly)
end