turtle gps rework

This commit is contained in:
kepler155c@gmail.com
2019-02-22 03:53:40 -05:00
parent 70a3bd1166
commit f37dac0c79
11 changed files with 195 additions and 139 deletions

View File

@@ -5,13 +5,11 @@ local fs = _G.fs
local turtle = _G.turtle
if turtle then
local Home = require('turtle.home')
local values = { }
Config.load('gps', values.home and { values.home } or { })
local config = Config.load('gps')
local gpsTab = UI.Tab {
tabTitle = 'GPS',
tabTitle = 'Home',
description = 'Turtle home location',
labelText = UI.Text {
x = 3, y = 2,
value = 'On restart, return to this location'
@@ -19,7 +17,7 @@ if turtle then
grid = UI.Grid {
x = 3, ex = -3, y = 4,
height = 2,
values = values,
values = { config.home or { } },
inactive = true,
columns = {
{ heading = 'x', key = 'x' },
@@ -37,24 +35,41 @@ if turtle then
text = 'Clear',
event = 'gps_clear',
},
breakingText = UI.Text {
x = 3, y = 9,
value = 'Can break blocks',
},
breaking = UI.Checkbox {
x = 20, y = 9,
value = config.destructive,
},
}
function gpsTab:eventHandler(event)
if event.type == 'gps_set' then
self:emit({ type = 'info_message', message = 'Determining location' })
self:sync()
if Home.set() then
Config.load('gps', values)
self.grid:setValues(values.home and { values.home } or { })
local pt = turtle.enableGPS()
if pt then
config.home = pt
Config.update('gps', config)
self.grid:setValues({ config.home })
self.grid:draw()
self:emit({ type = 'success_message', message = 'Location set' })
else
self:emit({ type = 'error_message', message = 'Unable to determine location' })
end
return true
elseif event.type == 'checkbox_change' then
config.destructive = event.checked
Config.update('gps', config)
elseif event.type == 'gps_clear' then
fs.delete('usr/config/gps')
self.grid:setValues({ })
self.grid:draw()
self.breaking:reset()
self:draw()
return true
end
end