update scanner
This commit is contained in:
@@ -5,7 +5,6 @@ local Util = require('util')
|
|||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local gps = _G.gps
|
local gps = _G.gps
|
||||||
local parallel = _G.parallel
|
|
||||||
|
|
||||||
local glasses = device['plethora:glasses']
|
local glasses = device['plethora:glasses']
|
||||||
local scanner = device['plethora:scanner'] or
|
local scanner = device['plethora:scanner'] or
|
||||||
@@ -25,7 +24,6 @@ end
|
|||||||
|
|
||||||
local offset = getPoint()
|
local offset = getPoint()
|
||||||
local canvas = glasses and glasses.canvas3d().create()
|
local canvas = glasses and glasses.canvas3d().create()
|
||||||
--{ -(offset.x % 1), -(offset.y % 1), -(offset.z % 1) }
|
|
||||||
|
|
||||||
UI:configure('Scanner', ...)
|
UI:configure('Scanner', ...)
|
||||||
|
|
||||||
@@ -33,7 +31,6 @@ local page = UI.Page {
|
|||||||
menuBar = UI.MenuBar {
|
menuBar = UI.MenuBar {
|
||||||
buttons = {
|
buttons = {
|
||||||
{ text = 'Scan', event = 'scan' },
|
{ text = 'Scan', event = 'scan' },
|
||||||
{ text = 'Totals', event = 'totals' },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
@@ -50,12 +47,11 @@ local page = UI.Page {
|
|||||||
detail = UI.SlideOut {
|
detail = UI.SlideOut {
|
||||||
menuBar = UI.MenuBar {
|
menuBar = UI.MenuBar {
|
||||||
buttons = {
|
buttons = {
|
||||||
{ text = 'Projector', event = 'project' },
|
|
||||||
{ text = 'Cancel', event = 'cancel' },
|
{ text = 'Cancel', event = 'cancel' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 2, ey = -2,
|
y = 2,
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = 'Name', key = 'name' },
|
{ heading = 'Name', key = 'name' },
|
||||||
{ heading = 'Dmg', key = 'metadata', width = 3 },
|
{ heading = 'Dmg', key = 'metadata', width = 3 },
|
||||||
@@ -114,15 +110,6 @@ function page.detail:show(blocks, entry)
|
|||||||
return UI.SlideOut.show(self)
|
return UI.SlideOut.show(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.detail:eventHandler(event)
|
|
||||||
if event.type == 'grid_select' then
|
|
||||||
target = event.selected
|
|
||||||
else
|
|
||||||
return UI.SlideOut.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
if event.type == 'quit' then
|
if event.type == 'quit' then
|
||||||
Event.exitPullEvents()
|
Event.exitPullEvents()
|
||||||
@@ -131,6 +118,7 @@ function page:eventHandler(event)
|
|||||||
self:scan()
|
self:scan()
|
||||||
|
|
||||||
elseif event.type == 'grid_select' then
|
elseif event.type == 'grid_select' then
|
||||||
|
target = self.grid:getSelected()
|
||||||
self.detail:show(self.blocks, self.grid:getSelected())
|
self.detail:show(self.blocks, self.grid:getSelected())
|
||||||
|
|
||||||
elseif event.type == 'cancel' then
|
elseif event.type == 'cancel' then
|
||||||
@@ -148,22 +136,16 @@ end
|
|||||||
if canvas then
|
if canvas then
|
||||||
Event.onInterval(.5, function()
|
Event.onInterval(.5, function()
|
||||||
if target then
|
if target then
|
||||||
local pos, scanned
|
local scanned = scanner.scan()
|
||||||
|
local pos = getPoint()
|
||||||
|
|
||||||
parallel.waitForAll(
|
|
||||||
function()
|
|
||||||
pos = getPoint()
|
|
||||||
end,
|
|
||||||
function()
|
|
||||||
scanned = scanner.scan()
|
|
||||||
end
|
|
||||||
)
|
|
||||||
local blocks = Util.reduce(scanned, function(acc, b)
|
local blocks = Util.reduce(scanned, function(acc, b)
|
||||||
if b.name == target.name and b.metadata == target.metadata then
|
if b.name == target.name and b.metadata == target.damage then
|
||||||
b.wx = math.floor(pos.x + b.x)
|
-- track block's world position
|
||||||
b.wy = math.floor(pos.y + b.y)
|
b.id = table.concat({
|
||||||
b.wz = math.floor(pos.z + b.z)
|
math.floor(pos.x + b.x),
|
||||||
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':')
|
math.floor(pos.y + b.y),
|
||||||
|
math.floor(pos.z + b.z) }, ':')
|
||||||
acc[b.id] = b
|
acc[b.id] = b
|
||||||
end
|
end
|
||||||
return acc
|
return acc
|
||||||
@@ -183,21 +165,21 @@ if canvas then
|
|||||||
|
|
||||||
for _, b in pairs(projecting) do
|
for _, b in pairs(projecting) do
|
||||||
if not blocks[b.id] then
|
if not blocks[b.id] then
|
||||||
projecting[b.id].box.remove()
|
b.box.remove()
|
||||||
projecting[b.id] = nil
|
projecting[b.id] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- canvas.recenter({
|
|
||||||
-- offset.x - pos.x,
|
|
||||||
-- offset.y - pos.y,
|
|
||||||
-- offset.z - pos.z,
|
|
||||||
-- })
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
|
|
||||||
|
Event.onTimeout(0, function()
|
||||||
|
page:scan()
|
||||||
|
page:sync()
|
||||||
|
end)
|
||||||
|
|
||||||
UI:pullEvents()
|
UI:pullEvents()
|
||||||
|
|
||||||
if canvas then
|
if canvas then
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
-- Bram S. (a.k.a ThatBram0101, bram0101)
|
-- Bram S. (a.k.a ThatBram0101, bram0101)
|
||||||
-- see: https://energetic.pw/computercraft/ore3d/assets/ore3d.lua
|
-- see: https://energetic.pw/computercraft/ore3d/assets/ore3d.lua
|
||||||
|
|
||||||
-- Updated to use canvas3d (which was not available when original was made)
|
-- Updated to use new(ish) canvas3d
|
||||||
|
|
||||||
local gps = _G.gps
|
local gps = _G.gps
|
||||||
local keys = _G.keys
|
local keys = _G.keys
|
||||||
@@ -11,13 +11,32 @@ local os = _G.os
|
|||||||
local parallel = _G.parallel
|
local parallel = _G.parallel
|
||||||
local peripheral = _G.peripheral
|
local peripheral = _G.peripheral
|
||||||
|
|
||||||
|
local function showRequirements(missing)
|
||||||
|
print([[A neural interface is required containing:
|
||||||
|
* Overlay glasses
|
||||||
|
* Scanner
|
||||||
|
]])
|
||||||
|
error('Missing: ' .. missing)
|
||||||
|
end
|
||||||
|
|
||||||
local modules = peripheral.find('neuralInterface')
|
local modules = peripheral.find('neuralInterface')
|
||||||
if not modules then
|
if not modules then
|
||||||
error('Plethora scanner must be equipped')
|
showRequirements('Neural interface')
|
||||||
elseif not modules.canvas then
|
elseif not modules.canvas then
|
||||||
error('Overlay glasses module is required')
|
showRequirements('Overlay glasses')
|
||||||
elseif not modules.scan then
|
elseif not modules.scan then
|
||||||
error('Scanner module is required')
|
showRequirements('Scanner module')
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getPoint()
|
||||||
|
local pt = { gps.locate() }
|
||||||
|
if pt[1] then
|
||||||
|
return {
|
||||||
|
x = pt[1],
|
||||||
|
y = pt[2],
|
||||||
|
z = pt[3],
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local targets = {
|
local targets = {
|
||||||
@@ -34,22 +53,10 @@ local targets = {
|
|||||||
["minecraft:glowstone"] = 0xFFDFA166
|
["minecraft:glowstone"] = 0xFFDFA166
|
||||||
}
|
}
|
||||||
local projecting = { }
|
local projecting = { }
|
||||||
|
|
||||||
local function getPoint()
|
|
||||||
local pt = { gps.locate() }
|
|
||||||
if pt[1] then
|
|
||||||
return {
|
|
||||||
x = pt[1],
|
|
||||||
y = pt[2],
|
|
||||||
z = pt[3],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local offset = getPoint() or error('GPS not found')
|
local offset = getPoint() or error('GPS not found')
|
||||||
local canvas = modules.canvas3d().create()
|
local canvas = modules.canvas3d().create()
|
||||||
|
|
||||||
local function run()
|
local function update()
|
||||||
while true do
|
while true do
|
||||||
-- order matters
|
-- order matters
|
||||||
local scanned = modules.scan()
|
local scanned = modules.scan()
|
||||||
@@ -114,7 +121,7 @@ parallel.waitForAny(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
run
|
update
|
||||||
)
|
)
|
||||||
|
|
||||||
canvas.clear()
|
canvas.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user