mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-08 00:39:30 +02:00
planet_prison: layers: add dependency injector
If some hook requires external variables it can inject them into layer object at runtime. This should solve the upvalue problem.
This commit is contained in:
parent
c895ff729d
commit
6d5f869e2b
@ -60,6 +60,7 @@ public.add_noise_layer = function(type, name, objects, elevation, resolution)
|
||||
resolution = resolution,
|
||||
cache = {},
|
||||
hook = nil,
|
||||
deps = nil,
|
||||
}
|
||||
|
||||
table.insert(global.this._layers, layer)
|
||||
@ -79,6 +80,20 @@ public.add_noise_layer_hook = function(name, hook)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
add_noise_layer_dependency - Adds dependency to the layer. It can be any
|
||||
lua variable. This dependency then is injected into hook.
|
||||
@param deps - Dependencies, any variable.
|
||||
--]]
|
||||
public.add_noise_layer_dependency = function(name, deps)
|
||||
for _, layer in pairs(global.this._layers) do
|
||||
if layer.name == name then
|
||||
layer.deps = deps
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
set_collision_mask - Set which tiles should be ignored.
|
||||
@param mask - Table of collision masks.
|
||||
@ -93,6 +108,7 @@ end
|
||||
|
||||
local function _do_job_entity(surf, layer)
|
||||
local hook = layer.hook
|
||||
local deps = layer.deps
|
||||
for _, object in pairs(layer.cache) do
|
||||
if object.name == "character" or object.name == "gun-turret" then
|
||||
if not surf.can_place_entity(object) then
|
||||
@ -106,7 +122,7 @@ local function _do_job_entity(surf, layer)
|
||||
end
|
||||
|
||||
if hook then
|
||||
hook(ent)
|
||||
hook(ent, deps)
|
||||
end
|
||||
|
||||
::continue::
|
||||
|
Loading…
Reference in New Issue
Block a user