fix(station): remove arrival and departure preview audio flow

Delete the station-side arrival/departure announcement requests and drop the server handlers for train arrival, train departure, and play_sequence messages so preview audio no longer interrupts live music.
This commit is contained in:
2026-07-31 21:53:12 +08:00
parent fd154afd82
commit 218aaabb50
2 changed files with 1 additions and 307 deletions
+1 -175
View File
@@ -38,15 +38,11 @@ local State = {
currentTrain = nil,
logs = {},
logScrollOffset = 0,
departingPlayed = false,
arrivalTonePlayed = false,
shortStopMode = false,
audioRx = nil,
audioQueue = {},
currentPlaying = nil,
currentPriority = -1,
interruptSeq = 0,
lastArrivalPlayAt = 0
interruptSeq = 0
}
-- ============================================================================
@@ -952,133 +948,11 @@ function Utils.getStationAudio(code, langPrefix)
return langPrefix .. code
end
function Audio.announceArrival(trainId, trainType, platform, dest, useAltJz3)
local seq = {}
Utils.log("DEBUG", string.format("Announcing Arrival: %s, Type: %s, Plat: %s, Dest: %s",
tostring(trainId), tostring(trainType), tostring(platform), tostring(dest)))
table.insert(seq, "ksts") -- Chime
table.insert(seq, "__DELAY_1__")
local destCode = Utils.getStationCode(dest)
if (not destCode or destCode == "unknown") and dest ~= "Unknown" then
-- Fallback to broadcast code if regular code failed
destCode = Utils.getBroadcastStationCode(dest)
Utils.log("DEBUG", "Station code fallback for " .. tostring(dest) .. ": " .. tostring(destCode))
end
Utils.log("DEBUG", "Final destination code for " .. tostring(dest) .. ": " .. tostring(destCode))
local chJz3 = useAltJz3 and "ch-jz3-1" or "ch-jz3"
local enJz3 = useAltJz3 and "en-jz3-1" or "en-jz3"
-- Chinese
table.insert(seq, "ch-jz1")
if destCode then
table.insert(seq, Utils.getStationAudio(destCode, "ch-"))
end
table.insert(seq, "ch-jz2")
table.insert(seq, trainType == "express" and "ch-tj" or "ch-pt")
table.insert(seq, chJz3)
-- Platform Number (Chinese)
local pAudio = Utils.getChineseNumberAudio(platform)
for _, a in ipairs(pAudio) do table.insert(seq, a) end
table.insert(seq, "ch-zt")
table.insert(seq, "ch-jz4")
-- English
table.insert(seq, "en-jz1")
table.insert(seq, trainType == "express" and "en-tj" or "en-pt")
table.insert(seq, "en-jz2")
if destCode then
table.insert(seq, Utils.getStationAudio(destCode, "en-"))
end
table.insert(seq, enJz3)
table.insert(seq, "en-zt")
-- English Platform Number
local pDigit, pLetter = tostring(platform):match("^(%d+)([a-zA-Z])$")
if pDigit and pLetter then
table.insert(seq, "en-" .. pDigit)
table.insert(seq, pLetter:upper())
else
table.insert(seq, "en-" .. platform)
end
table.insert(seq, "en-jz4")
Audio.play(seq)
end
function Audio.announceDeparture(trainId, trainType, platform, dest, time)
local seq = {}
table.insert(seq, "fcts")
table.insert(seq, "__DELAY_1__")
local destCode = Utils.getStationCode(dest)
-- Chinese
-- Platform Number
local pAudio = Utils.getChineseNumberAudio(platform)
for _, a in ipairs(pAudio) do table.insert(seq, a) end
table.insert(seq, "ch-zt")
table.insert(seq, "ch-fc1")
table.insert(seq, trainType == "express" and "ch-tj" or "ch-pt")
table.insert(seq, "ch-fc2")
if destCode then
table.insert(seq, Utils.getStationAudio(destCode, "ch-"))
end
table.insert(seq, "ch-fc3")
-- English
table.insert(seq, "en-fc1")
table.insert(seq, trainType == "express" and "en-tj" or "en-pt")
table.insert(seq, "en-fc2")
table.insert(seq, "en-zt")
-- English Platform Number
local pDigit, pLetter = tostring(platform):match("^(%d+)([a-zA-Z])$")
if pDigit and pLetter then
table.insert(seq, "en-" .. pDigit)
table.insert(seq, pLetter:upper())
else
table.insert(seq, "en-" .. platform)
end
table.insert(seq, "en-fc3")
if destCode then
table.insert(seq, Utils.getStationAudio(destCode, "en-"))
end
table.insert(seq, "en-fc4")
Audio.play(seq)
end
-- ============================================================================
-- 6. Network System
-- ============================================================================
local Network = {}
function Audio.play(files)
if not State.ws then
Utils.log("WARN", "Cannot play audio: Not connected to server")
return
end
Utils.log("INFO", "Requesting server to play sequence...")
Network.send({
type = "play_sequence",
stationName = State.stationName,
seq = files,
category = "train",
priority = 1,
requestId = tostring(os.epoch("utc")) .. "-" .. tostring(math.random(100000, 999999))
})
end
function Network.connect()
if State.ws then return end
Utils.log("INFO", "Connecting to cloud...")
@@ -1526,58 +1400,10 @@ function Main.loop()
departureTime = now + stationTime,
platform = Utils.getPlatformNumber(State.stationName, "1")
}
Network.send({
type = "train_arrival",
trainId = id,
stationName = State.stationName,
destination = dest
})
if not State.arrivalTonePlayed then
if stationTime < 50 then
Utils.log("INFO", "Short stop (<50s) and no pre-arrival. Skipping arrival announcement.")
State.shortStopMode = true
else
Utils.log("INFO", "Train arrived. Playing arrival announcement (alt).")
Audio.announceArrival(State.currentTrain.id, State.currentTrain.trainType, State.currentTrain.platform, State.currentTrain.dest, true)
end
State.arrivalTonePlayed = true
end
else
-- Train currently at station
local now = os.epoch("utc") / 1000
local remaining = State.currentTrain.departureTime - now
if State.shortStopMode then
-- Play fcts.wav only in the last 10 seconds
if remaining <= 10 and not State.departingPlayed then
Utils.log("INFO", "Short stop mode: playing fcts.wav only.")
Audio.play({"fcts"})
State.departingPlayed = true
end
else
if remaining <= 50 and not State.departingPlayed then
Audio.announceDeparture(State.currentTrain.id, State.currentTrain.trainType, State.currentTrain.platform, State.currentTrain.dest, 60)
State.departingPlayed = true
end
end
end
else
if State.currentTrain then
-- Train just left
Network.send({
type = "train_departure",
trainId = State.currentTrain.id,
stationName = State.stationName,
destination = State.currentTrain.dest,
schedule = State.currentTrain.schedule,
stationTime = math.floor((os.epoch("utc") / 1000) - State.currentTrain.arrivalTime)
})
State.currentTrain = nil
State.arrivalTonePlayed = false
State.departingPlayed = false
State.shortStopMode = false
end
end