Use ScrollingGrid component for gpsServer

This commit is contained in:
xAnavrins
2019-07-14 01:38:07 -04:00
parent a79e79db28
commit f51b286f2b

View File

@@ -1,6 +1,8 @@
local Config = require('opus.config') local Config = require('opus.config')
local GPS = require('opus.gps') local GPS = require('opus.gps')
local Util = require('opus.util') local Util = require('opus.util')
local UI = require('opus.ui')
local Event = require('opus.event')
local args = { ... } local args = { ... }
local colors = _G.colors local colors = _G.colors
@@ -21,6 +23,19 @@ local STARTUP_FILE = 'usr/autorun/gpsServer.lua'
local positions = { } local positions = { }
local page = UI.Page {
grid = UI.ScrollingGrid {
sortColumn = 'id',
autospace = true,
columns = {
{ heading = 'ID', key = 'id', align = 'right', width = 5 },
{ heading = 'X', key = 'x' },
{ heading = 'Y', key = 'y' },
{ heading = 'Z', key = 'z' },
},
}
}
local function build() local function build()
if not turtle.has(WIRED_MODEM, 5) or if not turtle.has(WIRED_MODEM, 5) or
not turtle.has(CABLE, 8) or not turtle.has(CABLE, 8) or
@@ -152,33 +167,31 @@ local function server()
if #computer == 4 then if #computer == 4 then
local pt = GPS.trilaterate(computer) local pt = GPS.trilaterate(computer)
if pt then if pt then
pt.id = computerId
positions[computerId] = pt positions[computerId] = pt
term.clear()
for k,v in pairs(positions) do
Util.print('ID: %d: %s %s %s', k, v.x, v.y, v.z)
end
end end
computers[computerId] = nil computers[computerId] = nil
page.grid.values = positions
page.grid:update()
page.grid:draw()
page.grid:sync()
end end
end end
while true do Event.on('modem_message', function(e, side, channel, computerId, message, distance)
local e, side, channel, computerId, message, distance = os.pullEvent( "modem_message" ) if distance and modems[side] then
if e == "modem_message" then if channel == gps.CHANNEL_GPS and message == "PING" then
if distance and modems[side] then for _, modem in pairs(modems) do
if channel == gps.CHANNEL_GPS and message == "PING" then modem.transmit(computerId, gps.CHANNEL_GPS, { modem.x, modem.y, modem.z })
for _, modem in pairs(modems) do
modem.transmit(computerId, gps.CHANNEL_GPS, { modem.x, modem.y, modem.z })
end
getPosition(computerId, modems[side], distance)
end end
getPosition(computerId, modems[side], distance)
--if channel == gps.CHANNEL_GPS or channel == 999 then
-- getPosition(computerId, modems[side], distance)
--end
end end
--if channel == gps.CHANNEL_GPS or channel == 999 then
-- getPosition(computerId, modems[side], distance)
--end
end end
end end)
end end
if args[1] == 'build' then if args[1] == 'build' then
@@ -199,3 +212,6 @@ else
error('Syntax: gpsServer [build | server]') error('Syntax: gpsServer [build | server]')
end end
UI:setPage(page)
UI:pullEvents()