2018-09-08 18:29:27 +02:00
|
|
|
-- this
|
|
|
|
local Template = {}
|
|
|
|
|
|
|
|
Template.events = {
|
2018-09-11 22:15:02 +02:00
|
|
|
--[[--
|
|
|
|
When an entity is placed via the template function.
|
|
|
|
- event.entity LuaEntity
|
|
|
|
]]
|
|
|
|
on_placed_entity = script.generate_event_name(),
|
2018-09-08 18:29:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
Inserts a batch of tiles and then entities.
|
|
|
|
|
|
|
|
@see LuaSurface.set_tiles
|
|
|
|
@see LuaSurface.entity
|
|
|
|
|
|
|
|
@param surface LuaSurface to put the tiles and entities on
|
|
|
|
@param tiles table of tiles as required by set_tiles
|
|
|
|
@param entities table of entities as required by create_entity
|
|
|
|
]]
|
|
|
|
function Template.insert(surface, tiles, entities)
|
|
|
|
if (nil == entities) then
|
|
|
|
entities = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
surface.set_tiles(tiles)
|
|
|
|
|
|
|
|
for _, entity in pairs(entities) do
|
2018-09-11 22:15:02 +02:00
|
|
|
entity = surface.create_entity(entity)
|
|
|
|
if (nil == entity) then
|
|
|
|
error('Failed creating entity ' .. entity.name .. ' on surface.')
|
|
|
|
end
|
|
|
|
script.raise_event(Template.events.on_placed_entity, {entity = entity})
|
2018-09-08 18:29:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return Template
|