mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Merge pull request #781 from plague006/fix/ent_and_terrain_modules
Switch to functions in table, adjust map_loader accordingly
This commit is contained in:
commit
dff903397c
@ -24,11 +24,11 @@ global.config = {
|
||||
['tiles_per_tick'] = 32,
|
||||
-- the entity modules to load (takes a list of requires), example included
|
||||
['entity_modules'] = {
|
||||
-- require('map_gen.entities.fluffy_rainbows')
|
||||
--function() return require('map_gen.entities.fluffy_rainbows') end
|
||||
},
|
||||
-- the terrain modules to load (takes a list of requires), example included
|
||||
['terrain_modules'] = {
|
||||
--require('map_gen.terrain.tris_chunk_grid')
|
||||
--function() return require('map_gen.terrain.tris_chunk_grid') end
|
||||
},
|
||||
},
|
||||
-- redmew_surface allows a map preset to control world generation as well as map and difficulty settings
|
||||
|
@ -3,20 +3,45 @@ local b = require 'map_gen.shared.builders'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local config = global.config.map_generation
|
||||
|
||||
local line = '-----------------------------\n'
|
||||
local shape_type = type(shape)
|
||||
|
||||
--- Check if shape is a function, if it isn't throw an error.
|
||||
local function shape_check()
|
||||
if shape_type ~= 'function' then
|
||||
error(line .. 'You cannot use entity or terrain modules together with this map as it does not return a function.')
|
||||
end
|
||||
end
|
||||
|
||||
--- Run each function once to trigger the require
|
||||
local function initialize(array)
|
||||
for i = 1, #array do
|
||||
array[i] = array[i]()
|
||||
end
|
||||
end
|
||||
|
||||
--- Initializes and applies entity modules after checking for errors.
|
||||
if #config.entity_modules > 0 then
|
||||
shape_check()
|
||||
initialize(config.entity_modules)
|
||||
shape = shape or b.full_shape
|
||||
shape = b.apply_entities(shape, config.entity_modules)
|
||||
end
|
||||
|
||||
--- Initializes and applies terrain modules after checking for errors.
|
||||
if #config.terrain_modules > 0 then
|
||||
shape_check()
|
||||
initialize(config.terrain_modules)
|
||||
shape = shape or b.full_shape
|
||||
|
||||
for _, m in ipairs(config.terrain_modules) do
|
||||
shape = b.overlay_tile_land(shape, m)
|
||||
end
|
||||
end
|
||||
|
||||
if type(shape) == 'function' then
|
||||
Debug.print(shape)
|
||||
Debug.print(shape_type)
|
||||
--- If shape is a function, initialize the generator
|
||||
if shape_type == 'function' then
|
||||
local surfaces = {
|
||||
[RS.get_surface_name()] = shape
|
||||
}
|
||||
@ -24,6 +49,6 @@ if type(shape) == 'function' then
|
||||
local gen = require('map_gen.shared.generate')
|
||||
gen.init({surfaces = surfaces, regen_decoratives = config.regen_decoratives, tiles_per_tick = config.tiles_per_tick})
|
||||
gen.register()
|
||||
elseif shape ~= true then
|
||||
error('You forgot to require a map')
|
||||
elseif shape ~= true then -- If a map is returning neither true nor a function, they did not include a map, or the map is returning an unexpected type.
|
||||
error(line .. 'The map selected in map_selection.lua is either missing or is returning a non-true non-function data type.')
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user