54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
class OverworldEvent {
|
|
constructor({map, event}) {
|
|
this.map = map;
|
|
this.event = event;
|
|
}
|
|
|
|
stand(resolve) {
|
|
const who = this.map.gameObjects[ this.event.who ];
|
|
who.startBehavior({
|
|
map: this.map
|
|
}, {
|
|
type: "stand",
|
|
direction: this.event.direction,
|
|
time: this.event.time
|
|
})
|
|
|
|
// handler to complete when correct person is done walking
|
|
const completeHandler = e => {
|
|
if (e.detail.whoId === this.event.who) {
|
|
document.removeEventListener("PersonStandComplete", completeHandler);
|
|
resolve();
|
|
}
|
|
}
|
|
|
|
document.addEventListener("PersonStandComplete", completeHandler)
|
|
}
|
|
|
|
walk(resolve) {
|
|
const who = this.map.gameObjects[ this.event.who ];
|
|
who.startBehavior({
|
|
map: this.map
|
|
}, {
|
|
type: "walk",
|
|
direction: this.event.direction,
|
|
retry: true
|
|
})
|
|
|
|
// handler to complete when correct person is done walking
|
|
const completeHandler = e => {
|
|
if (e.detail.whoId === this.event.who) {
|
|
document.removeEventListener("PersonWalkingComplete", completeHandler);
|
|
resolve();
|
|
}
|
|
}
|
|
|
|
document.addEventListener("PersonWalkingComplete", completeHandler)
|
|
}
|
|
|
|
init() {
|
|
return new Promise(resolve => {
|
|
this[this.event.type](resolve)
|
|
})
|
|
}
|
|
} |