Preserve elevator stop order and handle viewport resize

This commit is contained in:
sudhir
2026-05-20 00:52:01 +00:00
committed by open-pascal
parent d7a1ce89f3
commit a3378a666d
5 changed files with 107 additions and 64 deletions
@@ -49,6 +49,7 @@ export type ElevatorInteractiveState = {
phase: ElevatorPhase
phaseStartedAt: number | null
queue: AnyNodeId[]
requestedStops: AnyNodeId[]
}
type InteractiveStore = {
@@ -241,6 +242,7 @@ export const useInteractive = create<InteractiveStore>((set, get) => ({
phase: 'idle',
phaseStartedAt: null,
queue: [],
requestedStops: [],
},
},
}))
@@ -30,7 +30,9 @@ describe('elevator runtime helpers', () => {
const duplicated = queueElevatorRequest(queued, upperLevelId)
expect(queued.queue).toEqual([upperLevelId])
expect(queued.requestedStops).toEqual([upperLevelId])
expect(duplicated.queue).toEqual([upperLevelId])
expect(duplicated.requestedStops).toEqual([upperLevelId])
})
test('opens doors only when the elevator is not moving', () => {
@@ -78,5 +80,6 @@ describe('elevator runtime helpers', () => {
expect(arrived.phase).toBe('opening')
expect(open.phase).toBe('open')
expect(open.queue).toEqual([])
expect(open.requestedStops).toEqual([upperLevelId])
})
})
@@ -23,6 +23,7 @@ export function createElevatorInteractiveState(
phase: 'idle',
phaseStartedAt: null,
queue: [],
requestedStops: [],
}
}
@@ -64,6 +65,9 @@ export function queueElevatorRequest(
return {
...state,
queue: [...state.queue, levelId],
requestedStops: state.requestedStops.includes(levelId)
? state.requestedStops
: [...state.requestedStops, levelId],
}
}
@@ -124,6 +128,7 @@ export function stepElevatorRuntimeState({
phase: 'idle',
phaseStartedAt: null,
queue: [],
requestedStops: [],
doorOpen: 0,
}
}
@@ -147,7 +152,11 @@ export function stepElevatorRuntimeState({
doorOpen: Math.max(0, state.doorOpen - doorStep),
}
}
return state
if (state.requestedStops.length === 0) return state
return {
...state,
requestedStops: [],
}
}
return {
@@ -180,6 +189,7 @@ export function stepElevatorRuntimeState({
targetLevelId: null,
phase: 'idle',
queue: [],
requestedStops: [],
}
}