Skip to content

Commit

Permalink
Merge pull request #50 from davwheat/main
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
davwheat authored Nov 5, 2023
2 parents 9bb3f1f + ce02088 commit 02475be
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/announcement-data/systems/stations/KeTechPhil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import StationAnnouncementSystem from '@announcement-data/StationAnnouncementSys
import CallingAtSelector, { CallingAtPoint } from '@components/CallingAtSelector'
import CustomAnnouncementPane, { ICustomAnnouncementPaneProps, ICustomAnnouncementPreset } from '@components/PanelPanes/CustomAnnouncementPane'
import CustomButtonPane from '@components/PanelPanes/CustomButtonPane'
import { AllStationsTitleValueMap } from '@data/StationManipulators'
import { getStationByCrs } from '@data/StationManipulators'
import crsToStationItemMapper, { stationItemCompleter } from '@helpers/crsToStationItemMapper'
import { AudioItem, CustomAnnouncementTab } from '../../AnnouncementSystem'
import FullscreenIcon from 'mdi-react/FullscreenIcon'
Expand Down Expand Up @@ -3710,7 +3710,10 @@ export default class KeTechPhil extends StationAnnouncementSystem {
terminatingStationCode: {
name: 'Terminating station',
default: this.stations[0],
options: AllStationsTitleValueMap.filter(s => this.stations.includes(s.value)),
options: this.stations.map(s => {
const stn = getStationByCrs(s)
return { title: stn ? `${stn.stationName} (${s})` : `Unknown name (${s})`, value: s }
}),
type: 'select',
},
vias: {
Expand Down Expand Up @@ -3885,6 +3888,21 @@ function LiveTrainAnnouncements({ nextTrainHandler, system }: LiveTrainAnnouncem

const [nextTrainAnnounced, setNextTrainAnnounced] = useState<Record<string, number>>({})

const stationNameToCrsMap = useMemo(
() =>
Object.fromEntries(
supportedStations.map(s => {
if (!s.label) {
console.warn(`[Live Trains] Station ${s.value} has no label!`)
return [s.value, s.value]
}

return [s.label.toLowerCase(), s.value]
}),
),
[supportedStations],
)

function removeOldIds() {
const now = Date.now()

Expand Down Expand Up @@ -4091,6 +4109,28 @@ function LiveTrainAnnouncements({ nextTrainHandler, system }: LiveTrainAnnouncem
})
.filter(x => !!x) as CallingAtPoint[]

const vias: CallingAtPoint[] = []

if (firstUnannounced.destination[0].via) {
const v: string = firstUnannounced.destination[0].via.startsWith('via ')
? firstUnannounced.destination[0].via.slice(4)
: firstUnannounced.destination[0].via

v.split(/(&|and)/).forEach(via => {
const guessViaCrs = stationNameToCrsMap[via.trim().toLowerCase()]

console.log(`[Live Trains] Guessed via ${guessViaCrs} for ${via}`)

if (guessViaCrs) {
vias.push({
crsCode: guessViaCrs,
name: '',
randomId: '',
})
}
})
}

const options: INextTrainAnnouncementOptions = {
chime: 'four',
hour: h === '00' ? '00 - midnight' : h,
Expand All @@ -4100,7 +4140,7 @@ function LiveTrainAnnouncements({ nextTrainHandler, system }: LiveTrainAnnouncem
coaches: firstUnannounced.length ? `${firstUnannounced.length} coaches` : null,
platform: system.platforms.includes(firstUnannounced.platform.toLowerCase()) ? firstUnannounced.platform.toLowerCase() : '1',
terminatingStationCode: firstUnannounced.destination[0].crs,
vias: [],
vias,
callingAt,
}

Expand Down

0 comments on commit 02475be

Please sign in to comment.