Add auto-updating address list

This commit is contained in:
2026-01-01 21:40:37 -05:00
parent fed51c6b07
commit 458f1ecd6f
3 changed files with 93 additions and 20 deletions

View File

@ -10,6 +10,7 @@ local mon
local config
local addresses
local utils
local localGateAddress
-- State variables
local buttonXY = {}
@ -17,11 +18,12 @@ local computerAddresses = {}
local computerNames = {}
local x, y = 0, 0
function display.init(monitor, cfg, addr, utilsModule)
function display.init(monitor, cfg, addr, utilsModule, localAddr)
mon = monitor
config = cfg
addresses = addr
utils = utilsModule
localGateAddress = localAddr
end
function display.getButtonData()
@ -67,29 +69,49 @@ end
function display.screenWrite(list, fcount, fy)
for i = 1, #list do
local x1, x2 = 0, 0
local entryAddress = list[i][2]
if fcount == 0 then
x = 2
fcount = 1
elseif fcount == 1 then
x = 11
fcount = 2
else
x = 20
fcount = 0
fy = fy + 2
-- Skip this entry if it matches local gate address
local isLocalGate = false
if localGateAddress and entryAddress then
-- Compare addresses (excluding point of origin which is last element)
if #localGateAddress == #entryAddress then
isLocalGate = true
for j = 1, #localGateAddress - 1 do -- Skip last element (point of origin)
if localGateAddress[j] ~= entryAddress[j] then
isLocalGate = false
break
end
end
end
end
mon.setCursorPos(x, fy)
mon.write(list[i][1])
-- Skip if this is the local gate
if not isLocalGate then
local x1, x2 = 0, 0
x1 = x
x2 = x + 7
if fcount == 0 then
x = 2
fcount = 1
elseif fcount == 1 then
x = 11
fcount = 2
else
x = 20
fcount = 0
fy = fy + 2
end
table.insert(buttonXY, { x1, x2, fy })
table.insert(computerNames, list[i][1])
table.insert(computerAddresses, list[i][2])
mon.setCursorPos(x, fy)
mon.write(list[i][1])
x1 = x
x2 = x + 7
table.insert(buttonXY, { x1, x2, fy })
table.insert(computerNames, list[i][1])
table.insert(computerAddresses, list[i][2])
end
end
local oldterm = term.redirect(mon)