@@ -165,7 +165,7 @@ function gui_open_frame(player)
165165 else
166166 global [" config-tmp" ][player .name ][i ] = {
167167 from = global [" config" ][player .name ][i ].from ,
168- to = global [" config" ][player .name ][i ].to
168+ to = util . table . deepcopy ( global [" config" ][player .name ][i ].to )
169169 }
170170 end
171171 end
@@ -247,7 +247,20 @@ function gui_open_frame(player)
247247 name = " module-inserter-debug" ,
248248 caption = " D"
249249 }
250+ else
251+ button_grid .add {type = " label" , caption = " " }
250252 end
253+ button_grid .add {
254+ type = " button" ,
255+ name = " module-inserter-save-as" ,
256+ caption = {" module-inserter-config-button-save-as" }
257+ }
258+
259+ local saveText = button_grid .add {
260+ type = " textfield" ,
261+ name = " module-inserter-save-as-text"
262+ }
263+ saveText .text = global .config [player .name ].loaded or " "
251264
252265 storage_frame = player .gui .left .add {
253266 type = " frame" ,
@@ -313,7 +326,7 @@ function gui_open_frame(player)
313326 end
314327end
315328
316- function gui_save_changes (player )
329+ function gui_save_changes (player , name )
317330 -- Saving changes consists in:
318331 -- 1. copying config-tmp to config
319332 -- 2. removing config-tmp
@@ -330,12 +343,13 @@ function gui_save_changes(player)
330343 else
331344 global [" config" ][player .name ][i ] = {
332345 from = global [" config-tmp" ][player .name ][i ].from ,
333- to = global [" config-tmp" ][player .name ][i ].to
346+ to = util . table . deepcopy ( global [" config-tmp" ][player .name ][i ].to )
334347 }
335348 end
336349 end
337350 global [" config-tmp" ][player .name ] = nil
338351 end
352+ global .config [player .name ].loaded = name or nil
339353 -- saveVar(global, "saved")
340354 local frame = player .gui .left [" module-inserter-config-frame" ]
341355 local storage_frame = player .gui .left [" module-inserter-storage-frame" ]
@@ -353,6 +367,10 @@ function gui_clear_all(player)
353367 local frame = player .gui .left [" module-inserter-config-frame" ]
354368 if not frame then return end
355369 local ruleset_grid = frame [" module-inserter-ruleset-grid" ]
370+ global .config [player .name ].loaded = nil
371+ local frame = player .gui .left [" module-inserter-config-frame" ]
372+ frame [" module-inserter-button-grid" ][" module-inserter-save-as-text" ].text = " "
373+
356374 for i = 1 , MAX_CONFIG_SIZE do
357375 global [" config-tmp" ][player .name ][i ] = { from = " " , to = {} }
358376 ruleset_grid [" module-inserter-from-" .. i ].style = " mi-icon-style"
@@ -536,6 +554,37 @@ function gui_store(player)
536554 -- saveVar(global, "stored")
537555end
538556
557+ function gui_save_as (player )
558+ global [" storage" ][player .name ] = global [" storage" ][player .name ] or {}
559+ local storage_frame = player .gui .left [" module-inserter-storage-frame" ]
560+ local frame = player .gui .left [" module-inserter-config-frame" ]
561+
562+ if not storage_frame or not frame then return end
563+ local textfield = frame [" module-inserter-button-grid" ][" module-inserter-save-as-text" ]
564+ local name = textfield .text
565+ name = string.match (name , " ^%s*(.-)%s*$" )
566+
567+ if not name or name == " " then
568+ gui_display_message (frame , true , " module-inserter-storage-name-not-set" )
569+ return
570+ end
571+ local index = count_keys (global [" storage" ][player .name ]) + 1
572+ if not global [" storage" ][player .name ][name ] and index > MAX_STORAGE_SIZE then
573+ gui_display_message (frame , false , " module-inserter-storage-too-long" )
574+ return
575+ end
576+
577+ global [" storage" ][player .name ][name ] = {}
578+ local i = 0
579+ for i = 1 , # global [" config-tmp" ][player .name ] do
580+ global [" storage" ][player .name ][name ][i ] = {
581+ from = global [" config-tmp" ][player .name ][i ].from ,
582+ to = util .table .deepcopy (global [" config-tmp" ][player .name ][i ].to )
583+ }
584+ end
585+ gui_save_changes (player , name )
586+ end
587+
539588function gui_restore (player , index )
540589 local frame = player .gui .left [" module-inserter-config-frame" ]
541590 local storage_frame = player .gui .left [" module-inserter-storage-frame" ]
@@ -557,7 +606,7 @@ function gui_restore(player, index)
557606 else
558607 global [" config-tmp" ][player .name ][i ] = {
559608 from = global [" storage" ][player .name ][name ][i ].from ,
560- to = global [" storage" ][player .name ][name ][i ].to
609+ to = util . table . deepcopy ( global [" storage" ][player .name ][name ][i ].to )
561610 }
562611 end
563612 local style = global [" config-tmp" ][player .name ][i ].from ~= " " and " mi-icon-" .. global [" config-tmp" ][player .name ][i ].from or " mi-icon-style"
@@ -566,6 +615,7 @@ function gui_restore(player, index)
566615 gui_update_modules (player , i )
567616 end
568617 gui_display_message (storage_frame , true , " ---" )
618+ gui_save_changes (player , name )
569619end
570620
571621function gui_remove (player , index )
0 commit comments