-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.js
108 lines (97 loc) · 2.48 KB
/
init.js
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
/**
* init.js
*
* functions to initialise important global variables (JSON file of the game, location of the game folder)
* and some other useful functions (test if a file exists, loading screen display)
*/
/**
* Loads the json in variable at start
*/
window.onload = initialise();
/**
* Retrieves the game JSON from session storage
*/
function initialise() {
var str = window.sessionStorage.getItem("json");
GameJson = JSON.parse(str);
}
/**
* Stores the folder "Game" URL in the cookie "game_folder"
* Note : changer pour ne pas avoir à vider les cookies si on veut changer de jeu
*/
function storeGameFolderURL(){
if(getCookieValue("game_folder") == ""){
const GameFolder = CurrentURL + "Game/";
document.cookie = "game_folder=" + GameFolder + ";";
}
}
/**
* Loads 'game.segment'
*/
function loadJson() {
return new Promise(function (resolve, reject) {
$.ajax({
type: 'GET',
url: getGameJsonURL(),
async: true,
dataType: 'json',
success: function (data) {
GameJson = data;
window.sessionStorage.setItem("json", JSON.stringify(data));
}
});
});
}
/**
* Shows the loading screen (in front of the background)
*/
function showLoading(){
let loading = document.getElementById("loading");
loading.zIndex = 16;
loading.style.display = "inline";
loading.style.position = "absolute";
loading.style.width = window.innerWidth + "px";
loading.style.height = window.innerHeight + "px";
loading.style.borderStyle = "solid";
loading.style.borderColor = "black";
loading.style.backgroundColor = "black";
loading.style.color = "white";
loading.style.fontSize = "xx-large"; // extra extra large
loading.style.textAlign = "center";
loading.style.padding = "auto";
loading.innerHTML = "Loading ...";
}
/**
* Hides the loading screen
*/
function hideLoading(){
let loading = document.getElementById("loading");
loading.innerHTML = "";
loading.style.display = "none";
}
/**
* Checks if a file located at url exists
* @param {String} url
* @returns true if the file exists, false otherwise
*/
function fileExists(url)
{
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status!=404;
}
/**
* Returns the URL of the Game folder
* @returns URL as a string
*/
function getGameFolderURL(){
return getCookieValue("game_folder");
}
/**
* Returns the URL of the Game JSON file
* @returns URL as a string
*/
function getGameJsonURL(){
return (getCookieValue("game_folder") + "Game.segment");
}