From 7f458484b6405fabb5b828046b97fea212dd14a8 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 17 Dec 2018 00:30:38 -0500 Subject: [PATCH] entities - display on overlay --- neural/Entities.lua | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/neural/Entities.lua b/neural/Entities.lua index e14c5cd..6c410bf 100644 --- a/neural/Entities.lua +++ b/neural/Entities.lua @@ -1,24 +1,28 @@ +local Config = require('config') local Event = require('event') local Project = require('neural.project') local UI = require('ui') local Util = require('util') -local device = _G.device +local device = _G.device +local peripheral = _G.peripheral local ni = device.neuralInterface -local sensor = ni or device['plethora:sensor'] +local sensor = ni or device['plethora:sensor'] or peripheral.find('manipulator') if not sensor or not sensor.sense then error('Plethora sensor must be equipped') end -local canvas = ni.canvas() -canvas.clear() - -Project:init(canvas) - UI:configure('Entities', ...) +local config = Config.load('Entities', { }) + local page = UI.Page { + menuBar = UI.MenuBar { + buttons = { + { text = 'Project', event = 'project' }, + }, + }, grid = UI.ScrollingGrid { columns = { { heading = 'Name', key = 'displayName' }, @@ -45,6 +49,14 @@ end function page:eventHandler(event) if event.type == 'quit' then Event.exitPullEvents() + elseif event.type == 'project' then + config.projecting = not config.projecting + if config.projecting then + Project:init(ni.canvas()) + else + Project.canvas:clear() + end + Config.update('Entities', config) end UI.Page.eventHandler(self, event) end @@ -54,15 +66,23 @@ Event.onInterval(.5, function() local meta = ni.getMetaOwner() Util.filterInplace(entities, function(e) return e.id ~= meta.id end) - canvas:clear() - Project:drawPoints(meta, entities, 'X', 0xFFDF50AA) + if config.projecting then + Project.canvas:clear() + Project:drawPoints(meta, entities, 'X', 0xFFDF50AA) + end page.grid:setValues(entities) page.grid:draw() page:sync() end) +if config.projecting then + Project:init(ni.canvas()) +end + UI:setPage(page) UI:pullEvents() -canvas:clear() +if config.projecting then + Project.canvas:clear() +end