z_mirror/EditorExtensions

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

Caleb HeuerGenerate power in the debug worlde978e1a

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