entirely rework event handling take 4
This commit is contained in:
@ -110,6 +110,9 @@ function handlers.handlePasswordInput()
|
|||||||
-- Unregister the password handler
|
-- Unregister the password handler
|
||||||
events.clearHandlers("monitor_touch")
|
events.clearHandlers("monitor_touch")
|
||||||
|
|
||||||
|
-- Re-register connection handlers after password entry completes
|
||||||
|
handlers.setupConnectionHandlers()
|
||||||
|
|
||||||
-- Send password attempt
|
-- Send password attempt
|
||||||
utils.sendPasswordAttempt(password)
|
utils.sendPasswordAttempt(password)
|
||||||
|
|
||||||
@ -190,7 +193,6 @@ end
|
|||||||
function handlers.setupConnectionHandlers()
|
function handlers.setupConnectionHandlers()
|
||||||
-- Clear any existing handlers
|
-- Clear any existing handlers
|
||||||
events.clearHandlers()
|
events.clearHandlers()
|
||||||
|
|
||||||
-- Register all handlers with their priorities
|
-- Register all handlers with their priorities
|
||||||
events.registerHandler("monitor_touch", handlers.handleDisconnectButton, events.PRIORITY.DISCONNECT_BUTTON)
|
events.registerHandler("monitor_touch", handlers.handleDisconnectButton, events.PRIORITY.DISCONNECT_BUTTON)
|
||||||
events.registerHandler("monitor_touch", handlers.handleDefaultClick, events.PRIORITY.DEFAULT) -- Lowest priority - returns coordinates
|
events.registerHandler("monitor_touch", handlers.handleDefaultClick, events.PRIORITY.DEFAULT) -- Lowest priority - returns coordinates
|
||||||
@ -198,4 +200,6 @@ function handlers.setupConnectionHandlers()
|
|||||||
events.registerHandler("stargate_reconstructing_entity", handlers.handleEntityRead, events.PRIORITY.ENTITY_READ)
|
events.registerHandler("stargate_reconstructing_entity", handlers.handleEntityRead, events.PRIORITY.ENTITY_READ)
|
||||||
events.registerHandler("stargate_disconnected", handlers.handleDisconnect, events.PRIORITY.DISCONNECT_CHECK)
|
events.registerHandler("stargate_disconnected", handlers.handleDisconnect, events.PRIORITY.DISCONNECT_CHECK)
|
||||||
events.registerHandler("stargate_message_received", handlers.handleMessage, events.PRIORITY.MESSAGE)
|
events.registerHandler("stargate_message_received", handlers.handleMessage, events.PRIORITY.MESSAGE)
|
||||||
endreturn handlers
|
end
|
||||||
|
|
||||||
|
return handlers
|
||||||
|
|||||||
13
startup.lua
13
startup.lua
@ -85,7 +85,6 @@ end
|
|||||||
|
|
||||||
local function GetClick()
|
local function GetClick()
|
||||||
mon.setTextScale(1)
|
mon.setTextScale(1)
|
||||||
handlers.setupConnectionHandlers()
|
|
||||||
local result, eventType, eventData = events.pullEvent("monitor_touch")
|
local result, eventType, eventData = events.pullEvent("monitor_touch")
|
||||||
|
|
||||||
-- eventData is {eventType, side, x, y}
|
-- eventData is {eventType, side, x, y}
|
||||||
@ -100,14 +99,12 @@ local function GetClick()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function GetActivation()
|
local function GetActivation()
|
||||||
handlers.setupConnectionHandlers()
|
|
||||||
local result = events.pullEvent("stargate_incoming_wormhole")
|
local result = events.pullEvent("stargate_incoming_wormhole")
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ParaDisconnect()
|
local function ParaDisconnect()
|
||||||
-- Now handled by event system with priority
|
-- Now handled by event system with priority
|
||||||
handlers.setupConnectionHandlers()
|
|
||||||
while true do
|
while true do
|
||||||
local result = events.pullEvent("monitor_touch")
|
local result = events.pullEvent("monitor_touch")
|
||||||
if result == "disconnect" then
|
if result == "disconnect" then
|
||||||
@ -118,13 +115,11 @@ end
|
|||||||
|
|
||||||
local function EntityRead()
|
local function EntityRead()
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
handlers.setupConnectionHandlers()
|
|
||||||
local result = events.pullEvent("stargate_reconstructing_entity")
|
local result = events.pullEvent("stargate_reconstructing_entity")
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function DisconnectCheck()
|
local function DisconnectCheck()
|
||||||
handlers.setupConnectionHandlers()
|
|
||||||
local result = events.pullEvent("stargate_disconnected")
|
local result = events.pullEvent("stargate_disconnected")
|
||||||
return 2
|
return 2
|
||||||
end
|
end
|
||||||
@ -135,7 +130,6 @@ local function Paratimeout()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function GetMessage()
|
local function GetMessage()
|
||||||
handlers.setupConnectionHandlers()
|
|
||||||
local result = events.pullEvent("stargate_message_received")
|
local result = events.pullEvent("stargate_message_received")
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
@ -252,6 +246,9 @@ end
|
|||||||
local function handleIncomingWormhole()
|
local function handleIncomingWormhole()
|
||||||
local state = getState()
|
local state = getState()
|
||||||
|
|
||||||
|
-- Setup event handlers for this connection
|
||||||
|
handlers.setupConnectionHandlers()
|
||||||
|
|
||||||
mon.setBackgroundColor(colors.black)
|
mon.setBackgroundColor(colors.black)
|
||||||
mon.clear()
|
mon.clear()
|
||||||
mon.setBackgroundColor(colors.red)
|
mon.setBackgroundColor(colors.red)
|
||||||
@ -498,6 +495,10 @@ end
|
|||||||
|
|
||||||
local function handleOutgoingDial()
|
local function handleOutgoingDial()
|
||||||
local state = getState()
|
local state = getState()
|
||||||
|
|
||||||
|
-- Setup event handlers for this connection
|
||||||
|
handlers.setupConnectionHandlers()
|
||||||
|
|
||||||
totalstate = true
|
totalstate = true
|
||||||
local PDO = 0
|
local PDO = 0
|
||||||
PDO = parallel.waitForAny(selectCategory, Paratimeout)
|
PDO = parallel.waitForAny(selectCategory, Paratimeout)
|
||||||
|
|||||||
Reference in New Issue
Block a user