fix: normalize upcoming ETA keys before text override

This commit is contained in:
2026-08-02 17:11:31 +08:00
parent db818209f2
commit 426e55a7f0
2 changed files with 16 additions and 5 deletions
+12 -2
View File
@@ -2417,6 +2417,16 @@ local function parseEtaText(etaStr)
return -1
end
local function normalizeUpcomingKey(trainName, destination)
local function clean(value)
value = tostring(value or "")
value = value:gsub("%s+", " ")
value = value:match("^%s*(.-)%s*$") or ""
return value
end
return clean(trainName) .. "_" .. clean(destination)
end
function Main.loop()
while true do
local now = os.epoch("utc")
@@ -2462,7 +2472,7 @@ function Main.loop()
end
local etaSeconds = parseEtaText(etaStr)
if dest then
local textKey = tName .. "_" .. dest
local textKey = normalizeUpcomingKey(tName, dest)
etaByText[textKey] = etaSeconds
if not dbg.textKey then
dbg.textKey = textKey
@@ -2555,7 +2565,7 @@ function Main.loop()
local etaTicks = realArrival - currentTick
local etaSeconds = math.floor(etaTicks / (State.tickRate or 20))
if etaSeconds < 0 then etaSeconds = 0 end
local announceKey = trainName .. "_" .. destination
local announceKey = normalizeUpcomingKey(trainName, destination)
if not dbg.nbtKey then
dbg.nbtKey = announceKey
dbg.nbtEta = etaSeconds