diff --git a/station_broadcast.lua b/station_broadcast.lua index 372e1c6..deffaee 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -1,6 +1,6 @@ -- 1. Configuration & Constants -local APP_VERSION_TEXT = "v1.0.67" +local APP_VERSION_TEXT = "v1.0.68" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -1030,11 +1030,13 @@ function Utils.extractAllStationsFromSchedule(schedule) if inst.id == "create:station" or inst.id == "create:destination" then local text = (inst.data and inst.data.text) or inst.text if type(text) == "string" and text ~= "" then - table.insert(stations, { - index = i, - name = text, - isDestination = inst.id == "create:destination" - }) + local lower = text:lower() + if not lower:find("nan") and text:find("%S") then + table.insert(stations, { + index = i, + name = text + }) + end end end end @@ -2626,9 +2628,6 @@ function Display.render() drawRight(1, "SCHEDULE:", COLORS.SUCCESS) drawRight(2, "Train: " .. State.currentTrain.id, COLORS.INFO) local scheduleStations = Utils.extractAllStationsFromSchedule(State.currentTrain.schedule) - local currentStationBase = Utils.getBaseName(State.stationName) - local currentStationCode = Utils.getStationCode(State.stationName) - local reachedCurrent = false local stationLineY = 4 if State.currentTrain.schedule == nil then @@ -2639,31 +2638,90 @@ function Display.render() stationLineY = stationLineY + 1 end - if #scheduleStations == 0 then + local totalStations = #scheduleStations + if totalStations == 0 then drawRight(stationLineY, "(No station entries)", COLORS.WARNING) else + local destName = Utils.getDestination(State.currentTrain.schedule) + local destBase = Utils.getBaseName(destName) + local destCode = Utils.getStationCode(destName) + + local currentBase = Utils.getBaseName(State.stationName) + local currentCode = Utils.getStationCode(State.stationName) + local currentPlatform = tostring(State.stationPlatform or "") + + local function matchPlatform(aName, bPlatform) + if not bPlatform or bPlatform == "" then return true end + local pA = Utils.getPlatformNumber(aName, "") + return pA == "" or tostring(pA) == tostring(bPlatform) + end + + local currentIdx = nil 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 + local isBaseMatch = (currentBase and currentBase ~= "" and stBase == currentBase) + or (currentCode and currentCode ~= "" and stCode == currentCode) + or Utils.isFuzzyMatch(State.stationName, st.name) + if isBaseMatch and matchPlatform(st.name, currentPlatform) then + currentIdx = idx + break end + end - if isCurrentStation then - reachedCurrent = true + if currentIdx == nil then + for idx, st in ipairs(scheduleStations) do + local stBase = Utils.getBaseName(st.name) + local stCode = Utils.getStationCode(st.name) + if (currentBase and currentBase ~= "" and stBase == currentBase) + or (currentCode and currentCode ~= "" and stCode == currentCode) + or Utils.isFuzzyMatch(State.stationName, st.name) then + currentIdx = idx + break + end end + end + + local nextIdx = nil + if currentIdx and currentIdx < totalStations then + nextIdx = currentIdx + 1 + end + + local endIdx = nil + for idx = totalStations, 1, -1 do + local st = scheduleStations[idx] + local stBase = Utils.getBaseName(st.name) + local stCode = Utils.getStationCode(st.name) + if (destBase and destBase ~= "" and stBase == destBase) + or (destCode and destCode ~= "" and stCode == destCode) + or Utils.isFuzzyMatch(destName, st.name) then + endIdx = idx + break + end + end + if endIdx == nil then + endIdx = totalStations + end + + for idx, st in ipairs(scheduleStations) do + if stationLineY > h then break end + local isCurrent = (idx == currentIdx) + local isNext = (idx == nextIdx) + local isEnd = (idx == endIdx) + + local reachedCurrent = currentIdx ~= nil and idx < currentIdx local prefix = " " local lineColor = COLORS.INFO - if isCurrentStation then + if isCurrent then prefix = "> " lineColor = COLORS.SUCCESS + elseif isNext then + prefix = "~ " + lineColor = colors.orange + elseif isEnd then + prefix = " " + lineColor = COLORS.WARNING elseif reachedCurrent then prefix = " " lineColor = colors.lightGray @@ -2672,18 +2730,18 @@ function Display.render() lineColor = COLORS.INFO end - local suffix = "" - if st.isDestination then - suffix = " [END]" - lineColor = COLORS.WARNING + local tag = "" + if isCurrent then + tag = " <<" + end + if isNext then + tag = tag .. " [NEXT]" + end + if isEnd then + tag = tag .. " [END]" end - local displayName = st.name - if isCurrentStation then - displayName = displayName .. " <<" - end - - drawRight(stationLineY, prefix .. displayName .. suffix, lineColor) + drawRight(stationLineY, prefix .. st.name .. tag, lineColor) stationLineY = stationLineY + 1 end end