z_mirror/EditorExtensions

git clone https://git.raiguard.me/z_mirror/EditorExtensions

Caleb HeuerRemove usage of flib migration modulecabb4ba

trunk
5.6 KiB175 linesraw
1local content =
2  [[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.
3
4The 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.
5
6Due 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.
7
8Each 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.
9
10There are many other changes, improvements, and new features as well. Please consult the changelog for more details.
11
12Finally, 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!
13
14- raiguard]]
15
16local flib_gui = require("__flib__.gui")
17
18local function remove_legacy_loaders()
19  for _, loader in pairs(storage.legacy_infinity_loaders or {}) do
20    if loader.valid then
21      loader.destroy()
22    end
23  end
24  storage.legacy_infinity_loaders = nil
25end
26
27local function on_notification_confirm_clicked(e)
28  local player = game.get_player(e.player_index)
29  if not player then
30    return
31  end
32
33  local window = player.gui.screen.ee_update_notification_window
34  if not window then
35    return
36  end
37
38  window.destroy()
39end
40
41flib_gui.add_handlers({
42  on_notification_confirm_clicked = on_notification_confirm_clicked,
43  on_notification_remove_legacy_loaders_clicked = remove_legacy_loaders,
44})
45
46--- @param player LuaPlayer
47local function create_gui(player)
48  if player.gui.screen.ee_update_notification_window then
49    return
50  end
51
52  flib_gui.add(player.gui.screen, {
53    type = "frame",
54    name = "ee_update_notification_window",
55    style_mods = { width = 500 },
56    direction = "vertical",
57    caption = "Editor Extensions 2.0",
58    elem_mods = { auto_center = true },
59    {
60      type = "frame",
61      style = "inside_shallow_frame_with_padding",
62      { type = "label", style_mods = { single_line = false }, caption = content },
63    },
64    {
65      type = "flow",
66      style = "dialog_buttons_horizontal_flow",
67      drag_target = "ee_update_notification_window",
68      {
69        type = "button",
70        style = "red_button",
71        style_mods = { height = 32, bottom_padding = 2, font = "default-dialog-button" },
72        caption = "[img=utility/warning] Destroy all legacy loaders",
73        handler = {
74          [defines.events.on_gui_click] = remove_legacy_loaders,
75        },
76      },
77      { type = "empty-widget", style = "flib_dialog_footer_drag_handle", ignored_by_interaction = true },
78      {
79        type = "button",
80        style = "confirm_button",
81        caption = { "gui.confirm" },
82        handler = { [defines.events.on_gui_click] = on_notification_confirm_clicked },
83      },
84    },
85  })
86end
87
88--- @param e BuiltEvent
89local function on_entity_built(e)
90  local entity = e.entity or e.destination
91  if not entity.valid or entity.name ~= "ee-infinity-loader-dummy-combinator" then
92    return
93  end
94  local loaders = storage.legacy_infinity_loaders
95  if not loaders then
96    loaders = {}
97    storage.legacy_infinity_loaders = loaders
98  end
99  loaders[entity.unit_number] = entity
100end
101
102local update_notification = {}
103
104--- @param e ConfigurationChangedData
105update_notification.on_configuration_changed = function(e)
106  local ee_changes = e.mod_changes["EditorExtensions"]
107  if
108    not ee_changes
109    or not ee_changes.old_version
110    or helpers.compare_versions(ee_changes.old_version, "1.99.99") > 0
111  then
112    return
113  end
114
115  for _, player in pairs(game.players) do
116    create_gui(player)
117  end
118
119  --- @type table<uint64, LuaEntity>
120  local loaders = {}
121  for _, surface in pairs(game.surfaces) do
122    for _, loader in pairs(surface.find_entities_filtered({ name = "ee-infinity-loader-dummy-combinator" })) do
123      loaders[loader.unit_number] = loader
124    end
125    for _, chest in pairs(surface.find_entities_filtered({ name = "ee-infinity-loader-chest" })) do
126      chest.destroy()
127    end
128  end
129  storage.legacy_infinity_loaders = loaders
130end
131
132update_notification.on_nth_tick = {
133  [180] = function()
134    if not storage.legacy_infinity_loaders then
135      return
136    end
137
138    for i, legacy in pairs(storage.legacy_infinity_loaders) do
139      if not legacy.valid then
140        storage.legacy_infinity_loaders[i] = nil
141        goto continue
142      end
143
144      for _, player in pairs(legacy.force.players) do
145        player.add_custom_alert(
146          legacy,
147          { type = "item", name = "ee-infinity-loader" },
148          "Remove legacy infinity loader",
149          true
150        )
151      end
152
153      ::continue::
154    end
155
156    if not next(storage.legacy_infinity_loaders) then
157      storage.legacy_infinity_loaders = nil
158    end
159  end,
160}
161
162commands.add_command("ee-remove-legacy-loaders", nil, function()
163  remove_legacy_loaders()
164end)
165
166update_notification.events = {
167  [defines.events.on_built_entity] = on_entity_built,
168  [defines.events.on_entity_cloned] = on_entity_built,
169  [defines.events.on_robot_built_entity] = on_entity_built,
170  [defines.events.script_raised_built] = on_entity_built,
171  [defines.events.script_raised_revive] = on_entity_built,
172  [defines.events.on_space_platform_built_entity] = on_entity_built,
173}
174
175return update_notification