changes for deprecated ui methods - recolor milo - make turtle scripts run again - mob rancher improvements

This commit is contained in:
kepler155c@gmail.com
2020-04-17 20:41:58 -06:00
parent 3246579ab1
commit 949c485539
39 changed files with 258 additions and 122 deletions

View File

@@ -354,7 +354,7 @@ function categoryPage:eventHandler(event)
self:draw()
elseif event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
else
return UI.Page.eventHandler(self, event)
@@ -366,4 +366,4 @@ print("Retrieving catalog list")
categoryPage:setCategory(source.name, source.index)
UI:setPage(categoryPage)
UI:pullEvents()
UI:start()

View File

@@ -49,7 +49,7 @@ end
function peripheralsPage:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:quit()
elseif event.type == 'grid_select' then
UI:setPage('methods', event.selected)
@@ -198,4 +198,4 @@ UI:setPages({
methods = methodsPage,
})
UI:pullEvents()
UI:start()

View File

@@ -269,4 +269,4 @@ Event.onTimeout(.2, function()
end)
UI:setPage(page)
UI:pullEvents()
UI:start()

View File

@@ -90,7 +90,7 @@ local page = UI.Page {
self.grid:draw()
elseif event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
else
return UI.Page.eventHandler(self, event)

View File

@@ -238,6 +238,6 @@ Event.addRoutine(function()
end)
UI:setPage(page)
UI:pullEvents()
UI:start()
swarm:stop()

View File

@@ -60,4 +60,4 @@ function page:eventHandler(event)
end
UI:setPage(page)
UI:pullEvents()
UI:start()

View File

@@ -292,30 +292,42 @@ function page:runScript(scriptName)
print('Unable to read script file')
end
local socket = Socket.connect(turtle.id, 161)
if not socket then
print('Unable to connect to ' .. turtle.id)
return
end
local function processVariables(script)
local function processVariables()
local variables = {
COMPUTER_ID = os.getComputerID(),
COMPUTER_ID = os.getComputerID,
GPS = function()
local pt = require('opus.gps').getPoint()
if not pt then
error('Unable to determine location')
end
return _G.textutils.serialize(pt)
end,
}
for k,v in pairs(variables) do
local token = string.format('{%s}', k)
script = script:gsub(token, v)
if script:find(token, 1, true) then
local s, m = pcall(v)
if not s then
self.notification:error(m)
return
end
script = script:gsub(token, m)
end
end
return script
return true
end
script = processVariables(script)
if processVariables(script) then
local socket = Socket.connect(turtle.id, 161)
if not socket then
self.notification:error('Unable to connect')
return
end
socket:write({ type = 'script', args = script })
socket:close()
socket:write({ type = 'script', args = script })
socket:close()
self.notification:success('Sent')
self.notification:success('Sent')
end
end
end
@@ -339,7 +351,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
elseif event.type == 'tab_select' then
config.tab = event.button.text

View File

@@ -1,29 +0,0 @@
turtle.run(function()
_G.requireInjector(_ENV)
local GPS = require('opus.gps')
local Socket = require('opus.socket')
local id = {COMPUTER_ID}
if not turtle.enableGPS() then
error('turtle: No GPS found')
end
local socket = Socket.connect(id, 161)
if not socket then
error('turtle: Unable to connect to ' .. id)
end
socket:write({ type = 'gps' })
local pt = socket:read(3)
if not pt then
error('turtle: No GPS response')
end
if not turtle.pathfind(pt) then
error('Unable to go to location')
end
end)

View File

@@ -0,0 +1,17 @@
local turtle = _G.turtle
turtle.run(function()
_G.requireInjector(_ENV)
local GPS = require('opus.gps')
if not turtle.enableGPS() then
error('turtle: No GPS found')
end
local pt = {GPS}
if not turtle.pathfind(pt) then
error('Unable to go to location')
end
end)