mirror of
https://github.com/kepler155c/opus
synced 2025-01-16 18:32:52 +00:00
modules as devices
This commit is contained in:
parent
e2508c9037
commit
0c91082003
@ -59,8 +59,7 @@ end)
|
||||
kernel.hook('peripheral_detach', function(_, eventData)
|
||||
local side = eventData[1]
|
||||
if side then
|
||||
local dev = Util.find(device, 'side', side)
|
||||
if dev then
|
||||
for _, dev in pairs(Util.findAll(device, 'side', side)) do
|
||||
os.queueEvent('device_detach', dev.name, dev)
|
||||
if dev._children then
|
||||
for _,v in pairs(dev._children) do
|
||||
|
47
sys/extensions/3.modules.lua
Normal file
47
sys/extensions/3.modules.lua
Normal file
@ -0,0 +1,47 @@
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local kernel = _G.kernel
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local containers = {
|
||||
manipulator = true,
|
||||
neuralInterface = true,
|
||||
}
|
||||
|
||||
local function getModules(dev, side)
|
||||
local list = { }
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
for _,v in pairs(device) do
|
||||
if containers[v.type] then
|
||||
local list = getModules(v, v.side)
|
||||
for k, dev in pairs(list) do
|
||||
device[k] = dev
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- register modules as peripherals
|
||||
kernel.hook('device_attach', function(_, eventData)
|
||||
local dev = eventData[2]
|
||||
|
||||
if dev and containers[dev.type] then
|
||||
local list = getModules(peripheral.wrap(dev.side), dev.side)
|
||||
for k,v in pairs(list) do
|
||||
device[k] = v
|
||||
os.queueEvent('device_attach', k, v)
|
||||
end
|
||||
end
|
||||
end)
|
@ -1,5 +1,5 @@
|
||||
Cloud Catcher is a web terminal for ComputerCraft, allowing you to interact with any in-game computer in the browser, as well as edit files remotely!
|
||||
|
||||
To get started, visit https://cloud-catcher.squiddev.cc/cloud.lua for a session key.
|
||||
To get started, visit https://cloud-catcher.squiddev.cc for a session key.
|
||||
|
||||
Within Files, press 'c' to edit a file using Cloud Catcher.
|
||||
|
Loading…
Reference in New Issue
Block a user