milo: mass storage support (ae/rs)
This commit is contained in:
46
milo/apis/massAdapter.lua
Normal file
46
milo/apis/massAdapter.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
local class = require('class')
|
||||
local itemDB = require('itemDB')
|
||||
local Mini = require('miniAdapter')
|
||||
|
||||
local os = _G.os
|
||||
|
||||
local Adapter = class(Mini)
|
||||
|
||||
function Adapter:init(args)
|
||||
Mini.init(self, args)
|
||||
|
||||
self._rawList = self.list
|
||||
|
||||
function self.list()
|
||||
-- wait for up to 1 sec until any items that have been inserted into interface are added to the system
|
||||
for _ = 0, 20 do
|
||||
if #self._rawList() == 0 then
|
||||
break
|
||||
end
|
||||
os.sleep(0)
|
||||
end
|
||||
|
||||
local list = { }
|
||||
for _, v in pairs(self.listAvailableItems()) do
|
||||
list[itemDB:makeKey(v)] = v
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function self.getItemMeta(key)
|
||||
local item = self.findItem(itemDB:splitKey(key))
|
||||
if item and item.getMetadata then
|
||||
return item.getMetadata()
|
||||
end
|
||||
end
|
||||
|
||||
function self.pushItems(target, key, amount, slot)
|
||||
local item = self.findItem(itemDB:splitKey(key))
|
||||
if item and item.export then
|
||||
return item.export(target, amount, slot)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
return Adapter
|
||||
Reference in New Issue
Block a user