feat: implement train arrival/departure sequence logic and add departure beep config in client
This commit is contained in:
+85
-8
@@ -2,7 +2,7 @@
|
||||
-- ============================================================================
|
||||
-- 1. Configuration & Constants
|
||||
-- ============================================================================
|
||||
local APP_VERSION_TEXT = "v1.0.14"
|
||||
local APP_VERSION_TEXT = "v1.0.15"
|
||||
|
||||
local CONFIG = {
|
||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||
@@ -210,6 +210,8 @@ function Utils.promptSlaveIdentity()
|
||||
term.write("Station code (e.g. cb-03): ")
|
||||
term.setCursorPos(1, 8)
|
||||
term.write("Platform number (e.g. 6): ")
|
||||
term.setCursorPos(1, 10)
|
||||
term.write("Departure beep (e.g. fc1): ")
|
||||
|
||||
term.setCursorPos(30, 6)
|
||||
term.setTextColor(colors.cyan)
|
||||
@@ -218,21 +220,25 @@ function Utils.promptSlaveIdentity()
|
||||
term.setCursorPos(31, 8)
|
||||
local stationPlatform = Utils.trim(read() or "")
|
||||
|
||||
term.setCursorPos(32, 10)
|
||||
local departureBeep = Utils.trim(read() or "")
|
||||
if departureBeep == "" then departureBeep = "fc1" end
|
||||
|
||||
if stationCode == "" or stationPlatform == "" then
|
||||
term.setCursorPos(1, 10)
|
||||
term.setCursorPos(1, 12)
|
||||
term.setTextColor(colors.red)
|
||||
term.write("Both station code and platform are required.")
|
||||
term.setCursorPos(1, 12)
|
||||
term.setCursorPos(1, 14)
|
||||
term.setTextColor(colors.lightGray)
|
||||
term.write("Press any key to retry...")
|
||||
os.pullEvent("key")
|
||||
else
|
||||
local ok = Utils.saveStationIdentity(stationCode, stationPlatform, nil)
|
||||
local ok = Utils.saveStationIdentity(stationCode, stationPlatform, departureBeep)
|
||||
if ok then
|
||||
term.setCursorPos(1, 10)
|
||||
term.setCursorPos(1, 12)
|
||||
term.setTextColor(colors.green)
|
||||
term.write("Saved to " .. CONFIG.STATION_IDENTITY_FILE)
|
||||
term.setCursorPos(1, 12)
|
||||
term.setCursorPos(1, 14)
|
||||
term.setTextColor(colors.lightGray)
|
||||
term.write("Press any key to continue...")
|
||||
os.pullEvent("key")
|
||||
@@ -241,10 +247,79 @@ function Utils.promptSlaveIdentity()
|
||||
term.clear()
|
||||
return true
|
||||
end
|
||||
term.setCursorPos(1, 10)
|
||||
term.setCursorPos(1, 12)
|
||||
term.setTextColor(colors.red)
|
||||
term.write("Failed to save " .. CONFIG.STATION_IDENTITY_FILE)
|
||||
term.setCursorPos(1, 14)
|
||||
term.setTextColor(colors.lightGray)
|
||||
term.write("Press any key to retry...")
|
||||
os.pullEvent("key")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Utils.promptConfig()
|
||||
local manual = Utils.loadStationIdentity()
|
||||
local currentCode = manual.station_code or State.stationCode or ""
|
||||
local currentPlatform = manual.station_platform or State.stationPlatform or "1"
|
||||
local currentBeep = manual.departure_beep or State.departureBeep or "fc1"
|
||||
|
||||
while true do
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.white)
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
term.setTextColor(colors.yellow)
|
||||
term.write("Station Broadcast Configuration")
|
||||
term.setCursorPos(1, 3)
|
||||
term.setTextColor(colors.white)
|
||||
if Peripherals.station then
|
||||
term.write("Physical Station detected. Code/Platform are auto-synced.")
|
||||
term.setCursorPos(1, 4)
|
||||
term.write("You can override them here if needed.")
|
||||
else
|
||||
term.write("Slave node mode.")
|
||||
end
|
||||
|
||||
term.setCursorPos(1, 6)
|
||||
term.write("Station code [" .. currentCode .. "]: ")
|
||||
term.setCursorPos(1, 8)
|
||||
term.write("Platform number [" .. currentPlatform .. "]: ")
|
||||
term.setCursorPos(1, 10)
|
||||
term.write("Departure beep [" .. currentBeep .. "]: ")
|
||||
|
||||
term.setCursorPos(30, 6)
|
||||
term.setTextColor(colors.cyan)
|
||||
local codeInput = Utils.trim(read() or ""):lower()
|
||||
if codeInput == "" then codeInput = currentCode end
|
||||
|
||||
term.setCursorPos(31, 8)
|
||||
local platformInput = Utils.trim(read() or "")
|
||||
if platformInput == "" then platformInput = currentPlatform end
|
||||
|
||||
term.setCursorPos(32, 10)
|
||||
local beepInput = Utils.trim(read() or "")
|
||||
if beepInput == "" then beepInput = currentBeep end
|
||||
|
||||
local ok = Utils.saveStationIdentity(codeInput, platformInput, beepInput)
|
||||
if ok then
|
||||
Utils.refreshStationIdentity()
|
||||
term.setCursorPos(1, 12)
|
||||
term.setTextColor(colors.green)
|
||||
term.write("Configuration saved.")
|
||||
term.setCursorPos(1, 14)
|
||||
term.setTextColor(colors.lightGray)
|
||||
term.write("Press any key to return...")
|
||||
os.pullEvent("key")
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.white)
|
||||
term.clear()
|
||||
break
|
||||
else
|
||||
term.setCursorPos(1, 12)
|
||||
term.setTextColor(colors.red)
|
||||
term.write("Failed to save configuration.")
|
||||
term.setCursorPos(1, 14)
|
||||
term.setTextColor(colors.lightGray)
|
||||
term.write("Press any key to retry...")
|
||||
os.pullEvent("key")
|
||||
@@ -1977,7 +2052,7 @@ function Display.renderTerminal()
|
||||
term.setBackgroundColor(colors.gray)
|
||||
term.setTextColor(colors.white)
|
||||
term.clearLine()
|
||||
local title = " Station Broadcast Console (" .. State.stationName .. " " .. tostring(State.stationCode) .. "/P" .. tostring(State.stationPlatform) .. " / " .. APP_VERSION_TEXT .. ") "
|
||||
local title = " Station Broadcast (" .. State.stationName .. " " .. tostring(State.stationCode) .. "/P" .. tostring(State.stationPlatform) .. ") [C: Config] "
|
||||
term.setCursorPos(math.floor((w - #title)/2) + 1, 1)
|
||||
term.write(title)
|
||||
term.setBackgroundColor(colors.black)
|
||||
@@ -2070,6 +2145,8 @@ function Input.listener()
|
||||
State.logScrollOffset = 0
|
||||
elseif param1 == keys["end"] then
|
||||
State.logScrollOffset = math.max(0, #State.logs - maxLogs)
|
||||
elseif param1 == keys.c then
|
||||
Utils.promptConfig()
|
||||
end
|
||||
Display.renderTerminal()
|
||||
Display.render()
|
||||
|
||||
Reference in New Issue
Block a user