-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitleScreen.js
More file actions
66 lines (60 loc) · 2.04 KB
/
Copy pathTitleScreen.js
File metadata and controls
66 lines (60 loc) · 2.04 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
66
class TitleScreen {
constructor({ progress }) {
this.progress = progress;
this.titleMusic = new Sound("./Sound/title.mp3");
this.handleClick = () => {
// Play audio when the user interacts with the document
this.titleMusic.loop();
document.removeEventListener('click', handleClick);
};
document.addEventListener('click', this.handleClick, { once: true });
}
getOptions(resolve) {
const saveFile = this.progress.getSaveFile();
return [
{
label: "New Game",
description: "Start a new journey into the world of Evernight!",
handler: () => {
utils.emitEvent("NewGame");
this.close();
resolve();
}
},
saveFile ? {
label: "Continue Game",
description: "Resume previous adventure",
handler: () => {
this.close();
resolve(saveFile);
}
} : null,
{
label: "Music",
description: "Simply click anywhere on the screen to hear music",
},
].filter(v => v);
}
createElement() {
this.element = document.createElement("div");
this.element.classList.add("TitleScreen");
this.element.innerHTML = (`
<img class="TitleScreen_logo" src="./images/logo.png" alt="Evernight" />
`)
}
close() {
document.removeEventListener('click', this.handleClick);
this.titleMusic.stop();
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));
})
}
}