Skip to content

Commit 02d0191

Browse files
committed
Added option to disable logs. Disabled by default.
1 parent b455e8e commit 02d0191

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

js/jpak.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Array.prototype.clean = function(deleteValue) {
4040
/* Start of JPAK Class Stuff */
4141
var JPAK = function() {};
4242

43+
// Enable this to show Debug Messages
44+
JPAK.ShowMessages = false;
45+
4346
// Auxiliary functions
4447
// Convert Unsigned Int 8 Array Buffer to String
4548
JPAK.Uint8ArrayToString = function(uintArray) {
@@ -105,6 +108,10 @@ JPAK.ArrayBufferToBase64 = function(arrayBuffer) {
105108
return base64
106109
};
107110

111+
JPAK.log = function(msg) {
112+
if(JPAK.ShowMessages)
113+
console.log(msg);
114+
}
108115

109116
// JPAKLoader
110117
JPAK.jpakloader = function(parameters) {
@@ -153,7 +160,7 @@ JPAK.jpakloader.prototype.Load = function() {
153160
var data = this.response;
154161
var MagicNumber = u8as(new Uint8Array(data.slice(0,5)));
155162
if(MagicNumber == "JPAK1") {
156-
console.log("JPAK::jpakloader - Loaded file "+_this.jpakfile+" successfully. JPAK1 Format");
163+
JPAK.log("JPAK::jpakloader - Loaded file "+_this.jpakfile+" successfully. JPAK1 Format");
157164
var filetableoffset = new DataView(data.slice(data.byteLength-4,data.byteLength)).getUint32(0, true);
158165
var filetable = new Uint8Array(data.slice(filetableoffset,data.byteLength-4));
159166
filetable = JSON.parse(u8as(filetable));
@@ -163,7 +170,7 @@ JPAK.jpakloader.prototype.Load = function() {
163170
if(_this.onload != undefined)
164171
_this.onload();
165172
}else{
166-
console.log("JPAK::jpakloader - Error loading file "+_this.jpakfile+" (8000): Wrong File Magic. Expected JPAK1 got "+MagicNumber);
173+
JPAK.log("JPAK::jpakloader - Error loading file "+_this.jpakfile+" (8000): Wrong File Magic. Expected JPAK1 got "+MagicNumber);
167174
if(_this.onerror != undefined)
168175
_this.onerror({"text": "Wrong File Magic. Expected JPAK1 got "+MagicNumber, "errorcode" : 8000});
169176
}
@@ -172,7 +179,7 @@ JPAK.jpakloader.prototype.Load = function() {
172179
xhr.onreadystatechange = function (aEvt) {
173180
if (this.readyState == 4) {
174181
if(this.status != 200) {
175-
console.log("JPAK::jpakloader - Error loading file "+_this.jpakfile+" ("+this.status+"): "+this.statusText);
182+
JPAK.log("JPAK::jpakloader - Error loading file "+_this.jpakfile+" ("+this.status+"): "+this.statusText);
176183
if(_this.onerror != undefined)
177184
_this.onerror({"text": this.statusText, "errorcode": this.status});
178185
}
@@ -261,8 +268,10 @@ JPAK.jpakloader.prototype.GetFileURL = function(path, type) {
261268
var blob = this.GetFile(path, type);
262269
if(blob != undefined)
263270
return URL.createObjectURL(blob);
264-
else
271+
else{
272+
JPAK.log("Error: Cannot find file \""+path+"\"");
265273
return "about:blank"; // Dunno what to return here
274+
}
266275
}else
267276
return cache.url;
268277
};
@@ -281,7 +290,8 @@ JPAK.jpakloader.prototype.GetFileArrayBuffer = function(path, type) {
281290
return arraybuffer;
282291
}else if(cache != undefined)
283292
return cache.arraybuffer;
284-
293+
294+
JPAK.log("Error: Cannot find file \""+path+"\"");
285295
return undefined;
286296
};
287297
// Returns an arraybuffer with file content. It looks in the cache for already loaded files.

0 commit comments

Comments
 (0)