-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmigration.lua
104 lines (91 loc) · 2.78 KB
/
migration.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
local current_version = require("mpp.version")
local conf = require("configuration")
local enums = require("mpp.enums")
-- resetting a GUI manually from console
-- /c __mining-patch-planner__ game.player.gui.screen.mpp_settings_frame.destroy()
---@param player LuaPlayer
local function reset_gui(player, player_data)
local root = player.gui.left["mpp_settings_frame"] or player.gui.screen["mpp_settings_frame"]
if root then
root.destroy()
end
local cursor_stack = player.cursor_stack
if cursor_stack and cursor_stack.valid and cursor_stack.valid_for_read and cursor_stack.name == "mining-patch-planner" then
cursor_stack.clear()
end
player_data.gui = {
section = {},
tables = {},
selections = {},
advanced_settings = nil,
filtering_settings = nil,
blueprint_add_button = nil,
blueprint_add_section = nil,
blueprint_receptacle = nil,
layout_dropdown = nil,
quality_toggle = nil,
}
end
script.on_configuration_changed(function(config_changed_data)
local version = storage.version or 0
storage.version = current_version
if config_changed_data.mod_changes["mining-patch-planner"] and version < current_version then
storage.tasks = storage.tasks or {}
conf.initialize_deconstruction_filter()
for player_index, data in pairs(storage.players) do
---@cast data PlayerData
local player = game.players[player_index]
reset_gui(player, data)
--conf.initialize_global(player_index)
conf.update_player_data(player_index)
conf.update_player_quality_data(player_index)
end
else
for player_index, data in pairs(storage.players) do
reset_gui(game.players[player_index], data)
conf.update_player_quality_data(player_index)
end
end
if config_changed_data.old_version and string.sub(config_changed_data.old_version, 1, 3) == "1.1" then
-- delete tasks old 1.1 tasks
storage.tasks = {}
rendering.clear("mining-patch-planner")
for player_index, data in pairs(storage.players) do
---@cast data PlayerData
data.last_state = nil
end
end
if version == 0 then
return
end
if version < 010600 then
for player_index, data in pairs(storage.players) do
---@cast data PlayerData
local blueprints = data.blueprints
local bp_inventory = data.blueprint_items
for k, v in pairs(blueprints.flow) do
v.destroy()
end
if bp_inventory and bp_inventory.valid then
bp_inventory.clear()
bp_inventory.resize(1)
end
blueprints.original_id = {}
blueprints.mapping = {}
blueprints.cache = {}
blueprints.flow = {}
blueprints.button = {}
blueprints.delete = {}
end
end
if version < 010617 then
for player_index, player_data in pairs(storage.players) do
local filtered = player_data.filtered_entities
for k, v in pairs(filtered) do
if v == true then
filtered[k] = "user_hidden"
end
end
end
end
end)