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