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