debug: compare text and NBT ETA keys on monitor

This commit is contained in:
2026-08-02 17:00:24 +08:00
parent 4b95c86af6
commit 9f2dc5bb3d
2 changed files with 65 additions and 3 deletions
+41 -3
View File
@@ -2149,7 +2149,28 @@ function Display.render()
)
if #dbgLine > w then dbgLine = dbgLine:sub(1, w) end
mon.write(dbgLine)
logsStartY = upcomingStartY + 2
if upcomingStartY + 2 <= h then
mon.setCursorPos(1, upcomingStartY + 2)
local keyLine = string.format(
"TK:%s NK:%s",
tostring(dbg.textKey or "-"),
tostring(dbg.nbtKey or "-")
)
if #keyLine > w then keyLine = keyLine:sub(1, w) end
mon.write(keyLine)
end
if upcomingStartY + 3 <= h then
mon.setCursorPos(1, upcomingStartY + 3)
local etaLine = string.format(
"TXT:%s NBT:%s USE:%s",
tostring(dbg.textEta or "-"),
tostring(dbg.nbtEta or "-"),
tostring(dbg.usedEta or "-")
)
if #etaLine > w then etaLine = etaLine:sub(1, w) end
mon.write(etaLine)
end
logsStartY = upcomingStartY + 4
end
if hasUpcoming then
mon.setTextColor(COLORS.INFO)
@@ -2337,7 +2358,12 @@ function Main.loop()
hasCT = Peripherals.createTarget ~= nil,
ok = false,
trainStopsCount = 0,
tickRate = State.tickRate or 20
tickRate = State.tickRate or 20,
textKey = nil,
nbtKey = nil,
textEta = nil,
nbtEta = nil,
usedEta = nil
}
-- Prefer CRN's own ETA display text (create_target) when available.
@@ -2373,7 +2399,12 @@ function Main.loop()
end
end
if dest then
etaByText[tName .. "_" .. dest] = etaSeconds
local textKey = tName .. "_" .. dest
etaByText[textKey] = etaSeconds
if not dbg.textKey then
dbg.textKey = textKey
dbg.textEta = etaSeconds
end
end
end
end
@@ -2459,10 +2490,17 @@ function Main.loop()
local etaSeconds = math.floor(etaTicks / (State.tickRate or 20))
if etaSeconds < 0 then etaSeconds = 0 end
local announceKey = trainName .. "_" .. destination
if not dbg.nbtKey then
dbg.nbtKey = announceKey
dbg.nbtEta = etaSeconds
end
local textEta = etaByText[announceKey]
if type(textEta) == "number" and textEta >= 0 then
etaSeconds = textEta
end
if not dbg.usedEta then
dbg.usedEta = etaSeconds
end
-- Calculate Delay in minutes
local delayTicks = realArrival - scheduledArrival