From 734587569a524d5b2f72aff8718b0d54999eec04 Mon Sep 17 00:00:00 2001 From: CadenCoaster Date: Wed, 22 Oct 2025 14:03:07 -0700 Subject: [PATCH] add wallpaper and mesh routing support --- .wallpaper.nfp | 18 ++++++ apps/launcher.lua | 2 +- modules/entrypointclient.lua | 111 +++++++++++++++++++++++++++++++++++ startup.lua | 8 ++- 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 .wallpaper.nfp create mode 100644 modules/entrypointclient.lua diff --git a/.wallpaper.nfp b/.wallpaper.nfp new file mode 100644 index 0000000..1e65863 --- /dev/null +++ b/.wallpaper.nfp @@ -0,0 +1,18 @@ +0000000000000055555555d0000000000000000000000000000 +00000000055555d00555555d000000000000000000000000000 +000000005555555d00055555d00000000000000000000000000 +0000000055555555d05055555d3d30000000000000033300000 +00000000055555555d05555555d3d3000000000003333300000 +30000000300055555555d555555d3d333333303333333333330 +3303333333353555555d5d555555d3333033333333330330000 +033330303035355555555555555d3d333033033033333300000 +003030333333555ffff555ffff55d3303333333333303300077 +0033333033035555555555555555d3333303330330333000878 +78830333333535555555f555555d3d303333333333037787778 +87844bb0b0bb55b5555555555dbddbbbbbb0bbbb44407878888 +0780044bbbb0bb5b55555555dbdbb0b0bbbbbb4440778888888 +7870040b0b0bbbbb55555555dbbbbbbb0bb0b44407888808888 +78080044bbbbb0bb55555555db0bb0bb0bbbb40077870878087 +78788004bbb0bbb555555555dbbbbbbbbbbb440078788887787 +778788004b0bbbb5555555555dbbbb0bbb04408878888088777 +777888004bbbbb555555555555dbbbbbbbb4008878088878888 diff --git a/apps/launcher.lua b/apps/launcher.lua index e4b08a6..3fdd7a5 100644 --- a/apps/launcher.lua +++ b/apps/launcher.lua @@ -1,7 +1,7 @@ local window = require("libs.window") local threading = require("libs.threading") local x, y = term.getSize() -local win = window.create("Shell", x / 3, y / 1.4, x / 2 - ((x / 3) / 2), y / 2 - ((y / 1.5) / 2)) +local win = window.create("Launcher", x / 3, y / 1.4, x / 2 - ((x / 3) / 2), y / 2 - ((y / 1.5) / 2)) win.decorations = false win.alwaysOnTop = true local apps = {} diff --git a/modules/entrypointclient.lua b/modules/entrypointclient.lua new file mode 100644 index 0000000..f973be9 --- /dev/null +++ b/modules/entrypointclient.lua @@ -0,0 +1,111 @@ +local max_distance = 220 + +local pullEvent = os.pullEventRaw +local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end) +term.clear() +term.setCursorPos(1,1) +_G.network = {} +if not modem then + return +end +local message_queue = {} +modem.open(15125) +local canidate = {id = -1, distance = max_distance} +parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, +function () + while true do + local _, _, channel, _, msg, distance = pullEvent("modem_message") + if channel == 15125 then + if msg.protocol == "entrypoint_advertise" then + if distance < canidate.distance then + canidate.id = msg.sender + canidate.distance = distance + end + end + end + end +end) +local last_heartbeat = os.epoch("utc") +modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id}) + +local function receive() + while true do + local _, _, channel, _, msg, distance = pullEvent("modem_message") + if channel == 15125 then + if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then + last_heartbeat = os.epoch("utc") + modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id}) + if distance > max_distance then + modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id}) + canidate = {id = -1, distance = max_distance} + parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, + function () + while true do + local _, _, channel, _, msg, distance = pullEvent("modem_message") + if channel == 15125 then + if msg.protocol == "entrypoint_advertise" then + if distance < canidate.distance then + canidate.id = msg.sender + canidate.distance = distance + end + end + end + end + end) + if canidate.id == -1 then + sleep(5) + else + modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id}) + last_heartbeat = os.epoch("utc") + end + end + elseif msg.protocol == "packet" then + if msg.hops >= 1 then + os.queueEvent("network_packet",msg.content,msg.sender,msg.hops) + end + end + end + end +end + +function _G.network.send(msg,destination) + if not msg then error("No message provided",2) end + if not destination then error("No destination provided",2) end + message_queue[#message_queue+1] = {protocol="packet",content=msg,destination=destination,sender=os.getComputerID(),hops=0} +end + +local function connect() + while true do + if os.epoch("utc") - last_heartbeat > 200 then + canidate = {id = -1, distance = max_distance} + parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, + function () + while true do + local _, _, channel, _, msg, distance = pullEvent("modem_message") + if channel == 15125 then + if msg.protocol == "entrypoint_advertise" then + if distance < canidate.distance then + canidate.id = msg.sender + canidate.distance = distance + end + end + end + end + end) + if canidate.id == -1 then + sleep(5) + else + modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id}) + last_heartbeat = os.epoch("utc") + end + else + local msg = table.remove(message_queue,1) + if msg then + modem.transmit(15125,15125,msg) + end + end + sleep() + end +end +parallel.waitForAny(receive, connect) +os.shutdown() diff --git a/startup.lua b/startup.lua index 49a9683..0d76f66 100644 --- a/startup.lua +++ b/startup.lua @@ -66,15 +66,19 @@ end local function desktop() local image = nft.load(".wallpaper.nft") + local paint_image = paintutils.loadImage(".wallpaper.nfp") local w, h = term.getSize() - term.setBackgroundColor(colors.lightGray) + term.setBackgroundColor(colors.white) term.clear() term.setCursorPos(1, 1) term.setTextColor(colors.white) term.setBackgroundColor(colors.gray) - term.write(" Desktop ") + term.clearLine() + term.write(" "..((_G.windows[#_G.windows] or {name=""}).name or "").." ") if image then nft.draw(image,1,1) + elseif paint_image then + paintutils.drawImage(paint_image,1,2) end end local threading = require("libs.threading")