From 22f0d73184b9c349537ac5469f95046171b7a1ae Mon Sep 17 00:00:00 2001 From: hkc Date: Thu, 12 Oct 2023 21:25:20 +0300 Subject: [PATCH] Entities in frames now? --- augment/main.lua | 5 ++--- augment/modules/event.lua | 2 -- augment/modules/wh.lua | 34 ++++++++++++++++++++-------------- augment/startup.lua | 2 -- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/augment/main.lua b/augment/main.lua index f52f2f8..6a2c444 100644 --- a/augment/main.lua +++ b/augment/main.lua @@ -1,4 +1,3 @@ --- x-run: scp -r ./* pneumatic-pump:htdocs/cc/augment/ _G.NI = peripheral.wrap("back") _G._running = true @@ -9,7 +8,7 @@ _G.canvas3d_src.clear() _G.canvas3d = canvas3d_src.create() _G.player = nil -_G.entities = {} +_G.nearbyEntities = {} local function run_wrapped(func, filename) return function() @@ -72,7 +71,7 @@ function() -- Neural Interface coroutine print("NI routine started") while _G._running do _G.player = safeset(NI.getMetaOwner, "getMetaOwner()", _G.player) - _G.entities = safeset(NI.sense, "sense()", _G.entities) + _G.nearbyEntities = safeset(NI.sense, "sense()", _G.entities) _G.canvas3d.recenter() os.sleep(0.05) end diff --git a/augment/modules/event.lua b/augment/modules/event.lua index 44e9ad0..f984e2c 100644 --- a/augment/modules/event.lua +++ b/augment/modules/event.lua @@ -1,5 +1,3 @@ --- x-run: cd .. && scp -r ./* pneumatic-pump:htdocs/cc/augment/ - return function() while _G._running do local ev = { os.pullEvent() } diff --git a/augment/modules/wh.lua b/augment/modules/wh.lua index b170b4c..2d7434f 100644 --- a/augment/modules/wh.lua +++ b/augment/modules/wh.lua @@ -1,23 +1,29 @@ --- x-run: cd .. && scp -r ./* pneumatic-pump:htdocs/cc/augment/ - return function() - local cubes = {} + local cache = {} while _G._running do - local el = entities - for i, cube in ipairs(cubes) do + local el = _G.nearbyEntities + for i, entry in ipairs(cache) do if el[i] == nil then - cube.setSize(0.0, 0.0, 0.0) - print("entity box "..tostring(i).." unused") + entry.cube.setSize(0.0, 0.0, 0.0) + entry.frame.setAlpha(0x00) end end - for i, entity in ipairs(entities) do - if cubes[i] == nil then - cubes[i] = canvas3d.addBox(0, 0, 0) - cubes[i].setDepthTested(false) - print("Created cube for entity "..entity.name) + for i, entity in ipairs(nearbyEntities) do + if cache[i] == nil then + cache[i] = {} + cache[i].cube = canvas3d.addBox(0, 0, 0) + cache[i].frame = canvas3d.addFrame(0, 0, 0) + cache[i].text = cache[i].frame.addText({ 0, 0 }, "") + + cache[i].cube.setDepthTested(false) + cache[i].frame.setDepthTested(false) end - cubes[i].setPosition(entity.x, entity.y, entity.z) - cubes[i].setSize(0.25, 0.25, 0.25) + + cache[i].cube.setPosition(entity.x, entity.y, entity.z) + cache[i].frame.setPosition(entity.x, entity.y, entity.z) + cache[i].frame.setAlpha(0xFF) + cache[i].text.setText(entity.name) + cache[i].text.setColor(0xFF0000FF) end os.sleep(0.05) end diff --git a/augment/startup.lua b/augment/startup.lua index 2accb1d..71abaf7 100644 --- a/augment/startup.lua +++ b/augment/startup.lua @@ -1,5 +1,3 @@ --- x-run: scp ./* pneumatic-pump:htdocs/cc/augment/ - local repository = "https://git.salushnes.solutions/hkc/cc-stuff/raw/branch/master/augment/files.json" local files = textutils.unserializeJSON(http.get(repository).readAll())