Repository navigation
Expand file tree
/
Copy pathTitleScreen.js
More file actions
65 lines (56 loc) · 1.91 KB
/
Copy pathTitleScreen.js
File metadata and controls
65 lines (56 loc) · 1.91 KB
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
62
63
64
65
// will have a different structure - we only want the user's option, so the init method will be async
// and will return a promise - this allows the code to wait for the user's response
// before running the rest of the code.
// (instead of having the onComplete structure inside of the constructor)
class TitleScreen {
constructor() {
}
getOptions(resolve) {
return [
{
label: "Play",
description: "Start game!",
handler: () => {
this.close();
resolve();
}
},
{
label: "Instructions",
description: "Use WASD to move, space to interact.",
handler: () => {
}
},
{
label: "Credits",
description: "Developed by Serena Yung ^-^",
handler: () => {
}
},
]
}
createElement() {
this.element = document.createElement("div");
this.element.classList.add("TitleScreen");
this.element.innerHTML = (`
<img class="TitleScreen_logo" src="images/cutscenes/prologue/warr.png" />
<div class="container">
<h1>A Lost Promise</h1>
</div>
`);
}
close() {
this.keyboardMenu.end();
this.element.remove();
}
init(container) {
return new Promise(resolve => {
this.createElement();
container.appendChild(this.element);
this.keyboardMenu = new KeyboardMenu();
this.keyboardMenu.init(this.element);
this.keyboardMenu.setOptions(this.getOptions(resolve)) // pass the resolver through the getOptions()
// so that the handler in getOptions() can fire that resolver
})
}
}