-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
693 lines (626 loc) · 26.4 KB
/
index.html
File metadata and controls
693 lines (626 loc) · 26.4 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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<!DOCTYPE html>
<html lang="en-us">
<head>
<base href="https://cdn.jsdelivr.net/gh/genizy/brainrot@main/draw-joust/">
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<title>DrawJoust</title>
<link rel="shortcut icon" href="TemplateData/favicon.ico"/>
<link rel="stylesheet" href="TemplateData/style.css"/>
<!-- Yandex Games SDK -->
<script src="https://cdn.jsdelivr.net/gh/gn-math/assets@main/yandex-sdk.js?lol"></script>
<!-- Additional head modules -->
</head>
<body class="dark">
<div id="unity-container" class="unity-desktop">
<canvas id="unity-canvas"></canvas>
</div>
<div id="loading-cover" style="display:none;">
<div id="unity-loading-bar">
<div id="unity-logo"><img src="logo.png"/></div>
<div id="unity-progress-bar-empty" style="display: none;">
<div id="unity-progress-bar-full"></div>
</div>
<div class="spinner"></div>
</div>
</div>
<!-- Additional body modules -->
<script>
const hideFullScreenButton = "";
const buildUrl = "Build";
const loaderUrl = buildUrl + "/DrawJoustAB.loader.js";
const config = {
dataUrl: buildUrl + "/DrawJoustAB.data.unityweb",
frameworkUrl: buildUrl + "/DrawJoustAB.framework.js.unityweb",
codeUrl: buildUrl + "/DrawJoustAB.wasm.unityweb",
streamingAssetsUrl: "StreamingAssets",
companyName: "DefaultCompany",
productName: "DrawJoust",
productVersion: "0.1",
};
const container = document.querySelector("#unity-container");
const canvas = document.querySelector("#unity-canvas");
const loadingCover = document.querySelector("#loading-cover");
const progressBarEmpty = document.querySelector("#unity-progress-bar-empty");
const progressBarFull = document.querySelector("#unity-progress-bar-full");
const spinner = document.querySelector('.spinner');
const canFullscreen = (function () {
for (const key of [
'exitFullscreen',
'webkitExitFullscreen',
'webkitCancelFullScreen',
'mozCancelFullScreen',
'msExitFullscreen',
]) {
if (key in document) {
return true;
}
}
return false;
}());
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
container.className = "unity-mobile";
}
canvas.style.background = "url('background.jpg') center / cover";
loadingCover.style.display = "";
canvas.addEventListener("touchstart", () => { window.focus() });
canvas.addEventListener("pointerdown", () => { window.focus() });
let player;
let leaderboard;
let myGameInstance = null;
let payments = null;
let promptCanShow = false;
let reviewCanShow = false;
let initSDK = false;
let initGame = false;
let photoSizeForInit;
let scopesForInit;
let nowFullAdOpen = false;
let letGameReadyApi = true;
const script = document.createElement("script");
script.src = loaderUrl;
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {
spinner.style.display = "none";
progressBarEmpty.style.display = "";
progressBarFull.style.width = `${100 * progress}%`;
}).then((unityInstance) => {
myGameInstance = unityInstance;
loadingCover.style.display = "none";
}).catch((message) => {
alert(message);
});
};
InitYandex();
function InitYandex() {
YaGames.init()
.then(ysdk => {
console.log('Init Yandex SDK');
window.ysdk = ysdk;
InitPayments();
try {
ysdk.shortcut.canShowPrompt().then(prompt => {
if (prompt.canShow) {
promptCanShow = true;
}
});
} catch (e) {
console.error('CRASH canShowPrompt: ', e.message);
}
try {
ysdk.feedback.canReview().then(({ value, reason }) => {
if (value) {
reviewCanShow = true;
} else {
console.log('reviewCanShow = false', reason)
}
})
ysdk.shortcut.canShowPrompt().then(prompt => {
if (prompt.canShow) {
promptCanShow = true;
}
});
} catch (e) {
console.error('CRASH canShowFeedback: ', e.message);
}
// First ad false
if (initGame) {
InitPlayer(photoSize, scopes);
}
initSDK = true;
});
}
function InitGame(photoSize, scopes, gameReadyApi) {
console.log('Init GAME');
initGame = true;
photoSizeForInit = photoSize;
scopesForInit = scopes;
if (initSDK == true) {
if (gameReadyApi == true)
GameReadyAPI();
InitPlayer(photoSize, scopes);
}
else {
InitYandex();
setTimeout(function () {
if (!initSDK) {
console.error('CRASH InitYandex');
NotAuthorized();
}
}, 1000);
}
if (nowFullAdOpen == true) {
myGameInstance.SendMessage('YandexGame', 'OpenFullAd');
}
}
function GameReadyAPI() {
if (letGameReadyApi) {
ysdk.features.LoadingAPI?.ready();
letGameReadyApi = false;
console.log('Game Ready API');
}
}
function NotAuthorized() {
try {
console.log('Authorized failed');
let authJson = {
"playerAuth": "rejected",
"playerName": "unauthorized",
"playerId": "unauthorized",
"playerPhoto": "null"
};
myGameInstance.SendMessage('YandexGame', 'SetInitializationSDK', JSON.stringify(authJson));
} catch (e) {
console.error('CRASH Not Authorized: ', e.message);
}
}
function InitPlayer(photoSize, _scopes) {
try {
return ysdk.getPlayer({ scopes: _scopes }).then(_player => {
player = _player;
let playerName = player.getName();
let playerPhoto = player.getPhoto(photoSize);
if (!_scopes) {
playerName = "anonymous";
playerPhoto = "null";
}
if (player.getMode() === 'lite') {
console.log('Not Authorized');
NotAuthorized();
} else {
let authJson = {
"playerAuth": "resolved",
"playerName": playerName,
"playerId": player.getUniqueID(),
"playerPhoto": playerPhoto
};
myGameInstance.SendMessage('YandexGame', 'SetInitializationSDK', JSON.stringify(authJson));
window.focus();
}
}).catch(e => {
console.error('Authorized err: ', e.message);
NotAuthorized();
});
} catch (e) {
console.error('CRASH init Player: ', e.message);
window.focus();
}
}
function OpenAuthDialog(photoSize, scopes) {
try {
ysdk.auth.openAuthDialog().then(() => {
InitPlayer(photoSize, scopes);
}).catch(() => {
InitSDK(photoSize, scopes);
});
} catch (e) {
console.log('CRASH Open Auth Dialog: ', e.message);
}
}
function FullAdShow() {
try {
window.ysdk.adv.showFullscreenAdv(
{
callbacks: {
onOpen: () => {
console.log('Open Fullscreen Ad');
nowFullAdOpen = true;
if (initGame === true)
myGameInstance.SendMessage('YandexGame', 'OpenFullAd');
},
onClose: (wasShown) => {
nowFullAdOpen = false;
if (initGame === true) {
if (wasShown) {
myGameInstance.SendMessage('YandexGame', 'CloseFullAd', 'true');
}
else {
myGameInstance.SendMessage('YandexGame', 'CloseFullAd', 'false');
}
}
window.focus();
},
onError: (error) => {
console.error('Error Fullscreen Ad', error);
myGameInstance.SendMessage('YandexGame', 'ErrorFullAd');
window.focus();
}
}
});
} catch (e) {
console.error('CRASH FullAd Show: ', e.message);
}
}
function RewardedShow(id) {
try {
window.ysdk.adv.showRewardedVideo(
{
callbacks:
{
onOpen: () => {
console.log('Opened Video Ad. Id: ' + id);
myGameInstance.SendMessage('YandexGame', 'OpenVideo');
},
onClose: () => {
console.log('Closed Video Ad. Id: ' + id);
myGameInstance.SendMessage('YandexGame', 'CloseVideo');
window.focus();
},
onRewarded: () => {
console.log('Reward Video Ad. Id: ' + id);
myGameInstance.SendMessage('YandexGame', 'RewardVideo', id);
},
onError: (e) => {
console.error('Error Video Ad. Id: ' + id, e);
myGameInstance.SendMessage('YandexGame', 'ErrorVideo');
}
}
});
} catch (err) {
console.error('CRASH Rewarded Video Ad Show: ', err.message);
}
}
function StickyAdActivity(show) {
try {
ysdk.adv.getBannerAdvStatus().then(({ stickyAdvIsShowing, reason }) => {
if (stickyAdvIsShowing) {
if (!show) {
ysdk.adv.hideBannerAdv();
}
}
else if (reason) {
console.log('Sticky ad are not shown. Reason:', reason);
}
else if (show) {
ysdk.adv.showBannerAdv();
}
})
} catch (e) {
console.error('CRASH Sticky Activity: ', e.message);
}
}
function InitPayments() {
try {
ysdk.getPayments().then(_payments => {
console.log('Purchases are available');
payments = _payments;
}).catch(e => {
console.log('Purchases are not available', e.message);
})
} catch (e) {
console.error('CRASH Init Payments: ', e.message);
}
}
function BuyPayments(id) {
try {
if (payments != null) {
payments.purchase(id).then(() => {
console.log('Purchase Success');
ConsumePurchase(id);
window.focus();
}).catch(e => {
console.error('Purchase Failed', e.message);
myGameInstance.SendMessage('YandexGame', 'OnPurchaseFailed', id);
window.focus();
})
} else {
console.log('Payments == null');
}
} catch (e) {
console.error('CRASH Buy Payments: ', e.message);
window.focus();
}
}
function GetPayments() {
try {
if (payments != null) {
payments.getCatalog()
.then(products => {
let productID = [];
let title = [];
let description = [];
let imageURI = [];
let priceValue = [];
let consumed = [];
payments.getPurchases().then(purchases => {
for (let i = 0; i < products.length; i++) {
productID[i] = products[i].id;
title[i] = products[i].title;
description[i] = products[i].description;
imageURI[i] = products[i].imageURI;
priceValue[i] = products[i].priceValue;
consumed[i] = true;
for (i2 = 0; i2 < purchases.length; i2++) {
if (purchases[i2].productID === productID[i]) {
consumed[i] = false;
break;
}
}
}
let jsonPayments = {
"id": productID,
"title": title,
"description": description,
"imageURI": imageURI,
"priceValue": priceValue,
"consumed": consumed
};
myGameInstance.SendMessage('YandexGame', 'PaymentsEntries', JSON.stringify(jsonPayments));
});
});
}
else {
console.log('Get Payments: payments == null');
}
} catch (e) {
console.error('CRASH Get Payments: ', e.message);
}
}
function ConsumePurchase(id) {
try {
if (payments != null) {
payments.getPurchases().then(purchases => {
for (i = 0; i < purchases.length; i++) {
if (purchases[i].productID === id) {
payments.consumePurchase(purchases[i].purchaseToken);
myGameInstance.SendMessage('YandexGame', 'OnPurchaseSuccess', id);
}
}
});
}
else console.log('Consume purchase: payments null');
} catch (e) {
console.error('CRASH Consume Purchase: ', e.message);
}
}
function ConsumePurchases() {
try {
if (payments != null) {
payments.getPurchases().then(purchases => {
console.log('Unprocessed purchases: ', purchases.length);
for (i = 0; i < purchases.length; i++) {
payments.consumePurchase(purchases[i].purchaseToken);
myGameInstance.SendMessage('YandexGame', 'OnPurchaseSuccess', purchases[i].productID);
}
});
}
else console.log('Consume purchases: payments null');
} catch (e) {
console.error('CRASH Consume purchases: ', e.message);
}
}
function SaveCloud(jsonData, flush) {
try {
player.setData({
saves: [jsonData],
}, flush);
} catch (e) {
console.error('CRASH Save Cloud: ', e.message);
}
}
function LoadCloud() {
try {
player.getData(["saves"]).then(data => {
if (data.saves) {
myGameInstance.SendMessage('YandexGame', 'SetLoadSaves', JSON.stringify(data.saves));
} else {
myGameInstance.SendMessage('YandexGame', 'SetLoadSaves', "noData");
}
}).catch(() => {
console.error('getData Error!');
myGameInstance.SendMessage('YandexGame', 'SetLoadSaves', "noData");
});
} catch (e) {
console.error('CRASH Load saves Cloud: ', e.message);
myGameInstance.SendMessage('YandexGame', 'SetLoadSaves', "noData");
}
}
function InitLeaderboard() {
try {
ysdk.getLeaderboards().then(_lb => {
leaderboard = _lb
myGameInstance.SendMessage('YandexGame', 'InitializedLB');
});
} catch (e) {
console.error('CRASH Init Leaderboard: ', e.message);
}
}
function SetLeaderboardScores(_name, score) {
try {
ysdk.getLeaderboards()
.then(leaderboard => {
leaderboard.setLeaderboardScore(_name, score);
});
} catch (e) {
console.error('CRASH Set Leader board Scores: ', e.message);
}
}
function GetLeaderboardScores(nameLB, maxPlayers, quantityTop, quantityAround, photoSize, auth) {
try {
var jsonEntries = {
technoName: '',
isDefault: false,
isInvertSortOrder: false,
decimalOffset: 0,
type: '' // , title: ''
};
ysdk.getLeaderboards()
.then(leaderboard => leaderboard.getLeaderboardDescription(nameLB))
.then(res => {
jsonEntries.technoName = nameLB;
jsonEntries.isDefault = res.default;
jsonEntries.isInvertSortOrder = res.description.invert_sort_order;
jsonEntries.decimalOffset = res.description.score_format.options.decimal_offset;
jsonEntries.type = res.description.type; // Не определяется на момент 18.07.23
//jsonEntries.title = res.title; // Реализуйте по предпочтениям
return leaderboard.getLeaderboardEntries(nameLB, {
quantityTop: quantityTop,
includeUser: auth,
quantityAround: quantityAround
});
})
.then(res => {
let jsonPlayers = EntriesLB(res, maxPlayers, photoSize);
let combinedJson = { ...jsonEntries, ...jsonPlayers };
myGameInstance.SendMessage('YandexGame', 'LeaderboardEntries', JSON.stringify(combinedJson));
})
.catch(error => {
console.error(error);
});
}
catch (e) {
console.error('CRASH Get Leaderboard: ', e.message);
}
}
function EntriesLB(res, maxPlayers, photoSize) {
let LeaderboardEntriesText = '';
let playersCount;
if (res.entries.length < maxPlayers) {
playersCount = res.entries.length;
} else {
playersCount = maxPlayers;
}
let ranks = new Array(playersCount);
let photos = new Array(playersCount);
let mames = new Array(playersCount);
let scores = new Array(playersCount);
let uniqueIDs = new Array(playersCount);
for (i = 0; i < playersCount; i++) {
ranks[i] = res.entries[i].rank;
scores[i] = res.entries[i].score;
uniqueIDs[i] = res.entries[i].player.uniqueID;
if (photoSize === 'nonePhoto' || res.entries[i].player.scopePermissions.avatar !== "allow") {
photos[i] = 'nonePhoto';
} else {
photos[i] = res.entries[i].player.getAvatarSrc(photoSize);
}
if (res.entries[i].player.scopePermissions.public_name !== "allow") {
mames[i] = "anonymous";
} else {
mames[i] = res.entries[i].player.publicName;
}
LeaderboardEntriesText += ranks[i] + '. ' + mames[i] + ": " + scores[i] + '\n';
}
if (playersCount === 0) {
LeaderboardEntriesText = 'no data';
}
let jsonPlayers = {
"entries": LeaderboardEntriesText,
"ranks": ranks,
"photos": photos,
"names": mames,
"scores": scores,
"uniqueIDs": uniqueIDs
};
return jsonPlayers;
}
function LanguageRequest() {
try {
myGameInstance.SendMessage('YandexGame', 'SetLanguage', ysdk.environment.i18n.lang);
} catch (e) {
console.error('CRASH Language Request: ', e.message);
}
}
function RequestingEnvironmentData() {
try {
let jsonEnvir = {
"language": ysdk.environment.i18n.lang,
"domain": ysdk.environment.i18n.tld,
"deviceType": ysdk.deviceInfo.type,
"isMobile": ysdk.deviceInfo.isMobile(),
"isDesktop": ysdk.deviceInfo.isDesktop(),
"isTablet": ysdk.deviceInfo.isTablet(),
"isTV": ysdk.deviceInfo.isTV(),
"appID": ysdk.environment.app.id,
"browserLang": ysdk.environment.browser.lang,
"payload": ysdk.environment.payload,
"promptCanShow": promptCanShow,
"reviewCanShow": reviewCanShow
};
myGameInstance.SendMessage('YandexGame', 'SetEnvironmentData', JSON.stringify(jsonEnvir));
} catch (e) {
console.error('CRASH Requesting Environment Data: ', e.message);
}
}
function Review() {
try {
ysdk.feedback.canReview()
.then(({ value, reason }) => {
if (value) {
ysdk.feedback.requestReview().then(({ feedbackSent }) => {
console.log('feedbackSent ', feedbackSent);
if (feedbackSent) {
myGameInstance.SendMessage('YandexGame', 'ReviewSent', 'true');
console.log('Review left')
}
else {
myGameInstance.SendMessage('YandexGame', 'ReviewSent', 'false');
console.log('Review not left', reason)
}
window.focus();
})
}
else {
console.log('Review can show = false', reason);
window.focus();
}
})
} catch (e) {
console.error('CRASH Review: ', e.message);
window.focus();
}
}
function PromptShow() {
try {
ysdk.shortcut.showPrompt()
.then(result => {
console.log('Shortcut created?:', result);
if (result.outcome === 'accepted') {
console.log('Prompt Success');
myGameInstance.SendMessage('YandexGame', 'OnPromptSuccess');
}
else {
myGameInstance.SendMessage('YandexGame', 'OnPromptFail');
}
window.focus();
});
} catch (e) {
console.error('CRASH Prompt Show: ', e.message);
window.focus();
}
}
function PaintRBT(rbt) {
try {
document.getElementById(rbt).style.background = '#ff0000';
} catch (e) {
console.error('CRASH Paint RBT: ', e.message);
}
}
function StaticRBTDeactivate() {
}
// Additional script modules:
document.body.appendChild(script);
</script>
</body>
</html>