Skip to content

Commit

Permalink
feat: enable custom chime selection on live trains
Browse files Browse the repository at this point in the history
Fixes #190
  • Loading branch information
davwheat committed Jun 1, 2024
1 parent c2efdca commit ebcd2c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ static/temp/

# Sentry Config File
.sentryclirc

.wrangler/
35 changes: 28 additions & 7 deletions src/components/AmeyLiveTrainAnnouncements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
default as AmeyPhil,
ILiveTrainApproachingAnnouncementOptions,
IStandingTrainAnnouncementOptions,
ChimeType,
} from '../announcement-data/systems/stations/AmeyPhil'

import dayjs from 'dayjs'
Expand Down Expand Up @@ -271,6 +272,13 @@ const DisplayNames: Record<DisplayType, string> = {
'blackbox-landscape-lcd': 'Blackbox landscape LCD',
}

const ChimeTypeNames: Record<ChimeType | '', string> = {
'': 'Per-voice default',
none: 'No chime',
three: '3 chimes',
four: '4 chimes',
}

export function LiveTrainAnnouncements<SystemKeys extends string>({
nextTrainHandler,
disruptedTrainHandler,
Expand Down Expand Up @@ -362,6 +370,9 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
const [displayType, setDisplayType] = useState<DisplayType>('infotec-landscape-dmi')
const [isFullscreen, setFullscreen] = useState(false)
const [selectedCrs, setSelectedCrs] = useState('ECR')
const [chimeType, setChimeType] = useStateWithLocalStorage<ChimeType | ''>('amey.live-trains.chime-type', '', val =>
['', 'none', 'three', 'four'].includes(val),
)
const [hasEnabledFeature, setHasEnabledFeature] = useState(false)
const [useLegacyTocNames, setUseLegacyTocNames] = useStateWithLocalStorage<boolean>('amey.live-trains.use-legacy-toc-names', false)
const [showUnconfirmedPlatforms, setShowUnconfirmedPlatforms] = useStateWithLocalStorage<boolean>(
Expand Down Expand Up @@ -604,7 +615,7 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
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,
Expand Down Expand Up @@ -637,7 +648,7 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
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(
Expand Down Expand Up @@ -667,7 +678,7 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
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,
Expand Down Expand Up @@ -701,7 +712,7 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
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(
Expand Down Expand Up @@ -740,7 +751,7 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
}

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,
Expand Down Expand Up @@ -790,7 +801,7 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
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(() => {
Expand Down Expand Up @@ -824,7 +835,7 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({

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) {
Expand Down Expand Up @@ -1125,6 +1136,16 @@ export function LiveTrainAnnouncements<SystemKeys extends string>({
Use legacy TOC names
</label>

<label htmlFor="chime-type-select" className="option-select">
Chime
<Select<Option<ChimeType | ''>, false>
id="chime-type-select"
value={{ value: chimeType, label: ChimeTypeNames[chimeType] }}
onChange={val => setChimeType(val!.value!!)}
options={Object.entries(ChimeTypeNames).map(([k, v]) => ({ value: k as ChimeType | '', label: v }))}
/>
</label>

<fieldset>
<legend>Toggle announcement types</legend>

Expand Down
4 changes: 4 additions & 0 deletions src/data/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ebcd2c5

Please sign in to comment.