Skip to content

Instantly share code, notes, and snippets.

@saravanak
Created August 2, 2024 07:25
Show Gist options
  • Save saravanak/4f778729741fe15fdf904ae1140f29c9 to your computer and use it in GitHub Desktop.
Save saravanak/4f778729741fe15fdf904ae1140f29c9 to your computer and use it in GitHub Desktop.
Elevator Plugin Script
export const DIRS = {
UP: 1,
DOWN: 2,
STOPPED: 0,
};
class ElevatorLogic {
currentFloor = 1;
maxFloors = 1;
currentDirection = DIRS.STOPPED;
destinationFloor: number = -1;
constructor(numFloors: number) {
this.maxFloors = numFloors;
}
onFloorChanged() {
if (this.currentFloor == this.destinationFloor) {
this.currentDirection = DIRS.STOPPED;
}
}
onFloorSelected(floor: number) {
this.destinationFloor = floor;
}
onCalled(floor: number, direction: number) {
this.destinationFloor = floor;
console.log(direction);
}
onReady() {
if (this.currentFloor < this.destinationFloor) {
this.currentDirection = DIRS.UP;
} else if (this.currentFloor > this.destinationFloor) {
this.currentDirection = DIRS.DOWN;
}
}
}
export default ElevatorLogic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment