@@ -24,159 +24,118 @@ local function modname_valid(name)
24
24
end
25
25
26
26
local function get_formspec (data )
27
- local mod = data .list :get_list ()[data .selected_mod ]
27
+ local mod = data .list :get_list ()[data .selected_mod ] or { name = " " }
28
28
29
29
local retval =
30
30
" size[11.5,7.5,true]" ..
31
31
" label[0.5,0;" .. fgettext (" World:" ) .. " ]" ..
32
32
" label[1.75,0;" .. data .worldspec .name .. " ]"
33
33
34
- if mod == nil then
35
- mod = {name = " " }
36
- end
37
-
38
34
local hard_deps , soft_deps = pkgmgr .get_dependencies (mod .path )
39
35
40
36
retval = retval ..
41
37
" label[0,0.7;" .. fgettext (" Mod:" ) .. " ]" ..
42
38
" label[0.75,0.7;" .. mod .name .. " ]" ..
43
39
" label[0,1.25;" .. fgettext (" Dependencies:" ) .. " ]" ..
44
- " textlist[0,1.75;5,2.125;world_config_depends;" ..
45
- hard_deps .. " ;0]" ..
40
+ " textlist[0,1.75;5,2.125;world_config_depends;" .. hard_deps .. " ;0]" ..
46
41
" label[0,3.875;" .. fgettext (" Optional dependencies:" ) .. " ]" ..
47
42
" textlist[0,4.375;5,1.8;world_config_optdepends;" ..
48
43
soft_deps .. " ;0]" ..
49
- " button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext (" Save" ) .. " ]" ..
50
- " button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext (" Cancel" ) .. " ]"
44
+ " button[3.25,7;2.5,0.5;btn_config_world_save;" ..
45
+ fgettext (" Save" ) .. " ]" ..
46
+ " button[5.75,7;2.5,0.5;btn_config_world_cancel;" ..
47
+ fgettext (" Cancel" ) .. " ]"
51
48
52
- if mod and mod .name ~= " " and not mod .is_game_content then
49
+ if mod .name ~= " " and not mod .is_game_content then
53
50
if mod .is_modpack then
54
- local rawlist = data .list :get_raw_list ()
55
-
56
- local all_enabled = true
57
- for j = 1 , # rawlist , 1 do
58
- if rawlist [j ].modpack == mod .name and not rawlist [j ].enabled then
59
- all_enabled = false
60
- break
61
- end
62
- end
63
51
64
- if all_enabled then
65
- retval = retval .. " button[5.5,0.125;2.5,0.5;btn_mp_disable;" ..
52
+ if pkgmgr .is_modpack_entirely_enabled (data , mod .name ) then
53
+ retval = retval ..
54
+ " button[5.5,0.125;2.5,0.5;btn_mp_disable;" ..
66
55
fgettext (" Disable MP" ) .. " ]"
67
56
else
68
- retval = retval .. " button[5.5,0.125;2.5,0.5;btn_mp_enable;" ..
57
+ retval = retval ..
58
+ " button[5.5,0.125;2.5,0.5;btn_mp_enable;" ..
69
59
fgettext (" Enable MP" ) .. " ]"
70
60
end
71
61
else
72
- if mod .enabled then
73
- retval = retval .. " checkbox[5.5,-0.125;cb_mod_enable;" ..
74
- fgettext (" enabled" ) .. " ;true]"
75
- else
76
- retval = retval .. " checkbox[5.5,-0.125;cb_mod_enable;" ..
77
- fgettext (" enabled" ) .. " ;false]"
78
- end
62
+ retval = retval ..
63
+ " checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext (" enabled" ) ..
64
+ " ;" .. tostring (mod .enabled ) .. " ]"
79
65
end
80
66
end
81
67
if enabled_all then
82
68
retval = retval ..
83
- " button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext (" Disable all" ) .. " ]"
69
+ " button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" ..
70
+ fgettext (" Disable all" ) .. " ]"
84
71
else
85
72
retval = retval ..
86
- " button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext (" Enable all" ) .. " ]"
73
+ " button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" ..
74
+ fgettext (" Enable all" ) .. " ]"
87
75
end
88
- retval = retval ..
76
+ return retval ..
89
77
" tablecolumns[color;tree;text]" ..
90
- " table[5.5,0.75;5.75,6;world_config_modlist;"
91
- retval = retval .. pkgmgr .render_packagelist (data .list )
92
- retval = retval .. " ;" .. data .selected_mod .. " ]"
93
-
94
- return retval
95
- end
96
-
97
- local function enable_mod (this , toset )
98
- local mod = this .data .list :get_list ()[this .data .selected_mod ]
99
-
100
- if mod .is_game_content then
101
- -- game mods can't be enabled or disabled
102
- elseif not mod .is_modpack then
103
- if toset == nil then
104
- mod .enabled = not mod .enabled
105
- else
106
- mod .enabled = toset
107
- end
108
- else
109
- local list = this .data .list :get_raw_list ()
110
- for i = 1 ,# list ,1 do
111
- if list [i ].modpack == mod .name then
112
- if toset == nil then
113
- toset = not list [i ].enabled
114
- end
115
- list [i ].enabled = toset
116
- end
117
- end
118
- end
78
+ " table[5.5,0.75;5.75,6;world_config_modlist;" ..
79
+ pkgmgr .render_packagelist (data .list ) .. " ;" .. data .selected_mod .. " ]"
119
80
end
120
81
121
-
122
82
local function handle_buttons (this , fields )
123
- if fields [ " world_config_modlist" ] ~= nil then
124
- local event = core .explode_table_event (fields [ " world_config_modlist" ] )
83
+ if fields . world_config_modlist then
84
+ local event = core .explode_table_event (fields . world_config_modlist )
125
85
this .data .selected_mod = event .row
126
86
core .settings :set (" world_config_selected_mod" , event .row )
127
87
128
88
if event .type == " DCL" then
129
- enable_mod (this )
89
+ pkgmgr . enable_mod (this )
130
90
end
131
91
132
92
return true
133
93
end
134
94
135
- if fields [ " key_enter" ] ~= nil then
136
- enable_mod (this )
95
+ if fields . key_enter then
96
+ pkgmgr . enable_mod (this )
137
97
return true
138
98
end
139
99
140
- if fields [" cb_mod_enable" ] ~= nil then
141
- local toset = core .is_yes (fields [" cb_mod_enable" ])
142
- enable_mod (this ,toset )
100
+ if fields .cb_mod_enable ~= nil then
101
+ pkgmgr .enable_mod (this , core .is_yes (fields .cb_mod_enable ))
143
102
return true
144
103
end
145
104
146
- if fields [" btn_mp_enable" ] ~= nil or
147
- fields [" btn_mp_disable" ] then
148
- local toset = (fields [" btn_mp_enable" ] ~= nil )
149
- enable_mod (this ,toset )
105
+ if fields .btn_mp_enable ~= nil or
106
+ fields .btn_mp_disable then
107
+ pkgmgr .enable_mod (this , fields .btn_mp_enable ~= nil )
150
108
return true
151
109
end
152
110
153
- if fields [" btn_config_world_save" ] then
154
- local filename = this .data .worldspec .path ..
155
- DIR_DELIM .. " world.mt"
111
+ if fields .btn_config_world_save then
112
+ local filename = this .data .worldspec .path .. DIR_DELIM .. " world.mt"
156
113
157
114
local worldfile = Settings (filename )
158
115
local mods = worldfile :to_table ()
159
116
160
117
local rawlist = this .data .list :get_raw_list ()
161
118
162
- local i , mod
163
- for i , mod in ipairs ( rawlist ) do
119
+ for i = 1 , # rawlist do
120
+ local mod = rawlist [ i ]
164
121
if not mod .is_modpack and
165
122
not mod .is_game_content then
166
123
if modname_valid (mod .name ) then
167
- worldfile :set (" load_mod_" .. mod .name , tostring (mod .enabled ))
168
- else
169
- if mod .enabled then
170
- gamedata .errormessage = fgettext_ne (" Failed to enable mod \" $1\" as it contains disallowed characters. Only chararacters [a-z0-9_] are allowed." , mod .name )
171
- end
124
+ worldfile :set (" load_mod_" .. mod .name ,
125
+ tostring (mod .enabled ))
126
+ elseif mod .enabled then
127
+ gamedata .errormessage = fgettext_ne (" Failed to enable mo" ..
128
+ " d \" $1\" as it contains disallowed characters. " ..
129
+ " Only chararacters [a-z0-9_] are allowed." ,
130
+ mod .name )
172
131
end
173
- mods [" load_mod_" .. mod .name ] = nil
132
+ mods [" load_mod_" .. mod .name ] = nil
174
133
end
175
134
end
176
135
177
136
-- Remove mods that are not present anymore
178
- for key , value in pairs (mods ) do
179
- if key :sub (1 ,9 ) == " load_mod_" then
137
+ for key in pairs (mods ) do
138
+ if key :sub (1 , 9 ) == " load_mod_" then
180
139
worldfile :remove (key )
181
140
end
182
141
end
@@ -189,7 +148,7 @@ local function handle_buttons(this, fields)
189
148
return true
190
149
end
191
150
192
- if fields [ " btn_config_world_cancel" ] then
151
+ if fields . btn_config_world_cancel then
193
152
this :delete ()
194
153
return true
195
154
end
@@ -224,62 +183,60 @@ local function handle_buttons(this, fields)
224
183
end
225
184
226
185
function create_configure_world_dlg (worldidx )
227
- local dlg = dialog_create (" sp_config_world" ,
228
- get_formspec ,
229
- handle_buttons ,
230
- nil )
186
+ local dlg = dialog_create (" sp_config_world" , get_formspec , handle_buttons )
231
187
232
- dlg .data .selected_mod = tonumber (core .settings :get (" world_config_selected_mod" ))
233
- if dlg .data .selected_mod == nil then
234
- dlg .data .selected_mod = 0
235
- end
188
+ dlg .data .selected_mod = tonumber (
189
+ core .settings :get (" world_config_selected_mod" )) or 0
236
190
237
191
dlg .data .worldspec = core .get_worlds ()[worldidx ]
238
- if dlg .data .worldspec == nil then dlg :delete () return nil end
192
+ if not dlg .data .worldspec then
193
+ dlg :delete ()
194
+ return
195
+ end
239
196
240
197
dlg .data .worldconfig = pkgmgr .get_worldconfig (dlg .data .worldspec .path )
241
198
242
- if dlg .data .worldconfig == nil or dlg .data .worldconfig .id == nil or
199
+ if not dlg .data .worldconfig or not dlg .data .worldconfig .id or
243
200
dlg .data .worldconfig .id == " " then
244
-
245
201
dlg :delete ()
246
- return nil
202
+ return
247
203
end
248
204
249
205
dlg .data .list = filterlist .create (
250
- pkgmgr .preparemodlist , -- refresh
251
- pkgmgr .comparemod , -- compare
252
- function (element ,uid ) -- uid match
253
- if element .name == uid then
254
- return true
255
- end
256
- end ,
257
- function (element , criteria )
258
- if criteria .hide_game and
259
- element .is_game_content then
260
- return false
261
- end
262
-
263
- if criteria .hide_modpackcontents and
264
- element .modpack ~= nil then
265
- return false
266
- end
267
- return true
268
- end , -- filter
269
- { worldpath = dlg .data .worldspec .path ,
270
- gameid = dlg .data .worldspec .gameid }
271
- )
206
+ pkgmgr .preparemodlist ,
207
+ pkgmgr .comparemod ,
208
+ function (element , uid )
209
+ if element .name == uid then
210
+ return true
211
+ end
212
+ end ,
213
+ function (element , criteria )
214
+ if criteria .hide_game and
215
+ element .is_game_content then
216
+ return false
217
+ end
218
+
219
+ if criteria .hide_modpackcontents and
220
+ element .modpack ~= nil then
221
+ return false
222
+ end
223
+ return true
224
+ end ,
225
+ {
226
+ worldpath = dlg .data .worldspec .path ,
227
+ gameid = dlg .data .worldspec .gameid
228
+ }
229
+ )
272
230
273
231
274
232
if dlg .data .selected_mod > dlg .data .list :size () then
275
233
dlg .data .selected_mod = 0
276
234
end
277
235
278
- dlg .data .list :set_filtercriteria (
279
- {
280
- hide_game = dlg .data .hide_gamemods ,
281
- hide_modpackcontents = dlg .data .hide_modpackcontents
282
- })
236
+ dlg .data .list :set_filtercriteria ({
237
+ hide_game = dlg .data .hide_gamemods ,
238
+ hide_modpackcontents = dlg .data .hide_modpackcontents
239
+ })
283
240
dlg .data .list :add_sort_mechanism (" alphabetic" , sort_mod_list )
284
241
dlg .data .list :set_sortmode (" alphabetic" )
285
242