z_mirror/Tapeline

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

Caleb Heuerfix: Undefined function in 3.1.1 migrationd9815be

trunk
1.6 KiB62 linesraw
1--- @diagnostic disable
2
3local settings = require("scripts.settings")
4local tape = require("scripts.tape")
5
6local versions = {
7  ["3.0.0"] = function()
8    rendering.clear(script.mod_name)
9    for _, surface in pairs(game.surfaces) do
10      for _, box in pairs(surface.find_entities_filtered({ name = "tl-highlight-box" })) do
11        box.destroy()
12      end
13    end
14    storage = {}
15    settings.on_init()
16    tape.on_init()
17  end,
18  ["3.0.3"] = function()
19    --- @param tbl table<uint, Tape>
20    local function migrate_tapes(tbl)
21      for key, tape_data in pairs(tbl) do
22        if tape_data.player.valid then
23          tape_data.player_index = tape_data.player.index
24        else
25          tbl[key] = nil
26        end
27      end
28    end
29    migrate_tapes(storage.drawing)
30    migrate_tapes(storage.editing)
31    migrate_tapes(storage.tapes)
32  end,
33  ["3.1.1"] = function()
34    for _, player in pairs(game.players) do
35      if tape.get_tool(player)
36        and player.controller_type == defines.controllers.character
37        and player.character_build_distance_bonus >= 1000000
38      then
39        player.character_build_distance_bonus = player.character_build_distance_bonus - 1000000
40      end
41    end
42  end,
43}
44
45--- @type event_handler
46local migrations = {}
47
48--- @param e ConfigurationChangedData
49function migrations.on_configuration_changed(e)
50  local old_version = e.mod_changes[script.mod_name] and e.mod_changes[script.mod_name].old_version
51  if not old_version then
52    return
53  end
54
55  for version, migration in pairs(versions) do
56    if helpers.compare_versions(version, old_version) > 0 then
57      migration()
58    end
59  end
60end
61
62return migrations