-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhome.js
93 lines (92 loc) · 2.59 KB
/
home.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var username
var user
let mobileLayout
function HomeSetup() {
startButton = select("#startButton")
newOnlineButton = select("#newOnlineButton")
input = select("#input")
username = select("#username")
newLocalButton = select("#newLocalButton")
howToPlayButton = select("#howToPlayButton")
customizeButton = select("#customizeButton")
homeButton = select("#homeButton")
openGamesButton = select("#openGamesButton")
profileBox = select("#profileBox")
openGames = select("#openGames")
home = select("#home")
profile = select("#profile")
mobileLayout = false
firebase.auth().onAuthStateChanged((changedUser) => {
user = changedUser
if (changedUser.displayName != undefined) username.value(changedUser.displayName)
})
UpdateHomePanels()
customizeButton.mousePressed(() => {
profile.removeClass("hidden")
home.addClass("hidden")
openGames.addClass("hidden")
})
homeButton.mousePressed(() => {
profile.addClass("hidden")
home.removeClass("hidden")
openGames.addClass("hidden")
})
openGamesButton.mousePressed(() => {
profile.addClass("hidden")
home.addClass("hidden")
openGames.removeClass("hidden")
})
startButton.mousePressed(() => {
gameID = input.value()
if (user.displayName != username.value()) {
SetUsername(username.value(), () => {
ChangePage(gamepage)
})
} else {
ChangePage(gamepage)
}
})
newOnlineButton.mousePressed(() => {
CreateNewGame(user, defaultGameSettings).then(() => {
if (user.displayName != username.value()) {
SetUsername(username.value(), () => {
ChangePage(gamepage)
})
} else {
ChangePage(gamepage)
}
})
})
newLocalButton.mousePressed(() => {
gameID = "local"
ChangePage(gamepage)
})
howToPlayButton.mousePressed(() => {
ChangePage(rulespage)
})
UpdateHomePanels()
}
var resize = new ResizeObserver((entries) => {
UpdateHomePanels()
})
function UpdateHomePanels() {
if (window.innerWidth < 1000 && !mobileLayout) {
mobileLayout = true
profile.addClass("hidden")
home.removeClass("hidden")
openGames.addClass("hidden")
}
if (window.innerWidth > 1000) {
mobileLayout = false
profile.removeClass("hidden")
home.removeClass("hidden")
openGames.removeClass("hidden")
}
}
resize.observe(document.body)
// input.addEventListener("keydown", (e) => { //Press enter in the input field to join
// if (e.code === "Enter") {
// gameID = input.value()
// Username()
// }
// })