From ebcd2c58b415e4fdd286d7cd7f24c37d79fd9662 Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Sat, 1 Jun 2024 20:49:50 +0200 Subject: [PATCH] feat: enable custom chime selection on live trains Fixes #190 --- .gitignore | 2 ++ src/components/AmeyLiveTrainAnnouncements.tsx | 35 +++++++++++++++---- src/data/changelog.ts | 4 +++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d7e49c720..b762c5cac 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,5 @@ static/temp/ # Sentry Config File .sentryclirc + +.wrangler/ diff --git a/src/components/AmeyLiveTrainAnnouncements.tsx b/src/components/AmeyLiveTrainAnnouncements.tsx index 6915a897a..d81897546 100644 --- a/src/components/AmeyLiveTrainAnnouncements.tsx +++ b/src/components/AmeyLiveTrainAnnouncements.tsx @@ -26,6 +26,7 @@ import type { default as AmeyPhil, ILiveTrainApproachingAnnouncementOptions, IStandingTrainAnnouncementOptions, + ChimeType, } from '../announcement-data/systems/stations/AmeyPhil' import dayjs from 'dayjs' @@ -271,6 +272,13 @@ const DisplayNames: Record = { 'blackbox-landscape-lcd': 'Blackbox landscape LCD', } +const ChimeTypeNames: Record = { + '': 'Per-voice default', + none: 'No chime', + three: '3 chimes', + four: '4 chimes', +} + export function LiveTrainAnnouncements({ nextTrainHandler, disruptedTrainHandler, @@ -362,6 +370,9 @@ export function LiveTrainAnnouncements({ const [displayType, setDisplayType] = useState('infotec-landscape-dmi') const [isFullscreen, setFullscreen] = useState(false) const [selectedCrs, setSelectedCrs] = useState('ECR') + const [chimeType, setChimeType] = useStateWithLocalStorage('amey.live-trains.chime-type', '', val => + ['', 'none', 'three', 'four'].includes(val), + ) const [hasEnabledFeature, setHasEnabledFeature] = useState(false) const [useLegacyTocNames, setUseLegacyTocNames] = useStateWithLocalStorage('amey.live-trains.use-legacy-toc-names', false) const [showUnconfirmedPlatforms, setShowUnconfirmedPlatforms] = useStateWithLocalStorage( @@ -604,7 +615,7 @@ export function LiveTrainAnnouncements({ const vias = getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) const options: ILiveTrainApproachingAnnouncementOptions = { - chime: systems[systemKey].DEFAULT_CHIME, + chime: chimeType || systems[systemKey].DEFAULT_CHIME, hour: h === '00' ? '00 - midnight' : h, min: m === '00' ? '00 - hundred-hours' : m, isDelayed: delayMins > 5, @@ -637,7 +648,7 @@ export function LiveTrainAnnouncements({ console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`) setTimeout(() => setIsPlaying(false), 5000) }, - [markNextTrainAnnounced, systems, setIsPlaying, approachingTrainHandler, getStation, addLog, useLegacyTocNames], + [markNextTrainAnnounced, systems, setIsPlaying, approachingTrainHandler, getStation, addLog, useLegacyTocNames, chimeType], ) const announceNextTrain = useCallback( @@ -667,7 +678,7 @@ export function LiveTrainAnnouncements({ const [vias] = getViaPoints(train, systems[systemKey].STATIONS, stationNameToCrsMap, loc => getStation(loc, systemKey)) const options: INextTrainAnnouncementOptions = { - chime: systems[systemKey].DEFAULT_CHIME, + chime: chimeType || systems[systemKey].DEFAULT_CHIME, hour: h === '00' ? '00 - midnight' : h, min: m === '00' ? '00 - hundred-hours' : m, isDelayed: delayMins > 5, @@ -701,7 +712,7 @@ export function LiveTrainAnnouncements({ console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`) setTimeout(() => setIsPlaying(false), 5000) }, - [markNextTrainAnnounced, systems, setIsPlaying, nextTrainHandler, getStation, addLog, useLegacyTocNames], + [markNextTrainAnnounced, systems, setIsPlaying, nextTrainHandler, getStation, addLog, useLegacyTocNames, chimeType], ) const announceDisruptedTrain = useCallback( @@ -740,7 +751,7 @@ export function LiveTrainAnnouncements({ } const options: IDisruptedTrainAnnouncementOptions = { - chime: systems[systemKey].DEFAULT_CHIME, + chime: chimeType || systems[systemKey].DEFAULT_CHIME, hour: h === '00' ? '00 - midnight' : h, min: m === '00' ? '00 - hundred-hours' : m, toc, @@ -790,7 +801,7 @@ export function LiveTrainAnnouncements({ console.log(`[Live Trains] Announcement for ${train.rid} complete: waiting 5s until next`) setTimeout(() => setIsPlaying(false), 5000) }, - [markDisruptedTrainAnnounced, systems, setIsPlaying, disruptedTrainHandler, addLog, useLegacyTocNames], + [markDisruptedTrainAnnounced, systems, setIsPlaying, disruptedTrainHandler, addLog, useLegacyTocNames, chimeType], ) useEffect(() => { @@ -824,7 +835,7 @@ export function LiveTrainAnnouncements({ try { const resp = await fetch( - process.env.NODE_ENV === 'development' ? `http://localhost:8787/get-services?${params}` : `/api/get-services?${params}`, + process.env.NODE_ENV === 'development' ? `http://localhost:8787/api/get-services?${params}` : `/api/get-services?${params}`, ) if (!resp.ok) { @@ -1125,6 +1136,16 @@ export function LiveTrainAnnouncements({ Use legacy TOC names + +
Toggle announcement types diff --git a/src/data/changelog.ts b/src/data/changelog.ts index 0990f1a3f..d004766d5 100644 --- a/src/data/changelog.ts +++ b/src/data/changelog.ts @@ -457,6 +457,10 @@ const changelog: IChangelogVersion[] = [ ], fixes: ['[Class 700] Fix wrong St Pancras audio'], }, + { + date: '2024-06-01', + additions: ['[Live Trains] Customise/disable chimes'], + }, ] export default changelog