milo perf fixes
This commit is contained in:
@@ -12,8 +12,6 @@ local fs = _G.fs
|
|||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
local string = _G.string
|
local string = _G.string
|
||||||
|
|
||||||
local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
|
|
||||||
|
|
||||||
local context = {
|
local context = {
|
||||||
state = Config.load('miloRemote', { displayMode = 0, deposit = true }),
|
state = Config.load('miloRemote', { displayMode = 0, deposit = true }),
|
||||||
responseHandlers = { },
|
responseHandlers = { },
|
||||||
@@ -107,51 +105,6 @@ local page = UI.Page {
|
|||||||
|
|
||||||
q = 'quit',
|
q = 'quit',
|
||||||
},
|
},
|
||||||
setup = UI.SlideOut {
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
titleBar = UI.TitleBar {
|
|
||||||
title = 'Remote Setup',
|
|
||||||
},
|
|
||||||
form = UI.Form {
|
|
||||||
x = 2, ex = -2, y = 2, ey = -1,
|
|
||||||
[1] = UI.TextEntry {
|
|
||||||
formLabel = 'Server', formKey = 'server',
|
|
||||||
help = 'ID for the server',
|
|
||||||
shadowText = 'Milo server ID',
|
|
||||||
limit = 6,
|
|
||||||
validate = 'numeric',
|
|
||||||
required = true,
|
|
||||||
},
|
|
||||||
[2] = UI.TextEntry {
|
|
||||||
formLabel = 'Return Slot', formKey = 'slot',
|
|
||||||
help = 'Use a slot for sending to storage',
|
|
||||||
shadowText = 'Inventory slot #',
|
|
||||||
limit = 5,
|
|
||||||
validate = 'numeric',
|
|
||||||
required = false,
|
|
||||||
},
|
|
||||||
[3] = UI.Checkbox {
|
|
||||||
formLabel = 'Shield Slot', formKey = 'useShield',
|
|
||||||
help = 'Or, use the shield slot for sending'
|
|
||||||
},
|
|
||||||
[4] = UI.Checkbox {
|
|
||||||
formLabel = 'Run on startup', formKey = 'runOnStartup',
|
|
||||||
help = 'Run this program on startup'
|
|
||||||
},
|
|
||||||
info = UI.TextArea {
|
|
||||||
x = 1, ex = -1, y = 6, ey = -4,
|
|
||||||
textColor = colors.yellow,
|
|
||||||
marginLeft = 0,
|
|
||||||
marginRight = 0,
|
|
||||||
value = [[The Milo turtle must connect to a manipulator with a ]] ..
|
|
||||||
[[bound introspection module. The neural interface must ]] ..
|
|
||||||
[[also have an introspection module.]],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
statusBar = UI.StatusBar {
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
items = { },
|
items = { },
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,13 +164,6 @@ function page:transfer(item, count, msg)
|
|||||||
context:sendRequest({ request = 'transfer', item = item, count = count }, msg)
|
context:sendRequest({ request = 'transfer', item = item, count = count }, msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.setup:eventHandler(event)
|
|
||||||
if event.type == 'focus_change' then
|
|
||||||
self.statusBar:setStatus(event.focused.help)
|
|
||||||
end
|
|
||||||
return UI.SlideOut.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
if event.type == 'quit' then
|
if event.type == 'quit' then
|
||||||
UI:exitPullEvents()
|
UI:exitPullEvents()
|
||||||
@@ -233,27 +179,6 @@ function page:eventHandler(event)
|
|||||||
context:setStatus(depositMode[context.state.deposit].help)
|
context:setStatus(depositMode[context.state.deposit].help)
|
||||||
Config.update('miloRemote', context.state)
|
Config.update('miloRemote', context.state)
|
||||||
|
|
||||||
elseif event.type == 'form_complete' then
|
|
||||||
Config.update('miloRemote', context.state)
|
|
||||||
self.setup:hide()
|
|
||||||
self:refresh('list')
|
|
||||||
self.grid:draw()
|
|
||||||
self:setFocus(self.statusBar.filter)
|
|
||||||
|
|
||||||
if context.state.runOnStartup then
|
|
||||||
if not fs.exists(STARTUP_FILE) then
|
|
||||||
Util.writeFile(STARTUP_FILE,
|
|
||||||
[[os.sleep(1)
|
|
||||||
shell.openForegroundTab('packages/milo/MiloRemote')]])
|
|
||||||
end
|
|
||||||
elseif fs.exists(STARTUP_FILE) then
|
|
||||||
fs.delete(STARTUP_FILE)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'form_cancel' then
|
|
||||||
self.setup:hide()
|
|
||||||
self:setFocus(self.statusBar.filter)
|
|
||||||
|
|
||||||
elseif event.type == 'focus_change' then
|
elseif event.type == 'focus_change' then
|
||||||
context:setStatus(event.focused.help)
|
context:setStatus(event.focused.help)
|
||||||
|
|
||||||
@@ -399,8 +324,11 @@ end
|
|||||||
context.page = page
|
context.page = page
|
||||||
|
|
||||||
function context:setStatus(status)
|
function context:setStatus(status)
|
||||||
page.menuBar.infoBar:setStatus(status)
|
page.menuBar.infoBar.values = status
|
||||||
page:sync()
|
if page.menuBar.infoBar.enabled then
|
||||||
|
page.menuBar.infoBar:draw()
|
||||||
|
page:sync()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function processMessages(s)
|
local function processMessages(s)
|
||||||
|
|||||||
@@ -216,10 +216,20 @@ function Milo:makeRequest(item, count, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Milo:eject(item, count)
|
function Milo:eject(item, count)
|
||||||
count = self.context.storage:export(self.context.turtleInventory, nil, count, item)
|
local total = 0
|
||||||
Sound.play('entity.experience_bottle.throw')
|
while count > 0 do
|
||||||
turtle.emptyInventory()
|
local amount = math.min(count, 16*(item.maxCount or 64))
|
||||||
return count
|
amount = self.context.storage:export(self.context.turtleInventory, nil, amount, item)
|
||||||
|
if amount == 0 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
total = total + amount
|
||||||
|
count = count - amount
|
||||||
|
|
||||||
|
Sound.play('ui.button.click')
|
||||||
|
turtle.emptyInventory()
|
||||||
|
end
|
||||||
|
return total
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:learnRecipe()
|
function Milo:learnRecipe()
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ local function client(socket)
|
|||||||
if not data then
|
if not data then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
_G._debug(data)
|
|
||||||
socket.co = coroutine.running()
|
socket.co = coroutine.running()
|
||||||
|
|
||||||
if data.request == 'scan' then -- full scan of all inventories
|
if data.request == 'scan' then -- full scan of all inventories
|
||||||
@@ -94,18 +94,11 @@ _G._debug(data)
|
|||||||
|
|
||||||
elseif data.request == 'deposit' then
|
elseif data.request == 'deposit' then
|
||||||
local function deposit()
|
local function deposit()
|
||||||
local devType = 'inventory'
|
local node = makeNode(data.source or 'inventory')
|
||||||
local slotNo = data.slot
|
|
||||||
if data.slot == 'shield' then
|
|
||||||
slotNo = SHIELD_SLOT
|
|
||||||
devType = 'equipment'
|
|
||||||
end
|
|
||||||
|
|
||||||
local node = makeNode(devType)
|
|
||||||
if node then
|
if node then
|
||||||
local slot = node.adapter.getItemMeta(slotNo)
|
local slot = node.adapter.getItemMeta(data.slot)
|
||||||
if slot then
|
if slot then
|
||||||
if context.storage:import(node, slotNo, slot.count, slot) > 0 then
|
if context.storage:import(node, data.slot, slot.count, slot) > 0 then
|
||||||
local item = Milo:getItem(slot)
|
local item = Milo:getItem(slot)
|
||||||
if item then
|
if item then
|
||||||
socket:write({
|
socket:write({
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ local colors = _G.colors
|
|||||||
local device = _G.device
|
local device = _G.device
|
||||||
local ni = device.neuralInterface
|
local ni = device.neuralInterface
|
||||||
|
|
||||||
|
local SHIELD_SLOT = 2
|
||||||
local context = args[1]
|
local context = args[1]
|
||||||
|
|
||||||
if not context.state.autostore then
|
if not context.state.autostore then
|
||||||
@@ -21,7 +22,7 @@ local page = UI.Page {
|
|||||||
previousPage = true,
|
previousPage = true,
|
||||||
},
|
},
|
||||||
tabs = UI.Tabs {
|
tabs = UI.Tabs {
|
||||||
y = 2,
|
y = 2, ey = -2,
|
||||||
inventory = UI.Window {
|
inventory = UI.Window {
|
||||||
tabTitle = 'Inventory',
|
tabTitle = 'Inventory',
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
@@ -43,6 +44,9 @@ local page = UI.Page {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
statusBar = UI.StatusBar {
|
||||||
|
values = 'Double-click to toggle auto-deposit'
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local function makeKey(item)
|
local function makeKey(item)
|
||||||
@@ -55,13 +59,12 @@ function page.tabs.inventory:enable()
|
|||||||
local list = { }
|
local list = { }
|
||||||
|
|
||||||
for k, item in pairs(inv) do
|
for k, item in pairs(inv) do
|
||||||
local key = itemDB:makeKey(item)
|
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(k) end)
|
||||||
|
local key = makeKey(item)
|
||||||
if not list[key] then
|
if not list[key] then
|
||||||
local cItem = itemDB:get(item, function() return ni.getInventory().getItemMeta(k) end)
|
item.key = key
|
||||||
if cItem then
|
item.displayName = item.displayName:match('(.+) %(damage:.+%)') or item.displayName
|
||||||
cItem.key = makeKey(cItem)
|
list[key] = item
|
||||||
list[key] = cItem
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -120,31 +123,26 @@ function page.tabs.autostore:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Event.onInterval(5, function()
|
Event.onInterval(5, function()
|
||||||
if context.state.deposit and (context.state.useShield or context.state.slot) then
|
if context.socket and
|
||||||
local inv = ni.getInventory().list()
|
context.state.deposit and
|
||||||
local slot = context.state.slot
|
(context.state.useShield or context.state.slot) and
|
||||||
local target = 'inventory'
|
not Util.empty(context.state.autostore) then
|
||||||
local empty = not inv[slot]
|
|
||||||
|
|
||||||
if context.state.useShield then
|
pcall(function() -- prevent errors from some mod items
|
||||||
slot = 2
|
for slot,v in pairs(ni.getInventory().list()) do
|
||||||
target = 'equipment'
|
local item = itemDB:get(v, function() ni.getInventory().getItemMeta(slot) end)
|
||||||
empty = not ni.getEquipment().list()[slot]
|
if item then
|
||||||
end
|
if context.state.autostore[makeKey(item)] then
|
||||||
|
context:sendRequest({
|
||||||
if empty then
|
request = 'deposit',
|
||||||
pcall(function() -- prevent errors from some mod items
|
source = 'inventory',
|
||||||
for k,v in pairs(inv) do
|
slot = slot,
|
||||||
local item = itemDB:get(v, function() ni.getInventory().getItemMeta(k) end)
|
count = item.count,
|
||||||
if item then
|
})
|
||||||
if context.state.autostore[makeKey(item)] then
|
|
||||||
ni.getInventory().pushItems(target, k, v.count, slot)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -17,19 +17,18 @@ Event.addRoutine(function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
os.sleep(context.socket and sleepTime or 5)
|
os.sleep(context.socket and sleepTime or 5)
|
||||||
if context.state.deposit then
|
if context.state.deposit and context.state.server and (context.state.useShield or context.state.slot) then
|
||||||
local neural = device.neuralInterface
|
local neural = device.neuralInterface
|
||||||
local inv = context.state.useShield and 'getEquipment' or 'getInventory'
|
local inv = context.state.useShield and 'getEquipment' or 'getInventory'
|
||||||
if not neural or not neural[inv] then
|
if neural and neural[inv] then
|
||||||
_G._debug('missing Introspection module')
|
|
||||||
elseif context.state.server and (context.state.useShield or context.state.slot) then
|
|
||||||
local s, m = pcall(function()
|
local s, m = pcall(function()
|
||||||
local method = neural[inv]
|
local method = neural[inv]
|
||||||
local item = method and method().list()[context.state.useShield and SHIELD_SLOT or context.state.slot]
|
local item = method and method().list()[context.state.useShield and SHIELD_SLOT or context.state.slot]
|
||||||
if item then
|
if item then
|
||||||
if context:sendRequest({
|
if context:sendRequest({
|
||||||
request = 'deposit',
|
request = 'deposit',
|
||||||
slot = context.state.useShield and 'shield' or context.state.slot,
|
source = context.state.useShield and 'equipment' or 'inventory',
|
||||||
|
slot = context.state.useShield and SHIELD_SLOT or context.state.slot,
|
||||||
count = item.count,
|
count = item.count,
|
||||||
}) then
|
}) then
|
||||||
lastTransfer = os.clock()
|
lastTransfer = os.clock()
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ local page = UI.Page {
|
|||||||
notification = UI.Notification(),
|
notification = UI.Notification(),
|
||||||
}
|
}
|
||||||
|
|
||||||
local function makeKey(item)
|
local function makeKey(item) -- group items regardless of damage
|
||||||
local damage = item.maxDamage == 0 and item.damage
|
local damage = item.maxDamage == 0 and item.damage
|
||||||
return itemDB:makeKey({ name = item.name, damage = damage })
|
return itemDB:makeKey({ name = item.name, damage = damage })
|
||||||
end
|
end
|
||||||
@@ -50,13 +50,11 @@ function page:updateInventoryList()
|
|||||||
|
|
||||||
for slot, item in pairs(inv) do
|
for slot, item in pairs(inv) do
|
||||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||||
local key = itemDB:makeKey(item)
|
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||||
|
local key = makeKey(item)
|
||||||
if not list[key] then
|
if not list[key] then
|
||||||
local cItem = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
item.displayName = item.displayName:match('(.+) %(damage:.+%)') or item.displayName
|
||||||
if cItem then
|
list[key] = item
|
||||||
cItem.key = makeKey(cItem)
|
|
||||||
list[key] = cItem
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
list[key].count = list[key].count + item.count
|
list[key].count = list[key].count + item.count
|
||||||
end
|
end
|
||||||
@@ -83,6 +81,7 @@ function page:depositAll()
|
|||||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||||
context:sendRequest({
|
context:sendRequest({
|
||||||
request = 'deposit',
|
request = 'deposit',
|
||||||
|
source = 'inventory',
|
||||||
slot = slot,
|
slot = slot,
|
||||||
count = item.count,
|
count = item.count,
|
||||||
})
|
})
|
||||||
|
|||||||
87
milo/plugins/remote/setup.lua
Normal file
87
milo/plugins/remote/setup.lua
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
local Config = require('config')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local fs = _G.fs
|
||||||
|
|
||||||
|
local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
|
||||||
|
|
||||||
|
local context = ({ ... })[1]
|
||||||
|
|
||||||
|
local setup = UI.SlideOut {
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
titleBar = UI.TitleBar {
|
||||||
|
title = 'Remote Setup',
|
||||||
|
},
|
||||||
|
form = UI.Form {
|
||||||
|
x = 2, ex = -2, y = 2, ey = -1,
|
||||||
|
[1] = UI.TextEntry {
|
||||||
|
formLabel = 'Server', formKey = 'server',
|
||||||
|
help = 'ID for the server',
|
||||||
|
shadowText = 'Milo server ID',
|
||||||
|
limit = 6,
|
||||||
|
validate = 'numeric',
|
||||||
|
required = true,
|
||||||
|
},
|
||||||
|
[2] = UI.TextEntry {
|
||||||
|
formLabel = 'Return Slot', formKey = 'slot',
|
||||||
|
help = 'Use a slot for sending to storage',
|
||||||
|
shadowText = 'Inventory slot #',
|
||||||
|
limit = 5,
|
||||||
|
validate = 'numeric',
|
||||||
|
required = false,
|
||||||
|
},
|
||||||
|
[3] = UI.Checkbox {
|
||||||
|
formLabel = 'Shield Slot', formKey = 'useShield',
|
||||||
|
help = 'Or, use the shield slot for sending'
|
||||||
|
},
|
||||||
|
[4] = UI.Checkbox {
|
||||||
|
formLabel = 'Run on startup', formKey = 'runOnStartup',
|
||||||
|
help = 'Run this program on startup'
|
||||||
|
},
|
||||||
|
info = UI.TextArea {
|
||||||
|
x = 1, ex = -1, y = 6, ey = -4,
|
||||||
|
textColor = colors.yellow,
|
||||||
|
marginLeft = 0,
|
||||||
|
marginRight = 0,
|
||||||
|
value = [[The Milo turtle must connect to a manipulator with a ]] ..
|
||||||
|
[[bound introspection module. The neural interface must ]] ..
|
||||||
|
[[also have an introspection module.]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
statusBar = UI.StatusBar {
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup:eventHandler(event)
|
||||||
|
if event.type == 'focus_change' then
|
||||||
|
self.statusBar:setStatus(event.focused.help)
|
||||||
|
|
||||||
|
elseif event.type == 'form_complete' then
|
||||||
|
Config.update('miloRemote', context.state)
|
||||||
|
self:hide()
|
||||||
|
context.page:refresh('list')
|
||||||
|
context.page.grid:draw()
|
||||||
|
context.page:setFocus(context.page.statusBar.filter)
|
||||||
|
|
||||||
|
if context.state.runOnStartup then
|
||||||
|
if not fs.exists(STARTUP_FILE) then
|
||||||
|
Util.writeFile(STARTUP_FILE,
|
||||||
|
[[os.sleep(1)
|
||||||
|
shell.openForegroundTab('packages/milo/MiloRemote')]])
|
||||||
|
end
|
||||||
|
elseif fs.exists(STARTUP_FILE) then
|
||||||
|
fs.delete(STARTUP_FILE)
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'form_cancel' then
|
||||||
|
self:hide()
|
||||||
|
context.page:setFocus(context.page.statusBar.filter)
|
||||||
|
end
|
||||||
|
|
||||||
|
return UI.SlideOut.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
|
||||||
|
context.page:add({ setup = setup })
|
||||||
Reference in New Issue
Block a user