Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AroriaNetwork
GitHub Repository: AroriaNetwork/3kho-backup
Path: blob/main/projects/slope/TemplateData56/UnityProgress.js
1834 views
1
const rootPath = "TemplateData56";
2
function UnityProgress(gameInstance, progress) {
3
if (!gameInstance.Module) {
4
return;
5
}
6
if (!gameInstance.logo) {
7
gameInstance.logo = document.createElement("div");
8
gameInstance.logo.className = "logo " + gameInstance.Module.splashScreenStyle;
9
gameInstance.container.appendChild(gameInstance.logo);
10
}
11
if (!gameInstance.progress) {
12
gameInstance.progress = document.createElement("div");
13
gameInstance.progress.className = "progress " + gameInstance.Module.splashScreenStyle;
14
gameInstance.progress.empty = document.createElement("div");
15
gameInstance.progress.empty.className = "empty";
16
gameInstance.progress.appendChild(gameInstance.progress.empty);
17
gameInstance.progress.full = document.createElement("div");
18
gameInstance.progress.full.className = "full";
19
gameInstance.progress.appendChild(gameInstance.progress.full);
20
gameInstance.container.appendChild(gameInstance.progress);
21
gameInstance.textProgress = document.createElement("div");
22
gameInstance.textProgress.className = "text";
23
gameInstance.container.appendChild(gameInstance.textProgress);
24
}
25
gameInstance.progress.full.style.width = 100 * progress + "%";
26
gameInstance.progress.empty.style.width = 100 * (1 - progress) + "%";
27
gameInstance.textProgress.innerHTML = "Loading: " + Math.floor(progress * 100) + "%";
28
if (progress == 1) {
29
gameInstance.textProgress.innerHTML = 'Running... <img src="' + rootPath + '/gears.gif" class="spinner" />';
30
}
31
if (progress == "complete") {
32
gameInstance.logo.style.display = "none";
33
gameInstance.progress.style.display = "none";
34
gameInstance.textProgress.style.display = "none";
35
const event = new Event("removeSoundOverlay");
36
document.dispatchEvent(event);
37
}
38
}
39
window.Game = (function () {
40
var Game = function () {
41
this.registerEvents();
42
};
43
Game.prototype.registerEvents = function () {
44
var _this = this;
45
window.addEventListener(
46
"keydown",
47
function (e) {
48
if ([8, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
49
e.preventDefault();
50
}
51
},
52
false
53
);
54
document.onmousedown = function () {
55
window.focus();
56
};
57
document.addEventListener(
58
"DOMContentLoaded",
59
function () {
60
_this.resize();
61
},
62
false
63
);
64
window.addEventListener(
65
"resize",
66
function () {
67
setTimeout(function () {
68
_this.resize();
69
}, 1000);
70
},
71
false
72
);
73
};
74
Game.prototype.getQueryVariable = function (variable) {
75
var query = window.location.search.substring(1);
76
var vars = query.split("&");
77
for (var i = 0; i < vars.length; i++) {
78
var pair = vars[i].split("=");
79
if (pair[0] == variable) {
80
return pair[1];
81
}
82
}
83
return false;
84
};
85
Game.prototype.resize = function () {
86
var ratioTolerant = this.getQueryVariable("ratio_tolerant");
87
if (ratioTolerant == false || this.fullscreen()) {
88
return;
89
}
90
document.getElementsByTagName("body")[0].style.overflow = "hidden";
91
var gameContainer = document.getElementById("gameContainer") || document.getElementById("unityContainer");
92
var canvas = document.getElementById("#canvas");
93
var gameSizeRatio = gameContainer.offsetWidth / gameContainer.offsetHeight;
94
var maxHeight = this.maxHeight();
95
var maxWidth = window.innerWidth;
96
var windowSizeRatio = maxWidth / maxHeight;
97
var newStyle = { width: gameContainer.offsetWidth, height: gameContainer.offsetHeight };
98
if (ratioTolerant == "true") {
99
newStyle = { width: maxWidth, height: maxHeight };
100
} else if (ratioTolerant == "false") {
101
if (gameSizeRatio > windowSizeRatio) {
102
newStyle = { width: maxWidth, height: maxWidth / gameSizeRatio };
103
} else {
104
newStyle = { width: maxHeight * gameSizeRatio, height: maxHeight };
105
}
106
}
107
this.updateStyle(gameContainer, newStyle);
108
if (canvas) {
109
this.updateStyle(canvas, newStyle);
110
}
111
};
112
Game.prototype.maxHeight = function () {
113
return window.innerHeight - 43;
114
};
115
Game.prototype.updateStyle = function (element, size) {
116
element.setAttribute("width", size.width);
117
element.setAttribute("height", size.height);
118
element.style.width = size.width + "px";
119
element.style.height = size.height + "px";
120
};
121
Game.prototype.fullscreen = function () {
122
return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
123
};
124
return Game;
125
})();
126
new Game();
127