1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-20 18:27:40 +00:00

Replace process.api with Event

This commit is contained in:
kepler155c@gmail.com
2017-07-28 19:01:59 -04:00
parent f8bcf90a6b
commit be51935662
21 changed files with 326 additions and 343 deletions

View File

@@ -103,7 +103,7 @@ function page.grid:draw()
UI.Grid.draw(self)
end
function eventLoop()
Event.addRoutine(function()
while true do
local e = { os.pullEvent() }
@@ -124,8 +124,7 @@ function eventLoop()
page:sync()
end
end
end
end)
UI:setPage(page)
Event.pullEvents(eventLoop)
UI.term:reset()
UI:pullEvents()

View File

@@ -50,9 +50,11 @@ function page:eventHandler(event)
Event.exitPullEvents()
elseif event.type == 'key' and event.key == 'enter' then
showHelp(self.grid:getSelected().name)
self:setFocus(self.filter)
self:draw()
if self.grid:getSelected() then
showHelp(self.grid:getSelected().name)
self:setFocus(self.filter)
self:draw()
end
elseif event.type == 'grid_select' then
showHelp(event.selected.name)
@@ -80,5 +82,4 @@ function page:eventHandler(event)
end
UI:setPage(page)
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@@ -141,5 +141,4 @@ if not device.wireless_modem then
end
UI:setPage(page)
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@@ -476,7 +476,7 @@ UI:setPages({
main = page,
})
Event.addHandler('os_register_app', function()
Event.on('os_register_app', function()
loadApplications()
page:refresh()
page:draw()

View File

@@ -201,11 +201,11 @@ function methodsPage.viewportConsole:draw()
c.ymax = c.cursorY + 1
end
Event.addHandler('peripheral', function()
Event.on('peripheral', function()
peripheralsPage:updatePeripherals()
end)
Event.addHandler('peripheral_detach', function()
Event.on('peripheral_detach', function()
peripheralsPage:updatePeripherals()
end)
@@ -215,5 +215,4 @@ UI:setPages({
methods = methodsPage,
})
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@@ -62,12 +62,11 @@ function page.grid:getDisplayValues(row)
return row
end
Event.addTimer(1, true, function()
Event.onInterval(1, function()
page.grid:update()
page.grid:draw()
page:sync()
end)
UI:setPage(page)
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@@ -1,4 +1,5 @@
require = requireInjector(getfenv(1))
local Event = require('event')
local UI = require('ui')
local Socket = require('socket')
local Terminal = require('terminal')
@@ -320,20 +321,6 @@ function page:enable()
-- self.tabs:activateTab(page.tabs.turtles)
end
local function updateThread()
while true do
if page.turtle then
local t = _G.network[page.turtle.id]
page.turtle = t
page:draw()
page:sync()
end
os.sleep(1)
end
end
if not Util.getOptions(options, { ... }, true) then
return
end
@@ -348,9 +335,17 @@ if options.turtle.value >= 0 then
end
end
Event.onInterval(1, function()
if page.turtle then
local t = _G.network[page.turtle.id]
page.turtle = t
page:draw()
page:sync()
end
end)
UI:setPage(page)
page.tabs:activateTab(page.tabs[options.tab.value])
UI:pullEvents(updateThread)
UI.term:reset()
UI:pullEvents()

View File

@@ -475,7 +475,7 @@ function Builder:getSupplies()
return t
end
Event.addHandler('build', function()
Event.on('build', function()
Builder:build()
end)

View File

@@ -999,32 +999,29 @@ jobMonitor()
jobListGrid:draw()
jobListGrid:sync()
local function craftingThread()
Event.onInterval(5, function()
while true do
os.sleep(5)
if not craftingPaused then
local items = chestProvider:listItems()
if Util.size(items) == 0 then
jobListGrid.parent:clear()
jobListGrid.parent:centeredWrite(math.ceil(jobListGrid.parent.height/2), 'No items in system')
jobListGrid:sync()
if not craftingPaused then
local items = chestProvider:listItems()
if Util.size(items) == 0 then
jobListGrid.parent:clear()
jobListGrid.parent:centeredWrite(math.ceil(jobListGrid.parent.height/2), 'No items in system')
jobListGrid:sync()
else
local craftList = watchResources(items)
jobListGrid:setValues(craftList)
--jobListGrid:draw()
--jobListGrid:sync()
craftItems(craftList, items)
jobListGrid:update()
jobListGrid:draw()
jobListGrid:sync()
craftList = getAutocraftItems(items) -- autocrafted items don't show on job monitor
craftItems(craftList, items)
end
else
local craftList = watchResources(items)
jobListGrid:setValues(craftList)
--jobListGrid:draw()
--jobListGrid:sync()
craftItems(craftList, items)
jobListGrid:update()
jobListGrid:draw()
jobListGrid:sync()
craftList = getAutocraftItems(items) -- autocrafted items don't show on job monitor
craftItems(craftList, items)
end
end
end
end)
UI:pullEvents(craftingThread)
UI:pullEvents()
jobListGrid.parent:reset()

View File

@@ -4,7 +4,7 @@ local Socket = require('socket')
local MEProvider = require('meProvider')
local Logger = require('logger')
local Point = require('point')
local process = require('process')
local Event = require('event')
if not device.wireless_modem then
error('Modem is required')
@@ -16,14 +16,6 @@ if not turtle then
error('Can only be run on a turtle')
end
turtle.clearMoveCallback()
local gps = GPS.getPointAndHeading()
if not gps then
error('could not get gps location')
end
turtle.setPoint(gps)
local blocks = { }
local meProvider = MEProvider()
local items = { }
@@ -50,7 +42,7 @@ turtle.setMoveCallback(function(action, pt)
for _,slot in pairs(slots) do
if turtle.getItemCount(slot.index) ~= slot.qty then
printError('Slots changed')
process:terminate()
Event.exitPullEvents()
end
end
end
@@ -109,7 +101,8 @@ function gotoPoint(pt, doDetect)
end
if doDetect and not turtle.detectDown() then
error('Missing target')
printError('Missing target')
Event.exitPullEvents()
end
end
@@ -254,14 +247,14 @@ local function pickupHost(socket)
end
end
process:newThread('pickup', function()
Event.addRoutine(function()
while true do
print('waiting for connection on port 5222')
local socket = Socket.server(5222)
print('pickup: connection from ' .. socket.dhost)
process:newThread('pickup_connection', function() pickupHost(socket) end)
Event.addRoutine(function() pickupHost(socket) end)
end
end)
@@ -304,10 +297,7 @@ local function eachClosestEntry(t, fn)
end
end
refuel()
turtle.abort = false
local deliveryThread = process:newThread('deliveries', function()
Event.addRoutine(function()
while true do
if chestPt then
@@ -327,17 +317,17 @@ local deliveryThread = process:newThread('deliveries', function()
end
os.sleep(60)
end
Event.exitPullEvents()
end)
turtle.run(function()
turtle.run(function()
while true do
local e = process:pullEvent()
if e == 'terminate' or deliveryThread:isDead() then
break
end
if not turtle.enableGPS() then
error('turtle: No GPS found')
end
end)
refuel()
Event.pullEvents()
process:threadEvent('terminate')
end)

View File

@@ -612,7 +612,7 @@ while not bExit do
term.setTextColour(_colors.textColor)
if #sLine > 0 then
local result, err = shell.run( sLine )
if not result then
if not result and err then
printError(err)
end
end

View File

@@ -164,11 +164,10 @@ function changedPage:refresh()
self.grid:draw()
end
Event.addTimer(5, true, function()
Event.onInterval(5, function()
changedPage:refresh()
changedPage:sync()
end)
UI:setPage(changedPage)
UI:pullEvents()
UI.term:reset()

View File

@@ -896,4 +896,4 @@ Event.onInterval(5, function()
end)
UI:pullEvents()
jobListGrid.parent:reset()
jobListGrid.parent:reset()

View File

@@ -375,7 +375,7 @@ Message.addHandler('finished',
Builder:finish()
end)
Event.addHandler('turtle_abort',
Event.on('turtle_abort',
function()
turtle.abort = false
turtle.status = 'aborting'

View File

@@ -30,7 +30,6 @@ end
local w, h = ct.getSize()
socket:write({
type = 'termInfo',
width = w,
height = h,
isColor = ct.isColor(),
@@ -70,7 +69,7 @@ while true do
if filter[event] then
if not socket:write({ type = 'shellRemote', event = e }) then
if not socket:write(e) then
socket:close()
break
end