mirror of
https://github.com/kepler155c/opus
synced 2024-12-29 10:00:26 +00:00
manipulators aaarrrggghhh
This commit is contained in:
parent
d8dd17333c
commit
92686381c7
@ -3,3 +3,4 @@ sys/apps/update.lua urlfs http://pastebin.com/raw/UzGHLbNC
|
||||
sys/apps/Enchat.lua urlfs https://raw.githubusercontent.com/LDDestroier/enchat/master/enchat3.lua
|
||||
sys/apps/cloud.lua urlfs https://cloud-catcher.squiddev.cc/cloud.lua
|
||||
sys/apps/nfttrans.lua urlfs https://pastebin.com/raw/e8XrzeDY
|
||||
rom/modules/main/opus linkfs sys/modules/opus
|
@ -11,8 +11,11 @@ local containers = {
|
||||
|
||||
local cache = { }
|
||||
|
||||
-- manipulators will throw an error on listModules
|
||||
-- if the user has logged off
|
||||
local function getModules(dev, side)
|
||||
local list = { }
|
||||
local s, m = pcall(function()
|
||||
if dev and dev.listModules then
|
||||
for _, module in pairs(dev.listModules()) do
|
||||
list[module] = Util.shallowCopy(dev)
|
||||
@ -21,6 +24,10 @@ local function getModules(dev, side)
|
||||
list[module].side = side
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
@ -39,20 +46,27 @@ local function addDevice(dev, args, doQueue)
|
||||
if doQueue then
|
||||
os.queueEvent('device_attach', name)
|
||||
end
|
||||
return device[name]
|
||||
end
|
||||
|
||||
-- directly access the peripheral as the methods in getInventory, etc.
|
||||
-- can become invalid without any way to tell
|
||||
local function damnManipulator(container, method, args, doQueue)
|
||||
local dev = addDevice(container[method](), args)
|
||||
for k,v in pairs(dev) do
|
||||
if type(v) == 'function' then
|
||||
local dev = { }
|
||||
local methods = {
|
||||
'drop', 'getDocs', 'getItem', 'getItemMeta', 'getTransferLocations',
|
||||
'list', 'pullItems', 'pushItems', 'size', 'suck',
|
||||
}
|
||||
-- the user might not be logged in when the compputer is started
|
||||
-- and there's no way to know when they have logged in.
|
||||
-- these methods will error if the user is not logged in
|
||||
if container[method] then
|
||||
for _,k in pairs(methods) do
|
||||
dev[k] = function(...)
|
||||
return device[container.name][method]()[k](...)
|
||||
end
|
||||
end
|
||||
end
|
||||
if doQueue then
|
||||
os.queueEvent('device_attach', args.name)
|
||||
|
||||
addDevice(dev, args, doQueue)
|
||||
end
|
||||
end
|
||||
|
||||
@ -66,32 +80,29 @@ local function addContainer(v, doQueue)
|
||||
end
|
||||
|
||||
if v.getName then
|
||||
pcall(function()
|
||||
local s, m = pcall(function()
|
||||
local name = v.getName()
|
||||
if name then
|
||||
if v.getInventory then
|
||||
damnManipulator(v, 'getInventory', {
|
||||
name = name .. ':inventory',
|
||||
type = 'inventory',
|
||||
side = v.side
|
||||
}, doQueue)
|
||||
end
|
||||
if v.getEquipment then
|
||||
damnManipulator(v, 'getEquipment', {
|
||||
name = name .. ':equipment',
|
||||
type = 'equipment',
|
||||
side = v.side
|
||||
}, doQueue)
|
||||
end
|
||||
if v.getEnder then
|
||||
damnManipulator(v, 'getEnder', {
|
||||
name = name .. ':enderChest',
|
||||
type = 'enderChest',
|
||||
side = v.side
|
||||
}, doQueue)
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -113,9 +124,11 @@ kernel.hook('device_attach', function(_, eventData)
|
||||
-- a module is removed
|
||||
if cache[name] then
|
||||
device[name] = cache[name]
|
||||
-- TODO: cannot simply merge - need to remove
|
||||
-- all functions then merge
|
||||
Util.merge(device[name], dev)
|
||||
for k,v in pairs(device[name]) do
|
||||
if type(v) == 'function' then
|
||||
device[name][k] = nil
|
||||
end
|
||||
end
|
||||
else
|
||||
cache[name] = dev
|
||||
end
|
||||
|
@ -1,4 +1,3 @@
|
||||
local fs = _G.fs
|
||||
|
||||
fs.mount('rom/modules/main/opus', 'linkfs', 'sys/modules/opus')
|
||||
fs.loadTab('sys/etc/fstab')
|
||||
|
@ -1,14 +1,22 @@
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
-- Default label
|
||||
if not os.getComputerLabel() then
|
||||
local id = os.getComputerID()
|
||||
|
||||
if _G.turtle then
|
||||
os.setComputerLabel('turtle_' .. id)
|
||||
|
||||
elseif _G.pocket then
|
||||
os.setComputerLabel('pocket_' .. id)
|
||||
|
||||
elseif _G.commands then
|
||||
os.setComputerLabel('command_' .. id)
|
||||
|
||||
elseif peripheral.find('neuralInterface') then
|
||||
os.setComputerLabel('neural_' .. id)
|
||||
|
||||
else
|
||||
os.setComputerLabel('computer_' .. id)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user