fix(display): 修复时刻表不显示的多个问题
- 将宽度阈值从 50 降低到 30,适配更小的 monitor - 重构 schedule.entries 解析逻辑:兼容非纯数字索引(用 pairs 收集后排序) - 修复视觉逻辑 bug:已到达站(浅灰) vs 未到达站(白) 颜色搞反 - 增加 schedule 为 nil/invalid 时的错误提示显示 - 增加调试日志输出 monitor 尺寸和提取到的站点数 - 版本号升级至 v1.0.65
This commit is contained in:
+50
-19
@@ -1,6 +1,6 @@
|
||||
|
||||
-- 1. Configuration & Constants
|
||||
local APP_VERSION_TEXT = "v1.0.64"
|
||||
local APP_VERSION_TEXT = "v1.0.65"
|
||||
|
||||
local CONFIG = {
|
||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||
@@ -1001,16 +1001,30 @@ function Utils.getNextStation(schedule, currentStationName)
|
||||
end
|
||||
|
||||
function Utils.extractAllStationsFromSchedule(schedule)
|
||||
if not schedule or not schedule.entries then return {} end
|
||||
if not schedule then return {} end
|
||||
local entries = schedule.entries or (type(schedule) == "table" and schedule)
|
||||
if not entries or type(entries) ~= "table" then return {} end
|
||||
|
||||
local maxIdx = 0
|
||||
for k, _ in pairs(schedule.entries) do
|
||||
if type(k) == "number" and k > maxIdx then maxIdx = k end
|
||||
local ordered = {}
|
||||
local numericKeys = {}
|
||||
for k, v in pairs(entries) do
|
||||
if type(k) == "number" then
|
||||
table.insert(numericKeys, k)
|
||||
end
|
||||
end
|
||||
if #numericKeys > 0 then
|
||||
table.sort(numericKeys)
|
||||
for _, k in ipairs(numericKeys) do
|
||||
table.insert(ordered, entries[k])
|
||||
end
|
||||
else
|
||||
for _, v in pairs(entries) do
|
||||
table.insert(ordered, v)
|
||||
end
|
||||
end
|
||||
|
||||
local stations = {}
|
||||
for i = 1, maxIdx do
|
||||
local entry = schedule.entries[i]
|
||||
for i, entry in ipairs(ordered) do
|
||||
if entry and entry.instruction then
|
||||
local inst = entry.instruction
|
||||
if inst.id == "create:station" or inst.id == "create:destination" then
|
||||
@@ -1025,6 +1039,7 @@ function Utils.extractAllStationsFromSchedule(schedule)
|
||||
end
|
||||
end
|
||||
end
|
||||
Utils.log("DEBUG", string.format("ExtractStations: found %d stations from %d schedule entries", #stations, #ordered))
|
||||
return stations
|
||||
end
|
||||
|
||||
@@ -2495,14 +2510,19 @@ function Display.render()
|
||||
local rightX = nil
|
||||
local rightW = 0
|
||||
|
||||
if hasSchedulePanel and w >= 50 then
|
||||
rightW = math.min(math.floor(w * 0.4), 40)
|
||||
if hasSchedulePanel and w >= 30 then
|
||||
rightW = math.min(math.max(math.floor(w * 0.38), 18), 40)
|
||||
leftW = w - rightW - 1
|
||||
if leftW < 12 then
|
||||
leftW = w
|
||||
rightW = 0
|
||||
else
|
||||
sepX = leftW + 1
|
||||
rightX = sepX + 1
|
||||
leftW = math.max(leftW, 20)
|
||||
rightW = math.max(rightW, 15)
|
||||
end
|
||||
end
|
||||
|
||||
Utils.log("DEBUG", string.format("Monitor size W=%d H=%d, schedulePanel=%s leftW=%d rightW=%d", w, h, tostring(rightX ~= nil), leftW, rightW))
|
||||
|
||||
local function classifyAudioSource(source, priority)
|
||||
local s = tostring(source or ""):lower()
|
||||
@@ -2591,10 +2611,20 @@ function Display.render()
|
||||
local scheduleStations = Utils.extractAllStationsFromSchedule(State.currentTrain.schedule)
|
||||
local currentStationBase = Utils.getBaseName(State.stationName)
|
||||
local currentStationCode = Utils.getStationCode(State.stationName)
|
||||
local passedCurrent = false
|
||||
local reachedCurrent = false
|
||||
local stationLineY = 4
|
||||
local maxStationLines = h - 3
|
||||
|
||||
if State.currentTrain.schedule == nil then
|
||||
drawRight(stationLineY, "Schedule: nil", COLORS.ERROR)
|
||||
stationLineY = stationLineY + 1
|
||||
elseif type(State.currentTrain.schedule) ~= "table" then
|
||||
drawRight(stationLineY, "Schedule: invalid type", COLORS.ERROR)
|
||||
stationLineY = stationLineY + 1
|
||||
end
|
||||
|
||||
if #scheduleStations == 0 then
|
||||
drawRight(stationLineY, "(No station entries)", COLORS.WARNING)
|
||||
else
|
||||
for idx, st in ipairs(scheduleStations) do
|
||||
if stationLineY > h then break end
|
||||
local stBase = Utils.getBaseName(st.name)
|
||||
@@ -2608,17 +2638,21 @@ function Display.render()
|
||||
isCurrentStation = true
|
||||
end
|
||||
|
||||
if isCurrentStation then
|
||||
reachedCurrent = true
|
||||
end
|
||||
|
||||
local prefix = " "
|
||||
local lineColor = COLORS.INFO
|
||||
if isCurrentStation then
|
||||
prefix = "> "
|
||||
lineColor = COLORS.SUCCESS
|
||||
passedCurrent = true
|
||||
elseif passedCurrent then
|
||||
elseif reachedCurrent then
|
||||
prefix = " "
|
||||
lineColor = colors.lightGray
|
||||
else
|
||||
prefix = "* "
|
||||
lineColor = colors.lightGray
|
||||
lineColor = COLORS.INFO
|
||||
end
|
||||
|
||||
local suffix = ""
|
||||
@@ -2635,9 +2669,6 @@ function Display.render()
|
||||
drawRight(stationLineY, prefix .. displayName .. suffix, lineColor)
|
||||
stationLineY = stationLineY + 1
|
||||
end
|
||||
|
||||
if #scheduleStations == 0 then
|
||||
drawRight(4, "No station data", COLORS.WARNING)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user