2018-05-10 21:42:38 +02:00
|
|
|
local Token = require "utils.global_token"
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-05-09 00:46:49 +02:00
|
|
|
local shape
|
2018-05-10 21:42:38 +02:00
|
|
|
local place_decoratives = true
|
2018-05-09 00:46:49 +02:00
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
local function do_row(row, data)
|
2018-05-10 21:42:38 +02:00
|
|
|
local function do_tile(tile, pos)
|
2018-05-08 18:47:34 +02:00
|
|
|
if not tile then
|
2018-05-10 21:42:38 +02:00
|
|
|
table.insert(data.tiles, {name = "out-of-map", position = pos})
|
2018-05-08 18:47:34 +02:00
|
|
|
elseif type(tile) == "string" then
|
2018-05-10 21:42:38 +02:00
|
|
|
table.insert(data.tiles, {name = tile, position = pos})
|
2018-05-08 18:47:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
local y = data.top_y + row
|
|
|
|
local top_x = data.top_x
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-05-08 18:47:34 +02:00
|
|
|
data.y = y
|
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
for x = top_x, top_x + 31 do
|
2018-05-08 18:47:34 +02:00
|
|
|
data.x = x
|
2018-05-10 21:42:38 +02:00
|
|
|
local pos = {data.x, data.y}
|
2018-05-08 18:47:34 +02:00
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
2018-05-09 00:46:49 +02:00
|
|
|
local tile, entity = shape(x + 0.5, y + 0.5, data)
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-05-10 21:42:38 +02:00
|
|
|
if type(tile) == "table" then
|
|
|
|
do_tile(tile.tile, pos)
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-05-08 18:47:34 +02:00
|
|
|
local entities = tile.entities
|
|
|
|
if entities then
|
|
|
|
for _, entity in ipairs(entities) do
|
2018-05-10 21:42:38 +02:00
|
|
|
if not entity.position then
|
|
|
|
entity.position = pos
|
|
|
|
end
|
2018-05-08 18:47:34 +02:00
|
|
|
table.insert(data.entities, entity)
|
|
|
|
end
|
2018-02-23 13:40:26 +02:00
|
|
|
end
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-05-10 21:42:38 +02:00
|
|
|
--[[ local decoratives = tile.decoratives
|
2018-05-08 18:47:34 +02:00
|
|
|
if decoratives then
|
|
|
|
for _, decorative in ipairs(decoratives) do
|
|
|
|
table.insert(data.decoratives, decorative)
|
|
|
|
end
|
2018-05-10 21:42:38 +02:00
|
|
|
end ]]
|
2018-05-08 18:47:34 +02:00
|
|
|
else
|
2018-05-10 21:42:38 +02:00
|
|
|
do_tile(tile, pos)
|
2018-02-23 13:40:26 +02:00
|
|
|
end
|
|
|
|
end
|
2018-01-15 19:25:46 +02:00
|
|
|
end
|
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
local function do_place_tiles(data)
|
|
|
|
data.surface.set_tiles(data.tiles, true)
|
2018-01-15 19:25:46 +02:00
|
|
|
end
|
|
|
|
|
2018-05-10 21:42:38 +02:00
|
|
|
local decoratives = {
|
|
|
|
"brown-asterisk",
|
|
|
|
"brown-carpet-grass",
|
|
|
|
"brown-fluff",
|
|
|
|
"brown-fluff-dry",
|
|
|
|
"brown-hairy-grass",
|
|
|
|
"garballo",
|
|
|
|
"garballo-mini-dry",
|
|
|
|
"green-asterisk",
|
|
|
|
"green-bush-mini",
|
|
|
|
"green-carpet-grass",
|
|
|
|
"green-hairy-grass",
|
|
|
|
"green-pita",
|
|
|
|
"green-pita-mini",
|
|
|
|
"green-small-grass",
|
|
|
|
"red-asterisk"
|
|
|
|
}
|
|
|
|
|
2018-01-15 19:25:46 +02:00
|
|
|
local function do_place_decoratives(data)
|
2018-05-10 21:42:38 +02:00
|
|
|
if not place_decoratives then
|
2018-02-23 13:40:26 +02:00
|
|
|
return
|
|
|
|
end
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-05-10 21:42:38 +02:00
|
|
|
data.surface.regenerate_decorative(decoratives, {{data.top_x / 32, data.top_y / 32}})
|
2018-01-15 19:25:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function do_place_entities(data)
|
2018-02-23 13:40:26 +02:00
|
|
|
local surface = data.surface
|
|
|
|
for _, e in ipairs(data.entities) do
|
|
|
|
if surface.can_place_entity(e) then
|
2018-05-10 21:42:38 +02:00
|
|
|
local entity = surface.create_entity(e)
|
|
|
|
if e.callback then
|
|
|
|
local callback = Token.get(e.callback)
|
|
|
|
callback(entity)
|
|
|
|
end
|
2018-02-23 13:40:26 +02:00
|
|
|
end
|
2018-01-15 19:25:46 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-09 00:46:49 +02:00
|
|
|
local function on_chunk(event)
|
2018-05-10 21:42:38 +02:00
|
|
|
local area = event.area
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
local data = {
|
|
|
|
top_x = area.left_top.x,
|
|
|
|
top_y = area.left_top.y,
|
|
|
|
surface = event.surface,
|
|
|
|
tiles = {},
|
|
|
|
entities = {},
|
|
|
|
decoratives = {}
|
|
|
|
}
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
for row = 0, 31 do
|
|
|
|
do_row(row, data)
|
|
|
|
end
|
2018-01-15 19:25:46 +02:00
|
|
|
|
2018-02-23 13:40:26 +02:00
|
|
|
do_place_tiles(data)
|
2018-05-10 21:42:38 +02:00
|
|
|
do_place_entities(data)
|
2018-02-23 13:40:26 +02:00
|
|
|
do_place_decoratives(data)
|
2018-01-15 19:25:46 +02:00
|
|
|
end
|
2018-05-09 00:46:49 +02:00
|
|
|
|
|
|
|
local function init(s)
|
|
|
|
shape = s
|
|
|
|
return on_chunk
|
|
|
|
end
|
|
|
|
|
|
|
|
return init
|