Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Nov 5, 2023
2 parents 696e4fd + f5ed046 commit 9bb3f1f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 146 deletions.
50 changes: 38 additions & 12 deletions src/announcement-data/AnnouncementSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ export type CustomAnnouncementButton = {

export interface PluraliseOptions {
andId: string
prefix?: string
finalPrefix?: string
prefix: string
finalPrefix: string
firstItemDelay: number
beforeItemDelay: number
beforeAndDelay: number
afterAndDelay: number
}

const DefaultPluraliseOptions = {
andId: 'and',
}

export default abstract class AnnouncementSystem {
Expand Down Expand Up @@ -238,8 +246,10 @@ export default abstract class AnnouncementSystem {
* @param items Array of audio files
* @returns Pluralised array of audio files
*/
protected pluraliseAudio(items: AudioItem[], delay: number = 0, options: PluraliseOptions = { andId: 'and' }): AudioItem[] {
items = items
protected pluraliseAudio(items: AudioItem[], options: Partial<PluraliseOptions> = DefaultPluraliseOptions): AudioItem[] {
const _options = { ...DefaultPluraliseOptions, ...options }

const _items = items
.map(item => {
if (typeof item === 'string') {
return { id: item }
Expand All @@ -249,27 +259,43 @@ export default abstract class AnnouncementSystem {
})
.map((item, i) => {
if (items.length - 1 === i) {
if (options.finalPrefix) {
item.id = `${options.finalPrefix}${item.id}`
if (_options.finalPrefix !== undefined) {
item.id = `${_options.finalPrefix}${item.id}`

return item
}
} else {
if (options.prefix) {
item.id = `${options.prefix}${item.id}`
if (_options.prefix !== undefined) {
item.id = `${_options.prefix}${item.id}`

return item
}
}

if (i === 0 && _options.firstItemDelay !== undefined) {
item.opts = {
...item.opts,
delayStart: _options.firstItemDelay,
}
} else if (_options.beforeItemDelay !== undefined) {
item.opts = {
...item.opts,
delayStart: _options.beforeItemDelay,
}
}

return item
})

if (items.length > 1) {
items.splice(items.length - 1, 0, { id: options.andId, opts: { delayStart: delay } })
return items
if (_items.length > 1) {
_items.splice(_items.length - 1, 0, { id: _options.andId, opts: { delayStart: _options.beforeAndDelay } })

if (_options.afterAndDelay !== undefined || _options.beforeItemDelay !== undefined) {
_items[items.length - 1].opts ??= {}
_items[items.length - 1].opts!!.delayStart = _options.afterAndDelay ?? _options.beforeItemDelay
}
}

return items
return _items
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class BombardierXstar extends TrainAnnouncementSystem {
if (remainingStops.length > 1) {
// We are not at the termination point.
files.push('calling at')
files.push(...this.pluraliseAudio(remainingStops, 75))
files.push(...this.pluraliseAudio(remainingStops, { beforeAndDelay: 75 }))
files.push('the next station is', remainingStops[0])
}

Expand Down
42 changes: 11 additions & 31 deletions src/announcement-data/systems/rolling-stock/TLClass700.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class ThameslinkClass700 extends TrainAnnouncementSystem {
files.push(
...this.pluraliseAudio(
options.changeFor.map(poi => `station connections.${poi}`),
50,
{ beforeAndDelay: 50 },
),
)
}
Expand Down Expand Up @@ -211,21 +211,11 @@ export default class ThameslinkClass700 extends TrainAnnouncementSystem {
if (!this.validateStationExists(terminatesAtCode, 'low')) return

files.push(
...this.pluraliseAudio(
[
...callingAtCodes.map(
({ crsCode }): AudioItemObject => ({
id: `stations.high.${crsCode}`,
opts: { delayStart: 350 },
}),
),
{
id: `stations.low.${terminatesAtCode}`,
opts: { delayStart: 350 },
},
],
350,
),
...this.pluraliseAudio([...callingAtCodes.map(({ crsCode }) => `stations.high.${crsCode}`), `stations.low.${terminatesAtCode}`], {
beforeAndDelay: 350,
afterAndDelay: 350,
beforeItemDelay: 350,
}),
)
}

Expand Down Expand Up @@ -255,21 +245,11 @@ export default class ThameslinkClass700 extends TrainAnnouncementSystem {
if (!this.validateStationExists(terminatesAtCode, 'low')) return

files.push(
...this.pluraliseAudio(
[
...callingAtCodes.map(
({ crsCode }, i): AudioItemObject => ({
id: `stations.high.${crsCode}`,
opts: { delayStart: 350 },
}),
),
{
id: `stations.low.${terminatesAtCode}`,
opts: { delayStart: 350 },
},
],
350,
),
...this.pluraliseAudio([...callingAtCodes.map(({ crsCode }) => `stations.high.${crsCode}`), `stations.low.${terminatesAtCode}`], {
beforeAndDelay: 350,
afterAndDelay: 350,
beforeItemDelay: 350,
}),
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/announcement-data/systems/rolling-stock/TfLElizabeth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1219,14 +1219,14 @@ export default class TfLElizabethLine extends AnnouncementSystem {
if (nextStation.changeFor.length) {
files.push(
{ id: 'conjoiners.change for', opts: { delayStart: 1000 } },
...this.pluraliseAudio(nextStation.changeFor, 0, { andId: 'conjoiners.and', prefix: 'change for.m.', finalPrefix: 'change for.e.' }),
...this.pluraliseAudio(nextStation.changeFor, { andId: 'conjoiners.and', prefix: 'change for.m.', finalPrefix: 'change for.e.' }),
)
}

if (nextStation.exitFor.length) {
files.push(
{ id: 'conjoiners.exit for', opts: { delayStart: 1000 } },
...this.pluraliseAudio(nextStation.exitFor, 0, { andId: 'conjoiners.and', prefix: 'exit for.m.', finalPrefix: 'exit for.e.' }),
...this.pluraliseAudio(nextStation.exitFor, { andId: 'conjoiners.and', prefix: 'exit for.m.', finalPrefix: 'exit for.e.' }),
)
}

Expand Down
1 change: 0 additions & 1 deletion src/announcement-data/systems/rolling-stock/TfWTrainFx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default class TfWTrainFx extends TrainAnnouncementSystem {
files.push(
...this.pluraliseAudio(
callingAtCodes.map(stn => stn.crsCode),
0,
{ andId: 'conjoiners.and', prefix: 'stations.high.', finalPrefix: 'stations.low.' },
),
)
Expand Down
Loading

0 comments on commit 9bb3f1f

Please sign in to comment.