z_mirror/EditorExtensions

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

Patrick 'Quezler' MounierMerge branch 'master' into patch-1e65a4b6

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