milo: refresh on storage config change + rabbit + auto detect player name
This commit is contained in:
@@ -128,13 +128,6 @@ local page = UI.Page {
|
||||
required = true,
|
||||
},
|
||||
[2] = UI.TextEntry {
|
||||
formLabel = 'User Name', formKey = 'user',
|
||||
help = 'User name for bound manipulator',
|
||||
shadowText = 'User name',
|
||||
limit = 50,
|
||||
required = true,
|
||||
},
|
||||
[3] = UI.TextEntry {
|
||||
formLabel = 'Return Slot', formKey = 'slot',
|
||||
help = 'Use a slot for sending to storage',
|
||||
shadowText = 'Inventory slot #',
|
||||
@@ -142,12 +135,12 @@ local page = UI.Page {
|
||||
validate = 'numeric',
|
||||
required = false,
|
||||
},
|
||||
[4] = UI.Checkbox {
|
||||
[3] = UI.Checkbox {
|
||||
formLabel = 'Shield Slot', formKey = 'useShield',
|
||||
help = 'Or, use the shield slot for sending'
|
||||
},
|
||||
info = UI.TextArea {
|
||||
x = 1, ex = -1, y = 7, ey = -3,
|
||||
x = 1, ex = -1, y = 6, ey = -4,
|
||||
textColor = colors.yellow,
|
||||
marginLeft = 0,
|
||||
marginRight = 0,
|
||||
@@ -163,6 +156,14 @@ local page = UI.Page {
|
||||
items = { },
|
||||
}
|
||||
|
||||
local function getPlayerName()
|
||||
local neural = device.neuralInterface
|
||||
|
||||
if neural and neural.getName then
|
||||
return neural.getName()
|
||||
end
|
||||
end
|
||||
|
||||
local function filterItems(t, filter, displayMode)
|
||||
if filter or displayMode > 0 then
|
||||
local r = { }
|
||||
@@ -194,9 +195,12 @@ function page:sendRequest(data)
|
||||
|
||||
if not config.server then
|
||||
self:setStatus('Invalid configuration')
|
||||
Event.onTimeout(2, function()
|
||||
self:setStatus('')
|
||||
end)
|
||||
return
|
||||
end
|
||||
|
||||
local player = getPlayerName()
|
||||
if not player then
|
||||
self:setStatus('Missing neural or introspection')
|
||||
return
|
||||
end
|
||||
|
||||
@@ -207,7 +211,7 @@ function page:sendRequest(data)
|
||||
self:setStatus('connecting ...')
|
||||
socket, msg = Socket.connect(config.server, 4242)
|
||||
if socket then
|
||||
socket:write(config.user)
|
||||
socket:write(player)
|
||||
local r = socket:read(2)
|
||||
if r and not r.msg then
|
||||
self:setStatus('connected ...')
|
||||
@@ -416,27 +420,32 @@ Event.addRoutine(function()
|
||||
if not neural or not neural[inv] then
|
||||
_G._debug('missing Introspection module')
|
||||
elseif config.server and (config.useShield or config.slot) then
|
||||
local method = neural[inv]
|
||||
local item = method and method().getItemMeta(config.useShield and SHIELD_SLOT or config.slot)
|
||||
if item then
|
||||
local slotNo = config.useShield and 'shield' or config.slot
|
||||
local response = page:sendRequest({
|
||||
request = 'deposit',
|
||||
slot = slotNo,
|
||||
count = item.count,
|
||||
key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
})
|
||||
if response then
|
||||
local ritem = page.items[response.key]
|
||||
if ritem then
|
||||
ritem.count = response.current + item.count
|
||||
local s, m = pcall(function()
|
||||
local method = neural[inv]
|
||||
local item = method and method().getItemMeta(config.useShield and SHIELD_SLOT or config.slot)
|
||||
if item then
|
||||
local slotNo = config.useShield and 'shield' or config.slot
|
||||
local response = page:sendRequest({
|
||||
request = 'deposit',
|
||||
slot = slotNo,
|
||||
count = item.count,
|
||||
key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
})
|
||||
if response then
|
||||
local ritem = page.items[response.key]
|
||||
if ritem then
|
||||
ritem.count = response.current + item.count
|
||||
end
|
||||
page.grid:draw()
|
||||
page:sync()
|
||||
sleepTime = math.max(sleepTime - .25, .25)
|
||||
end
|
||||
page.grid:draw()
|
||||
page:sync()
|
||||
sleepTime = math.max(sleepTime - .25, .25)
|
||||
else
|
||||
sleepTime = math.min(sleepTime + .25, 1.5)
|
||||
end
|
||||
else
|
||||
sleepTime = math.min(sleepTime + .25, 1.5)
|
||||
end)
|
||||
if not s and m then
|
||||
_debug(m)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -301,8 +301,9 @@ function Milo:saveResources()
|
||||
end
|
||||
|
||||
-- Return a list of everything in the system
|
||||
function Milo:listItems(forceRefresh)
|
||||
return forceRefresh and self.context.storage:refresh() or self.context.storage:listItems()
|
||||
function Milo:listItems(forceRefresh, throttle)
|
||||
return forceRefresh and self.context.storage:refresh(throttle) or
|
||||
self.context.storage:listItems(throttle)
|
||||
end
|
||||
|
||||
return Milo
|
||||
|
||||
@@ -141,6 +141,10 @@ function Storage:onlineAdapters()
|
||||
end
|
||||
end
|
||||
|
||||
function Storage:setDirty()
|
||||
self.dirty = true
|
||||
end
|
||||
|
||||
function Storage:refresh(throttle)
|
||||
self.dirty = true
|
||||
self.lastRefresh = os.clock()
|
||||
|
||||
@@ -140,6 +140,9 @@ end
|
||||
function networkPage:disable()
|
||||
UI.Page.disable(self)
|
||||
Event.off(self.handler)
|
||||
|
||||
-- Since some storage may have been added/removed - force a full rescan
|
||||
context.storage:setDirty()
|
||||
end
|
||||
|
||||
function networkPage:applyFilter()
|
||||
|
||||
@@ -108,6 +108,10 @@ local listingPage = UI.Page {
|
||||
},
|
||||
},
|
||||
notification = UI.Notification(),
|
||||
throttle = UI.Throttle {
|
||||
textColor = colors.yellow,
|
||||
borderColor = colors.gray,
|
||||
},
|
||||
accelerators = {
|
||||
r = 'refresh',
|
||||
[ 'control-r' ] = 'refresh',
|
||||
@@ -240,32 +244,36 @@ function listingPage:eventHandler(event)
|
||||
end
|
||||
|
||||
function listingPage:enable()
|
||||
self:refresh()
|
||||
self:setFocus(self.statusBar.filter)
|
||||
Event.onTimeout(0, function()
|
||||
self:refresh()
|
||||
self:draw()
|
||||
self:sync()
|
||||
|
||||
self.timer = Event.onInterval(3, function()
|
||||
for _,v in pairs(self.allItems) do
|
||||
local c = context.storage.cache[v.key]
|
||||
v.count = c and c.count or 0
|
||||
self.timer = Event.onInterval(3, function()
|
||||
for _,v in pairs(self.allItems) do
|
||||
local c = context.storage.cache[v.key]
|
||||
v.count = c and c.count or 0
|
||||
end
|
||||
self.grid:draw()
|
||||
self:sync()
|
||||
end)
|
||||
|
||||
local function updateStatus()
|
||||
self.statusBar.storageStatus.value =
|
||||
context.storage:isOnline() and '' or 'offline'
|
||||
self.statusBar.storageStatus.textColor =
|
||||
context.storage:isOnline() and colors.lime or colors.red
|
||||
end
|
||||
self.grid:draw()
|
||||
self:sync()
|
||||
end)
|
||||
|
||||
local function updateStatus()
|
||||
self.statusBar.storageStatus.value =
|
||||
context.storage:isOnline() and '' or 'offline'
|
||||
self.statusBar.storageStatus.textColor =
|
||||
context.storage:isOnline() and colors.lime or colors.red
|
||||
end
|
||||
|
||||
self.handler = Event.on({ 'storage_offline', 'storage_online' }, function()
|
||||
updateStatus()
|
||||
self.statusBar.storageStatus:draw()
|
||||
self:sync()
|
||||
|
||||
self.handler = Event.on({ 'storage_offline', 'storage_online' }, function()
|
||||
updateStatus()
|
||||
self.statusBar.storageStatus:draw()
|
||||
self:sync()
|
||||
end)
|
||||
end)
|
||||
|
||||
updateStatus()
|
||||
self:setFocus(self.statusBar.filter)
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
@@ -276,8 +284,12 @@ function listingPage:disable()
|
||||
end
|
||||
|
||||
function listingPage:refresh(force)
|
||||
self.allItems = Milo:mergeResources(Milo:listItems(force))
|
||||
local throttle = function() self.throttle:update() end
|
||||
|
||||
self.throttle:enable()
|
||||
self.allItems = Milo:mergeResources(Milo:listItems(force, throttle))
|
||||
self:applyFilter()
|
||||
self.throttle:disable()
|
||||
end
|
||||
|
||||
function listingPage:applyFilter()
|
||||
|
||||
Reference in New Issue
Block a user