mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
allow multiple surfaces in map gen
This commit is contained in:
parent
fc1b0cc01d
commit
7725385ecd
@ -2,59 +2,13 @@ local Task = require 'utils.Task'
|
||||
local Token = require 'utils.global_token'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local shape
|
||||
local tiles_per_tick
|
||||
local regen_decoratives
|
||||
local surfaces
|
||||
|
||||
local total_calls
|
||||
|
||||
local function do_row(row, data)
|
||||
local function do_tile(tile, pos)
|
||||
if not tile then
|
||||
table.insert(data.tiles, {name = 'out-of-map', position = pos})
|
||||
elseif type(tile) == 'string' then
|
||||
table.insert(data.tiles, {name = tile, position = pos})
|
||||
end
|
||||
end
|
||||
|
||||
local y = data.top_y + row
|
||||
local top_x = data.top_x
|
||||
|
||||
data.y = y
|
||||
|
||||
for x = top_x, top_x + 31 do
|
||||
data.x = x
|
||||
local pos = {x, y}
|
||||
|
||||
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
||||
local tile = shape(x + 0.5, y + 0.5, data)
|
||||
|
||||
if type(tile) == 'table' then
|
||||
do_tile(tile.tile, pos)
|
||||
|
||||
local entities = tile.entities
|
||||
if entities then
|
||||
for _, entity in ipairs(entities) do
|
||||
if not entity.position then
|
||||
entity.position = pos
|
||||
end
|
||||
table.insert(data.entities, entity)
|
||||
end
|
||||
end
|
||||
|
||||
local decoratives = tile.decoratives
|
||||
if decoratives then
|
||||
for _, decorative in ipairs(decoratives) do
|
||||
table.insert(data.decoratives, decorative)
|
||||
end
|
||||
end
|
||||
else
|
||||
do_tile(tile, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function do_tile(y, x, data)
|
||||
local function do_tile(y, x, data, shape)
|
||||
local function do_tile_inner(tile, pos)
|
||||
if not tile then
|
||||
table.insert(data.tiles, {name = 'out-of-map', position = pos})
|
||||
@ -157,6 +111,11 @@ local function map_gen_action(data)
|
||||
local state = data.y
|
||||
|
||||
if state < 32 then
|
||||
local shape = surfaces[data.surface.name]
|
||||
if shape == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
local count = tiles_per_tick
|
||||
|
||||
local y = state + data.top_y
|
||||
@ -168,7 +127,7 @@ local function map_gen_action(data)
|
||||
|
||||
repeat
|
||||
count = count - 1
|
||||
do_tile(y, x, data)
|
||||
do_tile(y, x, data, shape)
|
||||
|
||||
x = x + 1
|
||||
if x == max_x then
|
||||
@ -206,6 +165,13 @@ end
|
||||
local map_gen_action_token = Token.register(map_gen_action)
|
||||
|
||||
local function on_chunk(event)
|
||||
local surface = event.surface
|
||||
local shape = surfaces[surface.name]
|
||||
|
||||
if not shape then
|
||||
return
|
||||
end
|
||||
|
||||
local area = event.area
|
||||
|
||||
local data = {
|
||||
@ -214,7 +180,7 @@ local function on_chunk(event)
|
||||
area = area,
|
||||
top_x = area.left_top.x,
|
||||
top_y = area.left_top.y,
|
||||
surface = event.surface,
|
||||
surface = surface,
|
||||
tiles = {},
|
||||
entities = {},
|
||||
decoratives = {}
|
||||
@ -224,9 +190,9 @@ local function on_chunk(event)
|
||||
end
|
||||
|
||||
local function init(args)
|
||||
shape = args.shape
|
||||
tiles_per_tick = args.tiles_per_tick or 32
|
||||
regen_decoratives = args.regen_decoratives or false
|
||||
surfaces = args.surfaces or {}
|
||||
|
||||
total_calls = math.ceil(1024 / tiles_per_tick) + 4
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
local Token = require 'utils.global_token'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local shape
|
||||
local regen_decoratives
|
||||
local surfaces
|
||||
|
||||
local function do_row(row, data)
|
||||
local function do_row(row, data, shape)
|
||||
local function do_tile(tile, pos)
|
||||
if not tile then
|
||||
table.insert(data.tiles, {name = 'out-of-map', position = pos})
|
||||
@ -97,20 +97,27 @@ local function do_place_entities(data)
|
||||
end
|
||||
|
||||
local function on_chunk(event)
|
||||
local surface = event.surface
|
||||
local shape = surfaces[surface.name]
|
||||
|
||||
if not shape then
|
||||
return
|
||||
end
|
||||
|
||||
local area = event.area
|
||||
|
||||
local data = {
|
||||
area = area,
|
||||
top_x = area.left_top.x,
|
||||
top_y = area.left_top.y,
|
||||
surface = event.surface,
|
||||
surface = surface,
|
||||
tiles = {},
|
||||
entities = {},
|
||||
decoratives = {}
|
||||
}
|
||||
|
||||
for row = 0, 31 do
|
||||
do_row(row, data)
|
||||
do_row(row, data, shape)
|
||||
end
|
||||
|
||||
do_place_tiles(data)
|
||||
@ -119,8 +126,8 @@ local function on_chunk(event)
|
||||
end
|
||||
|
||||
local function init(args)
|
||||
shape = args.shape
|
||||
regen_decoratives = args.regen_decoratives
|
||||
surfaces = args.surfaces or {}
|
||||
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk)
|
||||
end
|
||||
|
@ -55,7 +55,7 @@ local tiles_per_tick = 32
|
||||
--shape = require "map_gen.presets.hearts"
|
||||
--shape = require "map_gen.presets.women"
|
||||
--shape = require "map_gen.presets.fractal_balls"
|
||||
--shape = require "map_gen.presets.fruit_loops"
|
||||
shape = require "map_gen.presets.fruit_loops"
|
||||
--shape = require "map_gen.presets.fish_islands"
|
||||
--shape = require "map_gen.presets.ContraSpiral"
|
||||
--shape = require "map_gen.presets.cookies"
|
||||
@ -126,6 +126,10 @@ if #terrain_modules > 0 then
|
||||
end
|
||||
|
||||
if shape then
|
||||
require('map_gen.shared.generate')({shape = shape, regen_decoratives = regen_decoratives, tiles_per_tick = tiles_per_tick})
|
||||
--require ("map_gen.shared.generate_not_threaded")({shape = shape, regen_decoratives = regen_decoratives})
|
||||
local surfaces = {
|
||||
['nauvis'] = shape,
|
||||
}
|
||||
|
||||
require('map_gen.shared.generate')({surfaces = surfaces, regen_decoratives = regen_decoratives, tiles_per_tick = tiles_per_tick})
|
||||
--require ("map_gen.shared.generate_not_threaded")({surfaces = surfaces, regen_decoratives = regen_decoratives})
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user