Skip to content

Commit

Permalink
feat: "not calling at..." for amey
Browse files Browse the repository at this point in the history
See #230
  • Loading branch information
davwheat committed Jul 7, 2024
1 parent 5f27972 commit 0ac87a8
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/announcement-data/AnnouncementSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface CustomAnnouncementTab<OptionIds extends string> {
| 'system'
>
| ICustomButtonPaneProps
defaultState: Record<OptionIds, any>
}

export type CustomAnnouncementButton = {
Expand Down
168 changes: 161 additions & 7 deletions src/announcement-data/systems/stations/AmeyPhil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface INextTrainAnnouncementOptions {
firstClassLocation: FirstClassLocation
coaches: string
announceShortPlatformsAfterSplit: boolean
notCallingAtStations: { crsCode: string }[]
}

export interface IStandingTrainAnnouncementOptions extends Omit<INextTrainAnnouncementOptions, 'chime'> {
Expand Down Expand Up @@ -194,6 +195,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
mindTheGap: true,
thisStationCode: 'LIT',
firstClassLocation: 'none',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand Down Expand Up @@ -235,6 +238,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
mindTheGap: false,
thisStationCode: 'VIC',
firstClassLocation: 'none',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand All @@ -256,6 +261,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
mindTheGap: false,
thisStationCode: 'BTN',
firstClassLocation: 'none',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand Down Expand Up @@ -294,6 +301,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
coaches: '11 coaches',
mindTheGap: false,
firstClassLocation: 'rear',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand All @@ -315,6 +324,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
mindTheGap: false,
thisStationCode: 'MAN',
firstClassLocation: 'front',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand Down Expand Up @@ -376,6 +387,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
mindTheGap: false,
thisStationCode: 'ABD',
firstClassLocation: 'front',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand All @@ -400,6 +413,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
mindTheGap: false,
thisStationCode: 'MAN',
firstClassLocation: 'front',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand All @@ -421,6 +436,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
mindTheGap: false,
thisStationCode: 'MYB',
firstClassLocation: 'none',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand Down Expand Up @@ -456,6 +473,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
coaches: '3 coaches',
mindTheGap: false,
firstClassLocation: 'none',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
{
Expand All @@ -477,6 +496,8 @@ export default class AmeyPhil extends StationAnnouncementSystem {
coaches: '9 coaches',
mindTheGap: false,
firstClassLocation: 'none',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
},
],
Expand Down Expand Up @@ -4045,7 +4066,6 @@ export default class AmeyPhil extends StationAnnouncementSystem {
}
}

debugger
return files
}

Expand All @@ -4068,9 +4088,6 @@ export default class AmeyPhil extends StationAnnouncementSystem {
)

const order = Object.keys(shortPlatforms).sort((a, b) => a.localeCompare(b))

debugger

let firstAdded = false

order.forEach(s => {
Expand Down Expand Up @@ -4719,6 +4736,25 @@ export default class AmeyPhil extends StationAnnouncementSystem {
)),
)

if (options.notCallingAtStations.length > 0) {
files.push(
{ id: 's.please note this train will not call at', opts: { delayStart: 250 } },
...this.pluraliseAudio(
options.notCallingAtStations.map(s => s.crsCode),
{
prefix: 'station.m.',
finalPrefix: 'station.m.',
andId: 'm.and',
firstItemDelay: this.callingPointsOptions.afterCallingAtDelay,
beforeAndDelay: this.callingPointsOptions.aroundAndDelay,
beforeItemDelay: this.callingPointsOptions.betweenStopsDelay,
afterAndDelay: this.callingPointsOptions.aroundAndDelay,
},
),
'e.today',
)
}

files.push(
...getPlatFiles(this.BEFORE_SECTION_DELAY),
...(await this.getFilesForBasicTrainInfo(
Expand Down Expand Up @@ -4816,6 +4852,25 @@ export default class AmeyPhil extends StationAnnouncementSystem {
)
}

if (options.notCallingAtStations.length > 0) {
files.push(
{ id: 's.please note this train will not call at', opts: { delayStart: 250 } },
...this.pluraliseAudio(
options.notCallingAtStations.map(s => s.crsCode),
{
prefix: 'station.m.',
finalPrefix: 'station.m.',
andId: 'm.and',
firstItemDelay: this.callingPointsOptions.afterCallingAtDelay,
beforeAndDelay: this.callingPointsOptions.aroundAndDelay,
beforeItemDelay: this.callingPointsOptions.betweenStopsDelay,
afterAndDelay: this.callingPointsOptions.aroundAndDelay,
},
),
'e.today',
)
}

await this.playAudioFiles(files, download)
}

Expand Down Expand Up @@ -5370,6 +5425,21 @@ export default class AmeyPhil extends StationAnnouncementSystem {
nextTrain: {
name: 'Next train',
component: CustomAnnouncementPane,
defaultState: {
chime: 'three',
platform: this.PLATFORMS[1],
hour: '07',
min: '33',
isDelayed: false,
toc: '',
terminatingStationCode: this.STATIONS[0],
vias: [],
callingAt: [],
coaches: '8 coaches',
firstClassLocation: 'none',
announceShortPlatformsAfterSplit: false,
notCallingAtStations: [],
},
props: {
presets: this.announcementPresets.nextTrain,
playHandler: this.playNextTrainAnnouncement.bind(this),
Expand Down Expand Up @@ -5517,12 +5587,36 @@ export default class AmeyPhil extends StationAnnouncementSystem {
type: 'boolean',
default: false,
},
notCallingAtStations: {
name: '',
type: 'custom',
component: CallingAtSelector,
props: {
availableStations: [] as string[],
additionalOptions: this.STATIONS_AS_ITEMS,
selectLabel: 'Train does not call at',
placeholder: 'Add a "not" calling point…',
heading: 'Not calling at… (optional)',
} as ICallingAtSelectorProps,
default: [],
},
},
},
} as CustomAnnouncementTab<keyof INextTrainAnnouncementOptions>,
approachingTrain: {
name: 'Approaching train',
component: CustomAnnouncementPane,
defaultState: {
chime: 'three',
platform: this.PLATFORMS[1],
hour: '07',
min: '33',
isDelayed: false,
toc: '',
terminatingStationCode: this.STATIONS[0],
vias: [],
originStationCode: this.STATIONS[0],
},
props: {
playHandler: this.playTrainApproachingAnnouncement.bind(this),
options: {
Expand Down Expand Up @@ -5623,6 +5717,23 @@ export default class AmeyPhil extends StationAnnouncementSystem {
standingTrain: {
name: 'Standing train',
component: CustomAnnouncementPane,
defaultState: {
chime: 'three',
thisStationCode: this.STATIONS[0],
platform: this.PLATFORMS[1],
hour: '07',
min: '33',
isDelayed: false,
toc: '',
terminatingStationCode: this.STATIONS[0],
vias: [],
callingAt: [],
announceShortPlatformsAfterSplit: false,
coaches: '8 coaches',
firstClassLocation: 'none',
mindTheGap: false,
notCallingAtStations: [],
},
props: {
presets: this.announcementPresets.nextTrain.filter(x => 'thisStationCode' in x.state),
playHandler: this.playStandingTrainAnnouncement.bind(this),
Expand Down Expand Up @@ -5709,7 +5820,7 @@ export default class AmeyPhil extends StationAnnouncementSystem {
additionalOptions: this.STATIONS_AS_ITEMS,
selectLabel: 'Via points (non-splitting services only)',
placeholder: 'Add a via point…',
heading: 'Via... (optional)',
heading: 'Via (optional)',
} as ICallingAtSelectorProps,
default: [],
},
Expand Down Expand Up @@ -5771,12 +5882,36 @@ export default class AmeyPhil extends StationAnnouncementSystem {
type: 'boolean',
default: false,
},
notCallingAtStations: {
name: '',
type: 'custom',
component: CallingAtSelector,
props: {
availableStations: [] as string[],
additionalOptions: this.STATIONS_AS_ITEMS,
selectLabel: 'Train does not call at',
placeholder: 'Add a "not" calling point…',
heading: 'Not calling at… (optional)',
} as ICallingAtSelectorProps,
default: [],
},
},
},
} as CustomAnnouncementTab<keyof IStandingTrainAnnouncementOptions>,
disruptedTrain: {
name: 'Disrupted train',
component: CustomAnnouncementPane,
defaultState: {
chime: 'three',
hour: '07',
min: '33',
toc: '',
terminatingStationCode: this.STATIONS[0],
vias: [],
disruptionType: 'delayedBy',
delayTime: '65',
disruptionReason: '',
},
props: {
presets: this.announcementPresets.disruptedTrain,
playHandler: this.playDisruptedTrainAnnouncement.bind(this),
Expand Down Expand Up @@ -5851,7 +5986,7 @@ export default class AmeyPhil extends StationAnnouncementSystem {
additionalOptions: this.STATIONS_AS_ITEMS,
selectLabel: 'Via points (non-splitting services only)',
placeholder: 'Add a via point…',
heading: 'Via... (optional)',
heading: 'Via (optional)',
} as ICallingAtSelectorProps,
default: [],
},
Expand Down Expand Up @@ -5886,6 +6021,12 @@ export default class AmeyPhil extends StationAnnouncementSystem {
fastTrain: {
name: 'Fast train',
component: CustomAnnouncementPane,
defaultState: {
chime: 'three',
daktronicsFanfare: false,
fastTrainApproaching: false,
platform: this.PLATFORMS[1],
},
props: {
playHandler: this.playFastTrainAnnouncement.bind(this),
options: {
Expand Down Expand Up @@ -5921,6 +6062,19 @@ export default class AmeyPhil extends StationAnnouncementSystem {
platformAlteration: {
name: 'Platform alteration',
component: CustomAnnouncementPane,
defaultState: {
chime: 'three',
announceOldPlatform: false,
oldPlatform: this.PLATFORMS[6],
newPlatform: this.PLATFORMS[1],
hour: '07',
min: '33',
isDelayed: false,
toc: '',
terminatingStationCode: this.STATIONS[0],
vias: [],
callingAt: [],
},
props: {
presets: this.announcementPresets.nextTrain,
playHandler: this.playPlatformAlterationAnnouncement.bind(this),
Expand Down Expand Up @@ -6020,7 +6174,7 @@ export default class AmeyPhil extends StationAnnouncementSystem {
additionalOptions: this.STATIONS_AS_ITEMS,
selectLabel: 'Via points (non-splitting services only)',
placeholder: 'Add a via point…',
heading: 'Via... (optional)',
heading: 'Via (optional)',
} as ICallingAtSelectorProps,
default: [],
},
Expand Down
1 change: 1 addition & 0 deletions src/components/AnnouncementPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function AnnouncementPanel({ system }: IProps) {
savePersonalPreset={savePersonalPreset}
getPersonalPresets={getPersonalPresets}
deletePersonalPreset={deletePersonalPreset}
defaultState={JSON.stringify(opts.defaultState)}
/>
</AnnouncementTabErrorBoundary>
)
Expand Down
5 changes: 4 additions & 1 deletion src/components/PanelPanes/CustomAnnouncementPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ICustomAnnouncementPaneProps<OptionIds extends string> {
getPersonalPresets: (systemId: string, tabId: string) => Promise<IPersonalPresetObject[]>
deletePersonalPreset: (systemId: string, tabId: string, presetId: string) => Promise<void>
system: typeof AnnouncementSystem
defaultState: string
}

function CustomAnnouncementPane({
Expand All @@ -61,8 +62,10 @@ function CustomAnnouncementPane({
savePersonalPreset,
getPersonalPresets,
deletePersonalPreset,
defaultState: _defaultState,
}: ICustomAnnouncementPaneProps<string>) {
const { enqueueSnackbar } = useSnackbar()
const defaultState = JSON.parse(_defaultState)

const [playError, setPlayError] = React.useState<Error | null>(null)
const [isSharing, setIsSharing] = React.useState(false)
Expand Down Expand Up @@ -367,7 +370,7 @@ function CustomAnnouncementPane({
key={preset.presetId}
disabled={isPlayingAnnouncement}
presetData={preset}
onClick={() => setAllTabStates(prevState => ({ ...(prevState || {}), [tabId]: preset.state }))}
onClick={() => setAllTabStates(prevState => ({ ...(prevState || {}), [tabId]: { ...defaultState, ...preset.state } }))}
onDelete={() => deletePersonalPreset(systemId, tabId, preset.presetId).finally(loadPersonalPresetsForTab)}
/>
))}
Expand Down

0 comments on commit 0ac87a8

Please sign in to comment.