Skip to content

Instantly share code, notes, and snippets.

@hlysine
Created May 4, 2024 13:55
Show Gist options
  • Save hlysine/86c03f6401bacee99225b9d2adeb7728 to your computer and use it in GitHub Desktop.
Save hlysine/86c03f6401bacee99225b9d2adeb7728 to your computer and use it in GitHub Desktop.
Elevator Saga Type Definitions
/**
* Type definitions for the Elevator Saga programming game at https://play.elevatorsaga.com/
*/
declare module 'elevator-saga' {
export interface ElevatorEvents {
/**
* Triggered when the elevator has completed all its tasks and is not doing anything.
*/
(event: 'idle', fn: () => void): void;
/**
* Triggered when a passenger has pressed a button inside the elevator.
*/
(event: 'floor_button_pressed', fn: (floorNum: number) => void): void;
/**
* Triggered slightly before the elevator will pass a floor. A good time to decide whether to stop at that floor. Note that this event is not triggered for the destination floor. Direction is either "up" or "down".
*/
(event: 'passing_floor', fn: (floorNum: number, direction: 'up' | 'down') => void): void;
/**
* Triggered when the elevator has arrived at a floor.
*/
(event: 'stopped_at_floor', fn: (floorNum: number) => void): void;
}
export interface FloorEvents {
/**
* Triggered when someone has pressed the up button at a floor. Note that passengers will press the button again if they fail to enter an elevator.
*/
(event: 'up_button_pressed', fn: () => void): void;
/**
* Triggered when someone has pressed the down button at a floor. Note that passengers will press the button again if they fail to enter an elevator.
*/
(event: 'down_button_pressed', fn: () => void): void;
}
export interface Elevator {
/**
* Checks the destination queue for any new destinations to go to. Note that you only need to call this if you modify the destination queue explicitly.
*/
readonly checkDestinationQueue: () => void;
/**
* Gets the floor number that the elevator currently is on.
*/
readonly currentFloor: () => number;
/**
* Gets the direction the elevator is currently going to move toward. Can be "up", "down" or "stopped".
*/
readonly destinationDirection: () => 'up' | 'down' | 'stopped';
/**
* The current destination queue, meaning the floor numbers the elevator is scheduled to go to. Can be modified and emptied if desired. Note that you need to call checkDestinationQueue() for the change to take effect immediately.
*/
destinationQueue: number[];
// readonly getFirstPressedFloor: () => number;
/**
* Gets the currently pressed floor numbers as an array.
*/
readonly getPressedFloors: () => number[];
/**
* Queue the elevator to go to specified floor number. If you specify true as second argument, the elevator will go to that floor directly, and then go to any other queued floors.
*/
readonly goToFloor: (floorNum: number, forceNow: boolean) => void;
/**
* Gets or sets the going down indicator, which will affect passenger behaviour when stopping at floors.
*/
readonly goingDownIndicator: (() => boolean) | ((state: boolean) => void);
/**
* Gets or sets the going up indicator, which will affect passenger behaviour when stopping at floors.
*/
readonly goingUpIndicator: () => boolean;
/**
* Gets the load factor of the elevator. 0 means empty, 1 means full. Varies with passenger weights, which vary - not an exact measure.
*/
readonly loadFactor: () => number;
/**
* Gets the maximum number of passengers that can occupy the elevator at the same time.
*/
readonly maxPassengerCount: () => number;
/**
* Clear the destination queue and stop the elevator if it is moving. Note that you normally don't need to stop elevators - it is intended for advanced solutions with in-transit rescheduling logic. Also, note that the elevator will probably not stop at a floor, so passengers will not get out.
*/
readonly stop: () => void;
readonly on: ElevatorEvents;
readonly off: ElevatorEvents;
readonly one: ElevatorEvents;
}
export interface Floor {
readonly buttonStates: {
up: '' | 'activated';
down: '' | 'activated';
};
readonly elevatorAvailable: (elevator: Elevator) => boolean;
/**
* Gets the floor number of the floor object.
*/
readonly floorNum: () => number;
// readonly getSpawnPosY: () => number;
// readonly level: number;
// readonly pressDownButton: () => void;
// readonly pressUpButton: () => void;
// readonly yPosition: number;
readonly on: FloorEvents;
readonly off: FloorEvents;
readonly one: FloorEvents;
}
export interface GameObject {
init: (elevators: Elevator[], floors: Floor[]) => void;
update: (dt: number, elevators: Elevator[], floors: Floor[]) => void;
}
}
// @ts-check
/*
* Copy this file and the declaration file above to VS Code to get started.
*/
/** @type {import('elevator-saga').GameObject} */
({
init: function (elevators, floors) {
},
update: function (dt, elevators, floors) {
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment