milo wip
This commit is contained in:
@@ -106,6 +106,7 @@ local page = UI.Page {
|
|||||||
q = 'quit',
|
q = 'quit',
|
||||||
},
|
},
|
||||||
displayMode = 0,
|
displayMode = 0,
|
||||||
|
items = { },
|
||||||
}
|
}
|
||||||
|
|
||||||
local function filterItems(t, filter, displayMode)
|
local function filterItems(t, filter, displayMode)
|
||||||
@@ -137,7 +138,6 @@ end
|
|||||||
function page:sendRequest(data)
|
function page:sendRequest(data)
|
||||||
local response
|
local response
|
||||||
|
|
||||||
debug(data)
|
|
||||||
sync(self, function()
|
sync(self, function()
|
||||||
self:sync()
|
self:sync()
|
||||||
local msg
|
local msg
|
||||||
@@ -146,6 +146,7 @@ debug(data)
|
|||||||
self:setStatus('connecting ...')
|
self:setStatus('connecting ...')
|
||||||
socket, msg = Socket.connect(options.server.value, 4242)
|
socket, msg = Socket.connect(options.server.value, 4242)
|
||||||
if socket then
|
if socket then
|
||||||
|
self:setStatus('connected ...')
|
||||||
socket:write(options.user.value)
|
socket:write(options.user.value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -163,8 +164,11 @@ debug(data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:setStatus(msg or 'Failed to connect')
|
self:setStatus(msg or 'Failed to connect')
|
||||||
|
Event.onTimeout(2, function()
|
||||||
|
self:setStatus('')
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
debug('got response')
|
|
||||||
return response
|
return response
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -196,28 +200,32 @@ function page:eventHandler(event)
|
|||||||
if item then
|
if item then
|
||||||
self:setStatus('requesting 1 ...')
|
self:setStatus('requesting 1 ...')
|
||||||
local response = self:sendRequest({ request = 'transfer', item = item, count = 1 })
|
local response = self:sendRequest({ request = 'transfer', item = item, count = 1 })
|
||||||
item.count = response.count
|
if response then
|
||||||
self.grid:draw()
|
item.count = response.count
|
||||||
|
self.grid:draw()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'eject_stack' then
|
elseif event.type == 'eject_stack' then
|
||||||
local item = self.grid:getSelected()
|
local item = self.grid:getSelected()
|
||||||
if item then
|
if item then
|
||||||
self:setStatus('requesting stack ...')
|
self:setStatus('requesting stack ...')
|
||||||
-- TODO: send a stack request - have server figure out stack size
|
local response = self:sendRequest({ request = 'transfer', item = item, count = 'stack' })
|
||||||
local response = self:sendRequest({ request = 'transfer', item = item, count = 64 })
|
if response then
|
||||||
item.count = response.count
|
item.count = response.count
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'eject_all' then
|
elseif event.type == 'eject_all' then
|
||||||
local item = self.grid:getSelected()
|
local item = self.grid:getSelected()
|
||||||
if item then
|
if item then
|
||||||
self:setStatus('requesting all ...')
|
self:setStatus('requesting all ...')
|
||||||
-- TODO: let server figure out count
|
local response = self:sendRequest({ request = 'transfer', item = item, count = 'all' })
|
||||||
local response = self:sendRequest({ request = 'transfer', item = item, count = item.count })
|
if response then
|
||||||
item.count = response.count
|
item.count = response.count
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'eject_specified' then
|
elseif event.type == 'eject_specified' then
|
||||||
@@ -235,10 +243,10 @@ function page:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'refresh' then
|
elseif event.type == 'refresh' then
|
||||||
|
self:setFocus(self.statusBar.filter)
|
||||||
self:setStatus('updating ...')
|
self:setStatus('updating ...')
|
||||||
self:refresh()
|
self:refresh()
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
self:setFocus(self.statusBar.filter)
|
|
||||||
|
|
||||||
elseif event.type == 'toggle_display' then
|
elseif event.type == 'toggle_display' then
|
||||||
local values = {
|
local values = {
|
||||||
@@ -268,9 +276,13 @@ function page:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function page:enable()
|
function page:enable()
|
||||||
self:refresh()
|
|
||||||
self:setFocus(self.statusBar.filter)
|
self:setFocus(self.statusBar.filter)
|
||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
|
Event.onTimeout(.1, function()
|
||||||
|
self:refresh()
|
||||||
|
self.grid:draw()
|
||||||
|
self:sync()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:refresh()
|
function page:refresh()
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ function Milo:xxx(item, count)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Milo:provideItem(item, count, callback)
|
function Milo:provideItem(item, count, callback)
|
||||||
|
if count <= 0 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
local current = Milo:getItem(Milo:listItems(), item) or { count = 0 }
|
local current = Milo:getItem(Milo:listItems(), item) or { count = 0 }
|
||||||
local toCraft = count - math.min(current.count, count)
|
local toCraft = count - math.min(current.count, count)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local Socket = require('socket')
|
local Socket = require('socket')
|
||||||
|
|
||||||
@@ -59,7 +60,16 @@ debug('remote: ' .. data.request)
|
|||||||
Milo:clearGrid()
|
Milo:clearGrid()
|
||||||
|
|
||||||
elseif data.request == 'transfer' then
|
elseif data.request == 'transfer' then
|
||||||
local count = Milo:provideItem(data.item, data.count, function(amount, currentCount)
|
local count = data.count
|
||||||
|
|
||||||
|
if count == 'stack' then
|
||||||
|
count = itemDB:getMaxCount(data.item)
|
||||||
|
elseif count == 'all' then
|
||||||
|
local item = Milo:getItem(Milo:listItems(), data.item)
|
||||||
|
count = item and item.count or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local provided = Milo:provideItem(data.item, count, function(amount, currentCount)
|
||||||
amount = context.storage:export(
|
amount = context.storage:export(
|
||||||
context.localName,
|
context.localName,
|
||||||
nil,
|
nil,
|
||||||
@@ -75,7 +85,7 @@ debug('remote: ' .. data.request)
|
|||||||
return currentCount - amount
|
return currentCount - amount
|
||||||
end)
|
end)
|
||||||
|
|
||||||
socket:write({ count = count })
|
socket:write({ count = provided })
|
||||||
end
|
end
|
||||||
until not socket.connected
|
until not socket.connected
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user