-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathupdate-notification.lua
176 lines (149 loc) · 5.65 KB
/
update-notification.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
local content =
[[Editor Extensions has been updated to 2.0. This version is a BREAKING CHANGE, meaning that your testing setups may not function as they did before.
The infinity loader has been overhauled to fix belt saturation issues, solve edge cases with blueprints, and make them much more UPS efficient. Due to this, [font=default-bold][color=255,50,50]all previously placed infinity loaders will no longer function.[/color][/font] You will need to replace them in order for your testing setups to work again.
Due to game engine limitations, the new infinity loader only supports a single item filter. To put different items on each side of a belt, use two infinity loaders.
Each legacy infinity loader has been located and put into your alerts panel. If you wish to remove them, press the button below, or use the [font=default-bold]/ee-remove-legacy-loaders[/font] command.
There are many other changes, improvements, and new features as well. Please consult the changelog for more details.
Finally, the mod's control scripting has been rewritten from scratch, so there may be a few crashes. Please report any crashes you run into, and I will fix them posthaste. Thank you for your patience, and thank you for using Editor Extensions!
- raiguard]]
local flib_gui = require("__flib__.gui")
local flib_migration = require("__flib__.migration")
local function remove_legacy_loaders()
for _, loader in pairs(storage.legacy_infinity_loaders or {}) do
if loader.valid then
loader.destroy()
end
end
storage.legacy_infinity_loaders = nil
end
local function on_notification_confirm_clicked(e)
local player = game.get_player(e.player_index)
if not player then
return
end
local window = player.gui.screen.ee_update_notification_window
if not window then
return
end
window.destroy()
end
flib_gui.add_handlers({
on_notification_confirm_clicked = on_notification_confirm_clicked,
on_notification_remove_legacy_loaders_clicked = remove_legacy_loaders,
})
--- @param player LuaPlayer
local function create_gui(player)
if player.gui.screen.ee_update_notification_window then
return
end
flib_gui.add(player.gui.screen, {
type = "frame",
name = "ee_update_notification_window",
style_mods = { width = 500 },
direction = "vertical",
caption = "Editor Extensions 2.0",
elem_mods = { auto_center = true },
{
type = "frame",
style = "inside_shallow_frame_with_padding",
{ type = "label", style_mods = { single_line = false }, caption = content },
},
{
type = "flow",
style = "dialog_buttons_horizontal_flow",
drag_target = "ee_update_notification_window",
{
type = "button",
style = "red_button",
style_mods = { height = 32, bottom_padding = 2, font = "default-dialog-button" },
caption = "[img=utility/warning] Destroy all legacy loaders",
handler = {
[defines.events.on_gui_click] = remove_legacy_loaders,
},
},
{ type = "empty-widget", style = "flib_dialog_footer_drag_handle", ignored_by_interaction = true },
{
type = "button",
style = "confirm_button",
caption = { "gui.confirm" },
handler = { [defines.events.on_gui_click] = on_notification_confirm_clicked },
},
},
})
end
--- @param e BuiltEvent
local function on_entity_built(e)
local entity = e.entity or e.destination
if not entity.valid or entity.name ~= "ee-infinity-loader-dummy-combinator" then
return
end
local loaders = storage.legacy_infinity_loaders
if not loaders then
loaders = {}
storage.legacy_infinity_loaders = loaders
end
loaders[entity.unit_number] = entity
end
local update_notification = {}
--- @param e ConfigurationChangedData
update_notification.on_configuration_changed = function(e)
local ee_changes = e.mod_changes["EditorExtensions"]
if
not ee_changes
or not ee_changes.old_version
or flib_migration.is_newer_version("1.99.99", ee_changes.old_version)
then
return
end
for _, player in pairs(game.players) do
create_gui(player)
end
--- @type table<uint64, LuaEntity>
local loaders = {}
for _, surface in pairs(game.surfaces) do
for _, loader in pairs(surface.find_entities_filtered({ name = "ee-infinity-loader-dummy-combinator" })) do
loaders[loader.unit_number] = loader
end
for _, chest in pairs(surface.find_entities_filtered({ name = "ee-infinity-loader-chest" })) do
chest.destroy()
end
end
storage.legacy_infinity_loaders = loaders
end
update_notification.on_nth_tick = {
[180] = function()
if not storage.legacy_infinity_loaders then
return
end
for i, legacy in pairs(storage.legacy_infinity_loaders) do
if not legacy.valid then
storage.legacy_infinity_loaders[i] = nil
goto continue
end
for _, player in pairs(legacy.force.players) do
player.add_custom_alert(
legacy,
{ type = "item", name = "ee-infinity-loader" },
"Remove legacy infinity loader",
true
)
end
::continue::
end
if not next(storage.legacy_infinity_loaders) then
storage.legacy_infinity_loaders = nil
end
end,
}
commands.add_command("ee-remove-legacy-loaders", nil, function()
remove_legacy_loaders()
end)
update_notification.events = {
[defines.events.on_built_entity] = on_entity_built,
[defines.events.on_entity_cloned] = on_entity_built,
[defines.events.on_robot_built_entity] = on_entity_built,
[defines.events.script_raised_built] = on_entity_built,
[defines.events.script_raised_revive] = on_entity_built,
[defines.events.on_space_platform_built_entity] = on_entity_built,
}
return update_notification