z_mirror/EditorExtensions

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

Caleb HeuerSet "ignore surface conditions" on testing surfacesa0974f1

trunk
3.0 KiB114 linesraw
1local util = require("scripts.util")
2
3--- @param surface LuaSurface
4local function setup_surface(surface)
5  surface.generate_with_lab_tiles = true
6  surface.show_clouds = false
7  surface.freeze_daytime = true
8  surface.daytime = 0
9  surface.ignore_surface_conditions = true
10  surface.clear(true)
11end
12
13--- @param force LuaForce
14local function setup_force(force)
15  force.max_successful_attempts_per_tick_per_construction_queue = 30
16  force.max_failed_attempts_per_tick_per_construction_queue = 10
17  force.research_all_technologies()
18  if util.in_testing_scenario() then
19    force.rechart()
20  end
21end
22
23--- @param player LuaPlayer
24local function setup_player(player)
25  player.cheat_mode = true
26  local start_in_editor = player.mod_settings["ee-start-in-editor"]
27  if start_in_editor and start_in_editor.value then
28    player.toggle_map_editor()
29  end
30  if util.in_debug_world() then
31    local items = remote.call("freeplay", "get_created_items") --[[@as table<string, uint>]]
32    remote.call("freeplay", "set_created_items", {}) --- @diagnostic disable-line: missing-fields
33    remote.call("freeplay", "set_respawn_items", {}) --- @diagnostic disable-line: missing-fields
34    for name, count in pairs(items) do
35      player.remove_item({ name = name, count = count })
36    end
37  end
38end
39
40--- @param e EventData.on_force_created
41local function on_force_created(e)
42  if not util.in_debug_world() and not util.in_testing_scenario() then
43    return
44  end
45  setup_force(e.force)
46end
47
48--- @param e EventData.on_player_created
49local function on_player_created(e)
50  if not util.in_debug_world() and not util.in_testing_scenario() then
51    return
52  end
53  local player = game.get_player(e.player_index)
54  if player then
55    setup_player(player)
56  end
57end
58
59--- @param e EventData.on_surface_cleared
60local function on_surface_cleared(e)
61  if not util.in_debug_world() then
62    return
63  end
64  local surface = game.get_surface(e.surface_index)
65  if not surface then
66    return
67  end
68  surface.create_entity({
69    name = "ee-infinity-accumulator-primary-output",
70    position = { -24, -24 },
71    force = game.forces.player,
72    create_build_effect_smoke = false,
73  })
74  surface.create_entity({
75    name = "ee-super-substation",
76    position = { -22, -24 },
77    force = game.forces.player,
78    create_build_effect_smoke = false,
79  })
80end
81
82local function on_init()
83  if not util.in_debug_world() and not util.in_testing_scenario() then
84    return
85  end
86  if game.tick ~= 0 then
87    return
88  end
89  for _, force in pairs(game.forces) do
90    setup_force(force)
91  end
92  for _, player in pairs(game.players) do
93    setup_player(player)
94  end
95
96  if util.in_debug_world() then
97    local nauvis = game.get_surface("nauvis")
98    if nauvis then
99      setup_surface(nauvis)
100    end
101  end
102end
103
104local debug_world = {}
105
106debug_world.on_init = on_init
107
108debug_world.events = {
109  [defines.events.on_force_created] = on_force_created,
110  [defines.events.on_player_created] = on_player_created,
111  [defines.events.on_surface_cleared] = on_surface_cleared,
112}
113
114return debug_world