-
Notifications
You must be signed in to change notification settings - Fork 2
/
lvl1.js
61 lines (60 loc) · 1.35 KB
/
lvl1.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
55
56
57
58
59
60
61
function sleep(ms) {
return new Promise(function(resolve) {setTimeout(resolve, ms)});
}
exports.pickup = function(hud, PObject, actions) {
return function(objectName) {
async function x() {
var object = hud.GetInteractable(objectName);
if (object) {
var seconds = PObject.TurnTo(object.GetActorLocation());
await sleep(seconds);
seconds = PObject.WalkTo(object.GetActorLocation(), 200);
await sleep(seconds);
} else {
throw "Invalid Name"
}
return new Promise(function(resolve) {
resolve();
});
}
actions.list[actions.list.length] = x;
}
}
exports._advance = function(hud, PObject, actions) {
return function() {
async function x() {
hud.nextLevel();
return new Promise(function(resolve) {
resolve();
});
}
actions.list[actions.list.length] = x;
}
}
exports._remove = function(hud, PObject, actions) {
async function exec(resolve) {
if (actions.list.length === 0) {
actions.running = false;
resolve();
} else {
actions.running = true;
try {
await (actions.list.shift(1))();
exec(resolve);
} catch (e) {
hud.Output(e + "");
actions.running = false;
actions.list = [];
resolve();
}
}
}
function init() {
return new Promise(
function(resolve){
exec(resolve);
}
);
}
return init;
}