-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobile.js
280 lines (233 loc) · 6.73 KB
/
mobile.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// resizes everything for mobile devices
// AND resizes canvases for NON-mobile devices
// jQuery kind of looks like CSS, but different
let mobile = false;
let mobileWidth = 615;
let mobileHeight = 410;
$(document).ready(function() {
window.setTimeout(doMobileStuff, 200);
});
function doMobileStuff() {
// warn the client about possible bugs
/*window.alert("This game might have some bugs. If you do run into "
+ "a bug, refreshing the page should most likely fix it; "
+ "or at least temporarily. :)");*/
// check if device is a mobile device
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test
(navigator.userAgent)) {
mobile = true;
// call function in script.js to let server no, because not using socket.io in this file
letServerKnowPlayerIsMobile();
};
if(mobile) {
landscapeCheck();
// resize game canvases
// why does this actually work
/* I have no clue because I set the canvas css size to phone screen size,
but when game starts, js sets the canvas css size to what it should be for
computer. And somehow adding this code here scales the canvas down.*/
$("#layers").children().each(function() {
$(this).css({
"margin-top":"5px",
"width":"60vw",
"height":"65vh",
});
})
setMobileView();
}
else {
let mobileHeight = Math.floor(window.innerHeight - 70);
let mobileWidth = Math.floor(mobileHeight * 1.7);
// resize game canvases
$("#layers").children().each(function() {
$(this).css({
"margin-top":"0",
"width":mobileWidth.toString() + "px",
"height":mobileHeight.toString() + "px",
});
})
}
}
function landscapeCheck() {
let w = window.innerWidth;
let h = window.innerHeight;
if(h > w) {
window.alert("Please use landscape mode.");
window.setTimeout(
() => {landscapeCheck()}, 1500);
}
}
// actually make everything look good on mobile
function setMobileView() {
// menu stuff
let defaultMargin = "10px";
$(".menu").css({
"width":"100vw",
"height":"100vh",
"margin":"0",
"overflow": "auto"
});
// main menu
$("#menuTitle").css({
"font-size":"100px",
"margin":"0",
"margin-top":"-5vh"
});
$("#menuSubText").css({
"margin-bottom":"10px"
});
$(".menuButton").css({
"margin-bottom":"5px"
});
// settings
$("#settingsText").css({
"font-size":"25px",
"margin":"0",
"margin-bottom":defaultMargin,
"margin-left":"100px",
"margin-right":"100px"
});
// join
$("#joinInput").css({
// reorder join menu so input is on bottom
/* because sometimes the input keyboard-or-numberpad-thing
can go over and hide all of the other items*/
"order":"4",
"margin":"0"
});
// when entering game id shrink buttons and input so that keyboard won't hide input
$("#joinInput").focus(function() {
let newHeight = "40px";
$("#joinInput").css({
"height":"30px",
"width":"200px",
"font-size":"30px"
});
$("#joinMenuButtons").css({
"height":newHeight
});
$("#joinLobbyButton, #lobbyMainMenuButton").css({
"font-size":"35px",
"height":newHeight
});
$("#joinNotice").css({
"margin-top":"0",
});
});
// set things back to normal after game id input is out of focus
$("#joinInput").focusout(function() {
let newHeight = "58px";
$("#joinInput").css({
"height":"56px",
"width":"300px",
"font-size":"50px"
});
$("#joinMenuButtons").css({
"height":newHeight
});
$("#joinLobbyButton, #lobbyMainMenuButton").css({
"font-size":"50px",
"height":newHeight
});
$("#joinNotice").css({
"margin-top":"5px"
});
});
$("#joinNotice").css({
"margin":"0",
"margin-top":"5px"
});
// make join and main menu buttons left and right instead of up and down
$("#joinMenuButtons").css({
"display":"flex",
"flex-direction":"row",
"justify-content":"space-evenly",
"width":"95vw"
});
$("#joinLobbyButton, #lobbyMainMenuButton").css({
"margin":"0"
});
// move buttons beneath name change input to the left and right of input
$("#settingsDiv").css({
"flex-direction":"row"
});
// following 3 make input in the middle
$("#settingBackToMainMenuButton").css({
"order":1,
"width":250
});
$("#nameInput").css({
"order":2
});
$("#changeNameButton").css({
"order":3,
"width":250
});
// lobby
// make layout horizontal
$("#lobby").css({
"display":"flex",
"flex-direction":"row",
"justify-content":"flex-start",
"align-items":"flex-start"
});
$(".lobbyContainers").css({
"width":"45vw"
});
// add spacing between left and right
$("#firstLobbyContainer").css({
"width":"40vw",
"margin-right":"3.5vw"
});
$(".lobbyButtons").css({
"width":"100%"
});
// less spacing between you and players
$("#lobbyTopText").css({
"margin-top":"10px"
});
// make game id and you be aligned
$("#gameId").css({
"margin-top":"10px"
});
$("#playerName").css({
"margin-top":"3px",
"width":"90%",
"font-size":"25px"
});
// mobile controls
let dashSize = "110px";
$("#mobileDashImg, #mobileButtonsDash").css({
"width":dashSize,
"height":dashSize,
"margin":"0",
//"visibility":"hidden"
});
$("#mobileButtonsDash").css({
"margin-top":("-" + dashSize),
"visibility":"visible",
"opacity":"0"
});
$("#mobileDashContainer").css({
"width":dashSize,
"height":dashSize,
"position":"absolute",
//"margin-left":((mobileHorizontalMargin - 1) + "%"),
"margin-left":"80%",
"margin-top":"19%"
});
$("#joystickContainer").css({
"touch-action":"none",
"position":"absolute",
//"margin-right":(mobileHorizontalMargin + "%"),
"margin-right":"81%",
"margin-top":"15%",
//"visibility":"hidden"
});
$("#gameOverText").css({
"font-size":"150px",
"margin":"0",
"margin-top":"-10px"
});
window.scroll(0, 0);
}