z_mirror/EditorExtensions

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

Caleb HeuerMicro023e869

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