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

111 lines
2.3 KiB
Lua
Raw Normal View History

2020-09-26 21:02:53 +02:00
local Public = {}
local surface_count = 0
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
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}}}
player.teleport({0, 0}, surface)
end
)
return function()
player.teleport(old_position, old_surface)
game.delete_surface(surface)
end
end
return Public