TypeScript template for https://play.elevatorsaga.com/.
Simply download all the gist files and open up in VS code and you'll get type checking.
To run a solution simply copy the whole content of the JS file and paste it into the website.
TypeScript template for https://play.elevatorsaga.com/.
Simply download all the gist files and open up in VS code and you'll get type checking.
To run a solution simply copy the whole content of the JS file and paste it into the website.
| interface ElevatorEvents { | |
| idle: () => void; | |
| floor_button_pressed: (floorNum: number) => void; | |
| passing_floor: (floorNum: number, direction: "up" | "down") => void; | |
| stopped_at_floor: (floorNum: number) => void; | |
| } | |
| interface Elevator { | |
| goToFloor(floorNum: number, queueFirst?: boolean): void; | |
| stop(): void; | |
| currentFloor(): number; | |
| goingUpIndicator(state?: boolean): boolean; | |
| goingDownIndicator(state?: boolean): boolean; | |
| maxPassengerCount(): number; | |
| loadFactor(): number; | |
| destinationDirection(): "up" | "down" | "stopped"; | |
| destinationQueue: number[]; | |
| checkDestinationQueue(): void; | |
| getPressedFloors(): number[]; | |
| on<E extends keyof ElevatorEvents>(type: E, handler: ElevatorEvents[E]): void; | |
| } | |
| interface Floor { | |
| floorNum: number; | |
| on( | |
| type: "up_button_pressed" | "down_button_pressed", | |
| handler: () => void | |
| ): void; | |
| } | |
| interface GameState { | |
| init: (elevators: Elevator[], floors: Floor[]) => void; | |
| update: (dt: number, elevators: Elevator[], floors: Floor[]) => void; | |
| } |
| /// <reference path="./elevatorgame.d.ts" /> | |
| /** @type {GameState} */ | |
| ({ | |
| init: function(elevators, floors) { | |
| // Do stuff with the elevators and floors, which are both arrays of objects | |
| }, | |
| update: function(dt, elevators, floors) { | |
| // Do more stuff with the elevators and floors | |
| // dt is the number of game seconds that passed since the last time update was called | |
| } | |
| }) |
| { | |
| "compilerOptions": { | |
| "target": "es2016", | |
| "module": "None", | |
| "allowJs": true, | |
| "checkJs": true, | |
| "noEmit": true, | |
| "strict": true, | |
| "skipLibCheck": true | |
| } | |
| } |