mirror of
https://github.com/kepler155c/opus
synced 2024-06-16 02:10:01 +00:00
manipulator :(
This commit is contained in:
parent
34c653ca1b
commit
c5a821f264
|
@ -128,32 +128,43 @@ kernel.hook('monitor_touch', function(event, eventData)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function createDevice(name, devType, methods, parent)
|
local function createDevice(name, devType, method, manipulator)
|
||||||
methods.name = name
|
local dev = {
|
||||||
methods.side = name
|
name = name,
|
||||||
methods.type = devType
|
side = name,
|
||||||
device[name] = methods
|
type = devType,
|
||||||
|
}
|
||||||
if not parent._children then
|
local methods = {
|
||||||
parent._children = { methods }
|
'drop', 'getDocs', 'getItem', 'getItemMeta', 'getTransferLocations',
|
||||||
|
'list', 'pullItems', 'pushItems', 'size', 'suck',
|
||||||
|
}
|
||||||
|
if manipulator[method] then
|
||||||
|
for _,k in pairs(methods) do
|
||||||
|
dev[k] = function(...)
|
||||||
|
return manipulator[method]()[k](...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not manipulator._children then
|
||||||
|
manipulator._children = { dev }
|
||||||
else
|
else
|
||||||
table.insert(parent._children, methods)
|
table.insert(manipulator._children, dev)
|
||||||
|
end
|
||||||
|
device[name] = dev
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
drivers['manipulator'] = function(dev)
|
drivers['manipulator'] = function(dev)
|
||||||
pcall(function()
|
|
||||||
local name = dev.getName()
|
local name = dev.getName()
|
||||||
if dev.getInventory then
|
if dev.getInventory then
|
||||||
createDevice(name .. ':inventory', 'inventory', dev.getInventory(), dev)
|
createDevice(name .. ':inventory', 'inventory', 'getInventory', dev)
|
||||||
end
|
end
|
||||||
if dev.getEquipment then
|
if dev.getEquipment then
|
||||||
createDevice(name .. ':equipment', 'equipment', dev.getEquipment(), dev)
|
createDevice(name .. ':equipment', 'equipment', 'getEquipment', dev)
|
||||||
end
|
end
|
||||||
if dev.getEnder then
|
if dev.getEnder then
|
||||||
createDevice(name .. ':enderChest', 'enderChest', dev.getEnder(), dev)
|
createDevice(name .. ':enderChest', 'enderChest', 'getEnder', dev)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
return dev._children
|
return dev._children
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user