fix: normalize upcoming ETA keys before text override
This commit is contained in:
+12
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user