-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (55 loc) · 1.58 KB
/
main.js
File metadata and controls
64 lines (55 loc) · 1.58 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
// -- Lil'Dress Up -- //
///// Game Logic //////
const LOADING = 0;
const TITLE = 1;
const GAME = 2;
const FINISH = 3;
/**
* The different game screens.
* The index of these sections need to corelate to the above values.
* @type {HTMLElement[]}
*/
let sections = [
document.getElementById("loading"),
document.getElementById("title"),
document.getElementById("game"),
document.getElementById("finish")
];
/**
* The game's state
* @property {number} section - Index value of {@link sections}.
* @property {boolean} isLoading - Opposite return value of {@link DressUp#start}.
*/
let state = {
section: LOADING,
isLoading: true
};
/**
* Function that switches between game screens.
* @param {number} section - Corresponding index of {@link sections} for the target section.
*/
let switchSection = (section) => {
sections.forEach((item, i) => {
item.classList.add("hidden");
});
sections[section].classList.remove("hidden");
state.section = section;
};
/**
* Function for loading in the target {@link DressUp} object.
* @param {DressUp} dressup - The target game.
*/
let loadDressUp = async (dressup) => {
state.isLoading = (await dressup.start()) ? false : true;
switchSection(TITLE);
};
// Event listeners for switching between game screens.
document.getElementById("start_b").addEventListener("click", function () {
switchSection(2);
});
document.getElementById("finish_b").addEventListener("click", function () {
switchSection(3);
});
document.getElementById("back_b").addEventListener("click", function () {
switchSection(2);
});