alot of stuff

This commit is contained in:
2025-10-22 16:43:36 -07:00
parent 734587569a
commit b6126945fd
8 changed files with 110 additions and 35 deletions

View File

@@ -1,10 +1,10 @@
local max_distance = 220
local pullEvent = os.pullEventRaw
_G.network = {}
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
@@ -14,7 +14,7 @@ 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")
local _, _, channel, _, msg, distance = os.pullEvent("modem_message")
if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then
@@ -30,18 +30,19 @@ modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerI
local function receive()
while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message")
local _, _, channel, _, msg, distance = os.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})
canidate.distance = distance
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")
local _, _, channel, _, msg, distance = os.pullEvent("modem_message")
if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then
@@ -73,6 +74,12 @@ function _G.network.send(msg,destination)
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
function _G.network.getID()
return canidate.id
end
function _G.network.getDistance()
return canidate.distance
end
local function connect()
while true do
@@ -81,7 +88,7 @@ local function connect()
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function ()
while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message")
local _, _, channel, _, msg, distance = os.pullEvent("modem_message")
if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then

View File

@@ -1,6 +1,8 @@
local threading = require("libs.threading")
local dragging = nil
local resizing = false
local offsetX, offsetY = 0, 0
local key = {}
local function bringtofront(indx)
local win = _G.windows[indx]
if win.alwaysOnTop or win.alwaysBelow then return end
@@ -31,7 +33,13 @@ while true do
if data[1] == "mouse_click" then
for indx = #_G.windows, 1, -1 do
local win = _G.windows[indx]
if win.y - 1 == data[4] and win.x + 1 <= data[3] and win.x + win.w >= data[3] and data[2] == 1 and win.decorations then
if data[4] == 1 then
break
elseif win.x+win.w-1 == data[3] and win.y+win.h-1 == data[4] and win.decorations and win.resizable then
dragging = win
resizing = true
bringtofront(indx)
elseif ((win.y - 1 == data[4] and win.x + 1 <= data[3] and win.x + win.w >= data[3] and data[2] == 1 and win.decorations) or (win.y <= data[4] and win.x <= data[3] and win.y + win.h > data[4] and win.x + win.w > data[3] and key[keys["leftAlt"] and win.draggable])) then
dragging = win
offsetX = win.x - data[3]
offsetY = win.y - data[4]
@@ -49,8 +57,14 @@ while true do
end
elseif data[1] == "mouse_drag" then
if data[2] == 1 and dragging then
dragging.x = data[3] + offsetX
dragging.y = data[4] + offsetY
if resizing then
dragging.w = math.max(data[3] - dragging.x + 1,dragging.min_w)
dragging.h = math.max(data[4] - dragging.y + 1,dragging.min_h)
threading.addThread(function()dragging.resized(dragging.w,dragging.h)end)
else
dragging.x = data[3] + offsetX
dragging.y = data[4] + offsetY
end
else
for indx = #_G.windows, 1, -1 do
local win = _G.windows[indx]
@@ -64,6 +78,7 @@ while true do
elseif data[1] == "mouse_up" then
if data[2] == 1 and dragging then
dragging = nil
resizing = false
else
for indx = #_G.windows, 1, -1 do
local win = _G.windows[indx]
@@ -83,6 +98,7 @@ while true do
end
end
elseif data[1] == "key" then
key[data[2]] = true
if _G.windows[#_G.windows] then
threading.addThread(function() _G.windows[#_G.windows].key(data[2], data[3]) end)
end
@@ -91,6 +107,7 @@ while true do
threading.addThread(function() _G.windows[#_G.windows].char(data[2]) end)
end
elseif data[1] == "key_up" then
key[data[2]] = false
if _G.windows[#_G.windows] then
threading.addThread(function() _G.windows[#_G.windows].key_up(data[2]) end)
end