forked from gn-math/html
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.html
More file actions
341 lines (284 loc) · 13.6 KB
/
19.html
File metadata and controls
341 lines (284 loc) · 13.6 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
<!DOCTYPE html>
<html lang="en-us">
<head>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-');
</script>
<base href="https://cdn.jsdelivr.net/gh/bubbls/youtube-playables@d81a7682885569a11f3258c4d1ca63d57328f7a4/supreme-duelist/">
<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">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>YT Game Wrapper WebGL Template</title>
<link rel="stylesheet" href="TemplateData/style.css" nonce="S-a_6RaCChDj2Rp8rU1UyQ">
<script src="https://cdn.jsdelivr.net/gh/bubbls/youtube-playables@main/ytgame.js" nonce="S-a_6RaCChDj2Rp8rU1UyQ">// Load YT Game API code</script>
</head>
<body>
<div id="unity-container" class="unity-desktop">
<canvas id="unity-canvas" width=100% height=100% tabindex="-1"></canvas>
<div id="unity-loading-bar">
<div id="unity-logo"></div>
<div id="unity-progress-bar-empty">
<div id="unity-progress-bar-full"></div>
</div>
</div>
<div id="unity-warning"> </div>
</div>
<script src="unarchiver.min.js" nonce="S-a_6RaCChDj2Rp8rU1UyQ">// used for decompression if zip files are used</script>
<script nonce="S-a_6RaCChDj2Rp8rU1UyQ"> // Logic for Unity contianer
var container = document.querySelector("#unity-container");
var canvas = document.querySelector("#unity-canvas");
var loadingBar = document.querySelector("#unity-loading-bar");
var progressBarFull = document.querySelector("#unity-progress-bar-full");
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
var fullscreenOverlayButton = document.querySelector("#unity-overlay-fullscreen-button");
var quitcanvas = document.querySelector("#quit-canvas");
var warningBanner = document.querySelector("#unity-warning");
// For YT it is strongly encouraged that all warnings / errors show in
// console and banners should be in game as needed to not confuse users.
//
// If needed please uncomment section below to show a temporary message
// banner/ribbon for a few seconds, or a permanent error message on top
// of the canvas if type=='error'.
function unityShowBanner(msg, type) {
// function updateBannerVisibility() {
// warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
// }
// var div = document.createElement('div');
// div.innerHTML = msg;
// warningBanner.appendChild(div);
// if (type == 'error') div.style = 'background: red; padding: 10px;';
// else {
// if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
// setTimeout(function() {
// warningBanner.removeChild(div);
// updateBannerVisibility();
// }, 5000);
// }
// updateBannerVisibility();
}
var buildUrl = "Build";
var loaderUrl = buildUrl + "/YTPlayables.loader.js";
var config = {
dataUrl: buildUrl + "/YTPlayables.data.gz",
frameworkUrl: buildUrl + "/YTPlayables.framework.js.gz",
codeUrl: buildUrl + "/YTPlayables.wasm.gz",
streamingAssetsUrl: "StreamingAssets",
companyName: "Neron's Brother",
productName: "Supreme Duelist",
productVersion: "1.0.14.0109",
showBanner: unityShowBanner,
};
// By default, Unity keeps WebGL canvas render target size matched with
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
// Set this to false if you want to decouple this synchronization from
// happening inside the engine, and you would instead like to size up
// the canvas DOM size and WebGL render target sizes yourself.
// config.matchWebGLToCanvasSize = false;
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
// Mobile device style: fill the whole browser client area with the game canvas:
var meta = document.createElement('meta');
meta.name = 'viewport';
meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
document.getElementsByTagName('head')[0].appendChild(meta);
container.className = "unity-mobile";
canvas.className = "unity-mobile";
// To lower canvas resolution on mobile devices to gain some
// performance, uncomment the following line:
// config.devicePixelRatio = 1;
} else {
// Desktop style: Render the game canvas in a window that can be maximized to fullscreen:
canvas.style.width = "100%";
canvas.style.height = "100%";
}
loadingBar.style.display = "block";
// loadResources is only used if you need load Zipped files for .wasm, .js, or .data and need
// them to be decompressed. If the file is not zipped we bypass decompression step automatically,
// however its best to not trigger this if you dont used compression.
// NOTE: GZip does not work ATM. If this is needed Unarchiver will need to be updated.
loadResources = (callback) => {
const subZipStr = '.zip';
const subWASMStr = '.wasm';
const subJSStr = '.js';
var codeUrl = config.codeUrl;
var shouldDecompress = true;
// check if .zip already exists in the URL, if it doesnt check if a .zip file exists
if (!codeUrl.includes(subZipStr)) {
if (UrlExists(codeUrl + subZipStr)) {
codeUrl = codeUrl + subZipStr;
} else {
shouldDecompress = false;
}
}
// decompress if using a zip file, otherwise just load regular wasm file
if (shouldDecompress) {
// Decompress the file based on the type, WASM, JS, etc.
// if you need more types please add a const above and modify the type logic below.
var blobType = 'application/octet-stream';
if (codeUrl.includes(subWASMStr)){
blobType = 'application/wasm';
} else if (codeUrl.includes(subJSStr)){
blobType = 'text/javascript';
}
DecompressFile(codeUrl, blobType, (file) => {
config.codeUrl = file;
callback();
});
} else {
callback();
}
}
// Fetch/Load a file then call our callback
loadZipData = (url, callback) => {
fetch(url)
.then(response => response.blob())
.then(blob => {
callback(blob);
});
}
// Check if URL / File exists
function UrlExists(urlToCheck)
{
var httpReq = new XMLHttpRequest();
httpReq.open('HEAD', urlToCheck, false);
httpReq.send();
return httpReq.status!=404;
}
// decompress files and call callback
// TODO: test and potentially switch to Compression Streams API
function DecompressFile(file, blobMimeType, callback) {
let decompressedFile;
loadZipData(file, (f) => {
Unarchiver.open(f).then(async function (archive) {
for (let entry of archive.entries) {
if (entry.is_file) {
let entryRead = await entry.read();
let entryData = await entryRead.arrayBuffer();
let dataBlob = new Blob([new Uint8Array(entryData)], { type: blobMimeType });
decompressedFile = window.URL.createObjectURL(dataBlob);
}
}
callback(decompressedFile);
});
});
}
var unityGameInstance = null;
// Setup the Unity section once zip file is downloaded and decompressed
function InitUnitySection() {
var script = document.createElement("script");
script.src = loaderUrl;
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {
progressBarFull.style.width = 100 * progress + "%";
}).then((unityInstance) => {
unityGameInstance = unityInstance;
loadingBar.style.display = "none";
}).catch((message) => {
console.error(message);
});
};
document.body.appendChild(script);
}
function GetGzipUrl(url)
{
return url + "ip";
}
//
// Does not load .js properly, so rename framework above WITHOUT .gz and decompress
//
function DecompressGzipFiles(callback)
{
const wasmUrl = GetGzipUrl(config.codeUrl);
fetch(wasmUrl)
.then(response => response.blob())
.then(blob => {
console.log("gzipped blob loaded!!! " + blob.type);
const ds = new DecompressionStream("gzip");
const decompressedStream = blob.stream().pipeThrough(ds);
new Response(decompressedStream).blob()
.then(async unzippedBlob =>
{
console.log("gzip should be decompressed!");
unzippedBlob.type = "application/wasm";
decompressedUrl = window.URL.createObjectURL(unzippedBlob);
console.log("decompressed gzip at: " + decompressedUrl);
// HACK
config.codeUrl = decompressedUrl;
////////////////////////////////////
const dataUrl = GetGzipUrl(config.dataUrl);
fetch(dataUrl)
.then(response => response.blob())
.then(blob => {
console.log("gzipped blob loaded!!!");
blob.type = "application/x-gzip-compressed";
const ds = new DecompressionStream("gzip");
const decompressedStream = blob.stream().pipeThrough(ds);
new Response(decompressedStream).blob()
.then(async unzippedBlob =>
{
console.log("gzip should be decompressed!");
unzippedBlob.type = "application/octet-stream";
decompressedUrl = window.URL.createObjectURL(unzippedBlob);
console.log("decompressed gzip at: " + decompressedUrl);
// HACK
config.dataUrl = decompressedUrl;
/*//------------------------------------------------------------------------------*/
const frameworkUrl = GetGzipUrl(config.frameworkUrl);
console.log("frameworkUrl" + frameworkUrl)
fetch(frameworkUrl)
.then(response => response.blob())
.then(blob => {
console.log("gzipped blob loaded!!!");
const ds = new DecompressionStream("gzip");
const decompressedStream = blob.stream().pipeThrough(ds);
console.log("starting deomcompression");
new Response(decompressedStream).blob()
.then(async unzippedBlob =>
{
console.log("gzip should be decompressed!");
unzippedBlob.type = "text/javascript";
decompressedUrl = window.URL.createObjectURL(unzippedBlob);
console.log("decompressed gzip at: " + decompressedUrl);
// HACK
config.frameworkUrl = decompressedUrl;
console.log("config.frameworkUrl at: " + config.frameworkUrl);
callback();
})
.catch(err => {
console.error("gzip decompress error: " + err);
// Deal with the fact the chain failed
});
});
//------------------------------------------------------------------------------------------------------------*/
//callback();
})
.catch(err => {
console.error("gzip decompress error: " + err);
// Deal with the fact the chain failed
});
});
////////////////////////////////////
})
.catch(err => {
console.error("gzip decompres error: " + err);
// Deal with the fact the chain failed
});
});
}
// If compressed files are found, decompress before init
if (config.dataUrl.includes(".gz")) {
// Path 1: Use this path if your .wasm and .data files are gzipped
DecompressGzipFiles(InitUnitySection); // Uncomment this line to start Unity by loading gzip compressed files
}
else {
// Path 2: Just init if no decompression of your .wasm, .data, .js files was needed
InitUnitySection();
}
</script>
</body>
</html>