-
Notifications
You must be signed in to change notification settings - Fork 318
/
floor.js
54 lines (45 loc) · 1.66 KB
/
floor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var asFloor = function(obj, floorLevel, yPosition, errorHandler) {
var floor = riot.observable(obj);
floor.level = floorLevel;
floor.yPosition = yPosition;
floor.buttonStates = {up: "", down: ""};
// TODO: Ideally the floor should have a facade where tryTrigger is done
var tryTrigger = function(event, arg1, arg2, arg3, arg4) {
try {
floor.trigger(event, arg1, arg2, arg3, arg4);
} catch(e) { errorHandler(e); }
};
floor.pressUpButton = function() {
var prev = floor.buttonStates.up;
floor.buttonStates.up = "activated";
if(prev !== floor.buttonStates.up) {
tryTrigger("buttonstate_change", floor.buttonStates);
tryTrigger("up_button_pressed", floor);
}
};
floor.pressDownButton = function() {
var prev = floor.buttonStates.down;
floor.buttonStates.down = "activated";
if(prev !== floor.buttonStates.down) {
tryTrigger("buttonstate_change", floor.buttonStates);
tryTrigger("down_button_pressed", floor);
}
};
floor.elevatorAvailable = function(elevator) {
if(elevator.goingUpIndicator && floor.buttonStates.up) {
floor.buttonStates.up = "";
tryTrigger("buttonstate_change", floor.buttonStates);
}
if(elevator.goingDownIndicator && floor.buttonStates.down) {
floor.buttonStates.down = "";
tryTrigger("buttonstate_change", floor.buttonStates);
}
};
floor.getSpawnPosY = function() {
return floor.yPosition + 30;
};
floor.floorNum = function() {
return floor.level;
};
return floor;
};