2018-11-18 18:12:00 +02:00
|
|
|
--[[-- info
|
|
|
|
Provides the ability to refresh the map and generate darkness.
|
|
|
|
]]
|
|
|
|
|
|
|
|
-- dependencies
|
|
|
|
local Event = require 'utils.event'
|
|
|
|
|
|
|
|
-- this
|
|
|
|
local RefreshMap = {}
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
Registers all event handlers.
|
|
|
|
]]
|
2018-12-13 21:59:00 +02:00
|
|
|
function RefreshMap.register()
|
2018-11-18 18:12:00 +02:00
|
|
|
Event.add(defines.events.on_chunk_generated, function (event)
|
|
|
|
local tiles = {}
|
|
|
|
|
2018-11-26 22:37:41 +02:00
|
|
|
local left_top = event.area.left_top
|
|
|
|
local left_top_x = left_top.x
|
|
|
|
local left_top_y = left_top.y
|
|
|
|
|
|
|
|
local count = 0
|
2018-11-18 18:12:00 +02:00
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
2018-11-26 22:37:41 +02:00
|
|
|
local target_x = left_top_x + x
|
|
|
|
local target_y = left_top_y + y
|
2018-11-18 18:12:00 +02:00
|
|
|
local tile = 'out-of-map'
|
|
|
|
|
2018-11-26 22:37:41 +02:00
|
|
|
if target_x > -2 and target_x < 1 and target_y > -2 and target_y < 1 then
|
2018-11-18 18:12:00 +02:00
|
|
|
tile = 'lab-dark-1'
|
|
|
|
end
|
|
|
|
|
2018-11-26 22:37:41 +02:00
|
|
|
count = count + 1
|
|
|
|
tiles[count] = {
|
2018-11-18 18:12:00 +02:00
|
|
|
name = tile,
|
|
|
|
position = {x = target_x, y = target_y}
|
2018-11-26 22:37:41 +02:00
|
|
|
}
|
2018-11-18 18:12:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
event.surface.set_tiles(tiles)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
return RefreshMap
|