-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathghostconnections.lua
35 lines (30 loc) · 918 Bytes
/
ghostconnections.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local util = require "util"
local M = {}
-- returns an array of CircuitConnectionDefinition
function M.get_connections(entity)
local position = entity.position
local distance = entity.prototype.max_circuit_wire_distance
local area = {
left_top = { x = position.x - distance, y = position.y - distance },
right_bottom = { x = position.x + distance, y = position.y + distance }
}
local ghosts = entity.surface.find_entities_filtered{
type = "entity-ghost",
area = area,
}
local out = {}
for _, ghost in pairs(ghosts) do
for _, ccd in pairs(ghost.circuit_connection_definitions or {}) do
if ccd.target_entity == entity then
out[#out+1] = {
wire = ccd.wire,
target_entity = ghost,
source_circuit_id = ccd.target_circuit_id,
target_circuit_id = ccd.source_circuit_id,
}
end
end
end
return out
end
return M