Skip to content

Commit

Permalink
feat: allow rrb continuations on generator
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Mar 7, 2024
1 parent 826262b commit 6a07bff
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/announcement-data/AnnouncementSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface IBooleanOptions {
type: 'boolean'
default: boolean
onlyShowWhen?: (activeState: Record<string, unknown>) => boolean
disabled?: boolean
}
interface ITimeOptions {
name: string
Expand Down
2 changes: 2 additions & 0 deletions src/announcement-data/systems/stations/AmeyPhil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5170,6 +5170,7 @@ export default class AmeyPhil extends StationAnnouncementSystem {
enableShortPlatforms: this.SHORT_PLATFORMS,
enableRequestStops: true,
enableSplits: this.SPLITS,
enableRrbContinuations: true,
} as ICallingAtSelectorProps,
default: [],
},
Expand Down Expand Up @@ -5399,6 +5400,7 @@ export default class AmeyPhil extends StationAnnouncementSystem {
enableShortPlatforms: this.SHORT_PLATFORMS,
enableRequestStops: true,
enableSplits: this.SPLITS,
enableRrbContinuations: true,
} as ICallingAtSelectorProps,
default: [],
},
Expand Down
23 changes: 23 additions & 0 deletions src/components/CallingAtSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export interface ICallingAtSelectorProps {
* If false, splits and joins will be disabled. If an array, only the specified coach counts (for detachments) will be enabled.
*/
enableSplits?: false | { title: string; value: string }[]
/**
* If true, rail replacement continuations will be enabled.
*/
enableRrbContinuations?: boolean
}

function CallingAtSelector({
Expand All @@ -54,6 +58,7 @@ function CallingAtSelector({
enableShortPlatforms = false,
enableRequestStops = false,
enableSplits = false,
enableRrbContinuations = false,
className,
}: ICallingAtSelectorProps): JSX.Element {
const AvailableStations = React.useMemo(() => {
Expand Down Expand Up @@ -196,6 +201,24 @@ function CallingAtSelector({
},
)}

{enableRrbContinuations &&
createOptionField(
{
default: false,
name: 'Train ends; continues as replacement bus',
type: 'boolean',
// This can only happen once
disabled: value.some(s => s.continuesAsRrbAfterHere && s.randomId !== stop.randomId),
},
{
value: stop.continuesAsRrbAfterHere || false,
key: 'continuesAsRrbAfterHere',
onChange(v) {
onChange(value.map(s => (s.randomId === stop.randomId ? { ...s, continuesAsRrbAfterHere: v } : s)))
},
},
)}

{enableSplits && (
<>
{createOptionField(
Expand Down
12 changes: 9 additions & 3 deletions src/helpers/createOptionField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ export interface Option<Value extends string = string> {
readonly value: Value
}

export default function createOptionField(optionData: OptionsExplanation, options: OptionFieldOptions): JSX.Element {
if (optionData.onlyShowWhen?.(options.activeState) === false) {
export default function createOptionField(optionData: OptionsExplanation, options: OptionFieldOptions) {
if (optionData.onlyShowWhen?.(options?.activeState!!) === false) {
return null
}

switch (optionData.type) {
case 'boolean':
return (
<label key={options.key}>
<input type="checkbox" checked={options.value} onChange={e => options.onChange(e.currentTarget.checked)} /> {optionData.name}
<input
type="checkbox"
checked={options.value}
onChange={e => options.onChange(e.currentTarget.checked)}
disabled={optionData?.disabled || false}
/>{' '}
{optionData.name}
</label>
)

Expand Down
15 changes: 15 additions & 0 deletions src/styles/checkbox.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ input[type='checkbox'] {
&:checked::after {
opacity: 1;
}

&:disabled {
cursor: not-allowed;

&::after,
&::before {
border-color: #999;
cursor: not-allowed;
}

label:has(&) {
cursor: not-allowed;
color: #999;
}
}
}

0 comments on commit 6a07bff

Please sign in to comment.