Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
94 lines (77 loc) · 3.17 KB
/
Copy pathscript.js
File metadata and controls
94 lines (77 loc) · 3.17 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
const canvas = document.querySelector("#unity-canvas");
const gameVersionSelector = document.querySelector("#game-version-selector");
const loadingIndictor = document.querySelector("#unity-loading-indicator");
const playBtn = document.querySelector("#play-button");
const fullscreenBtn = document.querySelector("#fullscreen-button");
const earlyAccessText = document.querySelector("#ea-warning");
const baseUrl = "Builds";
let currentVersion = "";
function loadGameVersion(version) {
currentVersion = version;
playBtn.classList.remove("highlight");
playBtn.classList.add("disabled");
earlyAccessText.classList.toggle("hidden", version == "Latest");
const buildUrl = `${baseUrl}/${version}/${version}`;
const loaderUrl = buildUrl + ".loader.js";
const config = {
arguments: [],
dataUrl: buildUrl + ".data.unityweb",
frameworkUrl: buildUrl + ".framework.js.unityweb",
codeUrl: buildUrl + ".wasm.unityweb",
streamingAssetsUrl: "StreamingAssets",
companyName: "Team 2",
productName: "Tag-Team Takedown",
productVersion: version,
};
let oldScript = document.querySelector("#unity-loader-script");
if (oldScript) oldScript.remove();
const unityLoaderScript = document.createElement("script");
unityLoaderScript.id = "unity-loader-script";
unityLoaderScript.onload = () => {
loadingIndictor.classList.remove("hidden");
createUnityInstance(canvas, config, (progress) => {
loadingIndictor.textContent = `Loading... (${Math.floor(progress * 100)}%)`;
})
.then((unityInstance) => {
loadingIndictor.classList.add("hidden");
fullscreenBtn.onclick = () => {
unityInstance.SetFullscreen(1);
};
playBtn.onclick = () => {
unityInstance.Quit();
loadSelectedGameVersion();
};
})
.catch((message) => {
alert(message);
});
};
unityLoaderScript.src = loaderUrl;
document.body.appendChild(unityLoaderScript);
}
function selectGameVersion(version) {
playBtn.classList.toggle("disabled", version === currentVersion);
}
function loadSelectedGameVersion() {
const selectedVersion = gameVersionSelector.value;
if (selectedVersion !== currentVersion) {
loadGameVersion(selectedVersion);
}
}
function turnImageCarousel(id, direction) {
const carousel = document.querySelector(`#${id}`);
const image = carousel.querySelector("img");
const pageIndicator = carousel.querySelector(".carousel-controls p");
let imagePath = carousel.getAttribute("data-path");
let currentIndex = parseInt(carousel.getAttribute("data-current")) || 1;
const totalImages = parseInt(carousel.getAttribute("data-last")) || 1;
currentIndex += direction;
if (currentIndex < 1) {
currentIndex = totalImages;
} else if (currentIndex > totalImages) {
currentIndex = 1;
}
image.src = `${imagePath}/${currentIndex}.png`;
carousel.setAttribute("data-current", currentIndex);
pageIndicator.textContent = `${currentIndex}/${totalImages}`;
}