2019-03-15 12:26:56 +00:00
|
|
|
local Util = require('util')
|
|
|
|
|
|
|
|
local device = _G.device
|
|
|
|
local kernel = _G.kernel
|
|
|
|
local os = _G.os
|
|
|
|
local peripheral = _G.peripheral
|
|
|
|
|
|
|
|
local containers = {
|
2019-06-18 19:19:24 +00:00
|
|
|
manipulator = true,
|
|
|
|
neuralInterface = true,
|
2019-03-15 12:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local function getModules(dev, side)
|
2019-06-18 19:19:24 +00:00
|
|
|
local list = { }
|
2019-03-15 12:26:56 +00:00
|
|
|
|
2019-06-18 19:19:24 +00:00
|
|
|
if dev then
|
|
|
|
for _, module in pairs(dev.listModules()) do
|
|
|
|
list[module] = Util.shallowCopy(dev)
|
|
|
|
list[module].name = module
|
|
|
|
list[module].type = module
|
|
|
|
list[module].side = side
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return list
|
2019-03-15 12:26:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
for _,v in pairs(device) do
|
2019-06-18 19:19:24 +00:00
|
|
|
if containers[v.type] then
|
|
|
|
local list = getModules(v, v.side)
|
|
|
|
for k, dev in pairs(list) do
|
|
|
|
-- neural and attached modules have precedence over manipulator modules
|
|
|
|
if not device[k] or v.type ~= 'manipulator' then
|
|
|
|
device[k] = dev
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-15 12:26:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- register modules as peripherals
|
|
|
|
kernel.hook('device_attach', function(_, eventData)
|
2019-06-18 19:19:24 +00:00
|
|
|
local dev = eventData[2]
|
2019-03-15 12:26:56 +00:00
|
|
|
|
2019-06-18 19:19:24 +00:00
|
|
|
if dev and containers[dev.type] then
|
|
|
|
local list = getModules(peripheral.wrap(dev.side), dev.side)
|
|
|
|
for k,v in pairs(list) do
|
|
|
|
if not device[k] or dev.type ~= 'manipulator' then
|
|
|
|
device[k] = v
|
|
|
|
os.queueEvent('device_attach', k, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-15 12:26:56 +00:00
|
|
|
end)
|