@@ -18,20 +18,6 @@ typeToSlot["furnace"] = defines.inventory.assembling_machine_modules
1818typeToSlot [" rocket-silo" ] = defines .inventory .assembling_machine_modules
1919typeToSlot [" beacon" ] = 1
2020
21- nameToSlots = {}
22- local metaitem = game .forces .player .recipes [" mi-meta" ].ingredients
23-
24- for i , ent in pairs (metaitem ) do
25- nameToSlots [ent .name ] = ent .amount
26- end
27-
28- game .forces .player .technologies [" mi-meta-productivityRecipes" ].reload ()
29- productivityRecipes = game .forces .player .technologies [" mi-meta-productivityRecipes" ].effects
30- productivityAllowed = # productivityRecipes > 0 and {} or false
31- for _ , recipe in pairs (productivityRecipes ) do
32- productivityAllowed [recipe .recipe ] = true
33- end
34-
3521function subPos (p1 ,p2 )
3622 local p2 = p2 or {x = 0 ,y = 0 }
3723 return {x = p1 .x - p2 .x , y = p1 .y - p2 .y }
@@ -60,7 +46,7 @@ function hasPocketBots(player)
6046 return port
6147end
6248
63- game .on_event (defines .events .on_marked_for_deconstruction , function (event )
49+ script .on_event (defines .events .on_marked_for_deconstruction , function (event )
6450 local status , err = pcall (function ()
6551 local entity = event .entity
6652 local deconstruction = false
@@ -163,8 +149,8 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
163149 entity .cancel_deconstruction (entity .force )
164150 return
165151 end
166- if productivityAllowed and entity .type == " assembling-machine" then
167- if entity .recipe and not productivityAllowed [entity .recipe .name ] == true then
152+ if global . productivityAllowed and entity .type == " assembling-machine" then
153+ if entity .recipe and not global . productivityAllowed [entity .recipe .name ] == true then
168154 player .print (" Can't use " .. module .. " with recipe: " .. entity .recipe .name )
169155 entity .cancel_deconstruction (entity .force )
170156 return
@@ -229,7 +215,6 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
229215end )
230216
231217local function initGlob ()
232-
233218 if not global .version or global .version < " 0.0.2" then
234219 global .config = {}
235220 global [" config-tmp" ] = {}
@@ -245,20 +230,41 @@ local function initGlob()
245230 global [" config-tmp" ] = global [" config-tmp" ] or {}
246231 global [" storage" ] = global [" storage" ] or {}
247232 global .guiVersion = global .guiVersion or {}
233+ global .nameToSlots = global .nameToSlots or {}
234+ global .productivityAllowed = global .productivityAllowed or {}
248235
249- if global .version < " 0.0.7" then
250- global [" storage" ] = {}
251- global .version = " 0.0.7"
236+ global .version = " 0.1.1"
237+ end
238+
239+ local function getMetaItemData ()
240+ local metaitem = game .forces .player .recipes [" mi-meta" ].ingredients
241+
242+ for i , ent in pairs (metaitem ) do
243+ global .nameToSlots [ent .name ] = ent .amount
252244 end
253245
254- if global . version < " 0.0.9 " then
255- global . entitiesToInsert = {}
256- global .removeTicks = {}
257- global . guiVersion = {}
258- global .version = " 0.0.9 "
246+ game . forces . player . technologies [ " mi-meta-productivityRecipes " ]. reload ()
247+ productivityRecipes = game . forces . player . technologies [ " mi-meta-productivityRecipes " ]. effects
248+ global . productivityAllowed = # productivityRecipes > 0 and global .productivityAllowed or false
249+ for _ , recipe in pairs ( productivityRecipes ) do
250+ global .productivityAllowed [ recipe . recipe ] = true
259251 end
252+ end
260253
261- -- hanndle removed items here
254+ local function oninit ()
255+ initGlob ()
256+ getMetaItemData ()
257+ script .on_event (defines .events .on_tick , function () update_gui () end )
258+ end
259+
260+ local function onload ()
261+ initGlob ()
262+ script .on_event (defines .events .on_tick , function () update_gui () end )
263+ end
264+
265+ local function on_configuration_changed (data )
266+ getMetaItemData ()
267+ -- handle removed items
262268 local items = game .item_prototypes
263269 for name , p in pairs (global .config ) do
264270 for i =# p ,1 ,- 1 do
@@ -294,17 +300,6 @@ local function initGlob()
294300 end
295301 end
296302 end
297- global .version = " 0.0.9"
298- end
299-
300- local function oninit ()
301- initGlob ()
302- game .on_event (defines .events .on_tick , function () update_gui () end )
303- end
304-
305- local function onload ()
306- initGlob ()
307- game .on_event (defines .events .on_tick , function () update_gui () end )
308303end
309304
310305function update_gui (player )
@@ -319,6 +314,24 @@ function update_gui(player)
319314 end
320315 gui_init (player )
321316 else
317+ for player , store in pairs (global .storage ) do
318+ for name , p in pairs (store ) do
319+ for i =# p ,1 ,- 1 do
320+ if p [i ].from ~= " " and not items [p [i ].from ] then
321+ global .storage [player ][name ][i ].from = " "
322+ global .storage [player ][name ][i ].to = " "
323+ end
324+ if type (p [i ].to ) == " table" then
325+ for k , m in pairs (p [i ].to ) do
326+ if m and not items [m ] then
327+ global .storage [player ][name ][i ].to [k ] = false
328+ end
329+ end
330+ end
331+ end
332+ end
333+ end
334+
322335 for i ,player in pairs (game .players ) do
323336 if player .valid and player .connected then
324337 if not global .guiVersion [player .name ] then
@@ -332,7 +345,7 @@ function update_gui(player)
332345 end
333346 end
334347 end
335- game .on_event (defines .events .on_tick , on_tick )
348+ script .on_event (defines .events .on_tick , on_tick )
336349 end )
337350 if not status then
338351 debugDump (err , true )
@@ -358,8 +371,9 @@ function get_config_item(player, index, type1)
358371 return game .get_localised_item_name (global [" config-tmp" ][player .name ][index ][type1 ])
359372end
360373
361- game .on_init (oninit )
362- game .on_load (onload )
374+ script .on_init (oninit )
375+ script .on_load (onload )
376+ script .on_configuration_changed (on_configuration_changed )
363377
364378function on_tick (event )
365379 if global .removeTicks [event .tick ] then
@@ -378,7 +392,7 @@ function on_tick(event)
378392 end
379393end
380394
381- game .on_event (defines .events .on_robot_built_entity , function (event )
395+ script .on_event (defines .events .on_robot_built_entity , function (event )
382396 local status , err = pcall (function ()
383397 local entity = event .created_entity
384398 if entity .name == " module-inserter-proxy" then
@@ -430,7 +444,7 @@ game.on_event(defines.events.on_robot_built_entity, function(event)
430444 end
431445end )
432446
433- game .on_event (defines .events .on_gui_click , function (event )
447+ script .on_event (defines .events .on_gui_click , function (event )
434448 local element = event .element
435449 -- debugDump(element.name, true)
436450 local player = game .get_player (event .player_index )
@@ -481,7 +495,7 @@ game.on_event(defines.events.on_gui_click, function(event)
481495 end
482496end )
483497
484- game .on_event (defines .events .on_research_finished , function (event )
498+ script .on_event (defines .events .on_research_finished , function (event )
485499 if event .research .name == ' automated-construction' then
486500 for _ , player in pairs (event .research .force .players ) do
487501 gui_init (player , true )
506520function saveVar (var , name )
507521 local var = var or global
508522 local n = name or " "
509- game .makefile (" module" .. n .. " .lua" , serpent .block (var , {name = " glob" }))
523+ game .write_file (" module" .. n .. " .lua" , serpent .block (var , {name = " glob" }))
510524end
511525
512526remote .add_interface (" mi" ,
0 commit comments