1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/utils/test/helper.lua

129 lines
2.7 KiB
Lua
Raw Normal View History

2020-10-04 13:10:27 +02:00
local Global = require 'utils.global'
2020-09-26 21:02:53 +02:00
local Public = {}
local surface_count = 0
2020-10-04 13:10:27 +02:00
Global.register(
{surface_count = surface_count},
function(tbl)
surface_count = tbl.surface_count
end
)
2020-09-26 21:02:53 +02:00
local function get_surface_name()
surface_count = surface_count + 1
return 'test_surface' .. surface_count
end
local autoplace_settings = {
tile = {
treat_missing_as_default = false,
settings = {
['grass-1'] = {frequency = 1, size = 1, richness = 1}
}
}
}
local autoplace_controls = {
trees = {
frequency = 1,
richness = 1,
size = 0
},
['enemy-base'] = {
frequency = 1,
richness = 1,
size = 0
},
coal = {
frequency = 1,
richness = 1,
size = 0
},
['copper-ore'] = {
frequency = 1,
richness = 1,
size = 0
},
['crude-oil'] = {
frequency = 1,
richness = 1,
size = 0
},
['iron-ore'] = {
frequency = 1,
richness = 1,
size = 0
},
stone = {
frequency = 1,
richness = 1,
size = 0
},
['uranium-ore'] = {
frequency = 1,
richness = 1,
size = 0
}
}
local cliff_settings = {
cliff_elevation_0 = 1024,
cliff_elevation_interval = 10,
name = 'cliff'
}
2020-09-28 21:40:47 +02:00
function Public.startup_test_surface(context, options)
2020-09-26 21:02:53 +02:00
options = options or {}
local name = options.name or get_surface_name()
local area = options.area or {64, 64}
2020-09-28 21:40:47 +02:00
local player = context.player
2020-09-26 21:02:53 +02:00
local old_surface = player.surface
local old_position = player.position
2020-09-28 22:03:31 +02:00
local old_character = player.character
2020-09-26 21:02:53 +02:00
local surface =
game.create_surface(
name,
{
width = area.x or area[1],
height = area.y or area[2],
autoplace_settings = autoplace_settings,
autoplace_controls = autoplace_controls,
cliff_settings = cliff_settings
}
)
surface.request_to_generate_chunks({0, 0}, 32)
surface.force_generate_chunk_requests()
context:next(
function()
for k, v in pairs(surface.find_entities()) do
v.destroy()
end
surface.destroy_decoratives {area = {{-32, -32}, {32, 32}}}
2020-09-28 22:03:31 +02:00
player.character = nil
2020-09-26 21:02:53 +02:00
player.teleport({0, 0}, surface)
2020-09-28 22:03:31 +02:00
player.create_character()
2020-09-26 21:02:53 +02:00
end
)
return function()
2020-09-29 21:50:07 +02:00
player.character = nil
2020-09-26 21:02:53 +02:00
player.teleport(old_position, old_surface)
2020-09-28 22:03:31 +02:00
if old_character and old_character.valid then
player.character = old_character
end
2020-09-26 21:02:53 +02:00
game.delete_surface(surface)
end
end
return Public