Skip to content

Commit 493ba08

Browse files
committed
feat: add new console._log function
Before, everything was logged to console. Using the new _log function should only display logs when in debug mode
1 parent 4255667 commit 493ba08

7 files changed

+41
-33
lines changed

js/src/alerter.1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function createAlert(data, settings){
3939

4040
settings = Object.assign({ newsest_on_top: true, placement: { from: "bottom", align: "left" }, delay: 10000, type: "warning" }, settings);
4141

42-
//console.log(JSON.stringify(data));
43-
//console.log(JSON.stringify(settings));
42+
//console._log(JSON.stringify(data));
43+
//console._log(JSON.stringify(settings));
4444

4545
return $.notify(data, settings);; // Incase I need this in future for shit like prgress bars or, if i need to update the alert
4646
}

js/src/controls.2.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
// ************************************************************************** //
1818

1919
function toggleBlips(){
20-
console.log("showing local blips");
20+
console._log("showing local blips");
2121
if (_showBlips){
2222

2323
for(var spriteId in _blips){
2424
var blipArray = _blips[spriteId];
25-
//console.log("Disabled (" + spriteId + ")? " + _disabledBlips.includes(spriteId));
25+
//console._log("Disabled (" + spriteId + ")? " + _disabledBlips.includes(spriteId));
2626

2727
if(_disabledBlips.indexOf(spriteId) != -1){
2828
if(_SETTINGS_debug){
29-
console.log("Blip " + spriteId + "'s are disabled..");
29+
console._log("Blip " + spriteId + "'s are disabled..");
3030
}
3131
// If disabled, don't make a marker for it
3232
continue;
@@ -67,7 +67,7 @@ $(document).ready(function(){
6767
});
6868

6969
$("#server_menu").on("click", ".serverMenuItem", function(e){
70-
console.log($(this).text());
70+
console._log($(this).text());
7171
changeServer($(this).text());
7272
});
7373

js/src/init.1.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
// along with this program in the file "LICENSE". If not, see <http://www.gnu.org/licenses/>.
1717
// ************************************************************************** //
1818

19+
// Ugly hack. Please. Avert eyes.
20+
_log = console._log = function(message, ...params){
21+
if(window.config.debug){
22+
params.unshift(message);
23+
console.log.apply(this, params);
24+
}
25+
}
26+
1927
var _invervalId;
2028
var _isLive = false;
2129
var _blips = [];
@@ -27,7 +35,7 @@ var playerCount = 0;
2735
var _overlays = [];
2836
var _disabledBlips = [];
2937
window.changeServer = function (nameOfServer) {
30-
console.log("Changing connected server to: " + nameOfServer);
38+
console._log("Changing connected server to: " + nameOfServer);
3139
if (!(nameOfServer in config.servers)) {
3240
createAlert({
3341
title: "<strong>Couldn't load server config!</strong>",
@@ -82,7 +90,7 @@ function globalInit() {
8290
for (const serverName in config.servers) {
8391
// Make sure all servers inherit defaults if they need
8492
var o = Object.assign({}, config.defaults, config.servers[serverName]);
85-
if (config.debug) console.log(o);
93+
console._log(o);
8694
config.servers[serverName] = o;
8795
}
8896

@@ -111,7 +119,7 @@ function initPage() {
111119

112120
var $myGroup = $('#control-wrapper');
113121
$myGroup.on('show.bs.collapse','.collapse', function() {
114-
console.log("hidding?");
122+
console._log("hidding?");
115123
$myGroup.find('.collapse.show').collapse('hide');
116124
});
117125

@@ -208,7 +216,7 @@ function blipSuccess(data, textStatus){
208216
}
209217
}
210218

211-
console.log(_blipCount + " blips created");
219+
console._log(_blipCount + " blips created");
212220
$("#blip_count").text(_blipCount);
213221

214222
}
@@ -227,7 +235,7 @@ function initBlips(url){
227235
_blipCount = 0;
228236
_blips = [];
229237

230-
console.log("Sending ajax request to " + url);
238+
console._log("Sending ajax request to " + url);
231239
$.ajax(url, {
232240
error: blipError,
233241
dataType: "json",

js/src/map.1.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ function mapInit(elementID) {
2929
var tileLayers = {};
3030
var maps = window.config.maps;
3131
maps.forEach(map => {
32-
console.log(map);
32+
console._log(map);
3333
tileLayers[map.name] = L.tileLayer(map.url,
3434
Object.assign(
3535
{ minZoom: -2, maxZoom: 0, maxNativeZoom: 0, minNativeZoom: 0, tileSize: 1024, tileDirectory: config.tileDirectory },
3636
map)
3737
);
38-
console.log(tileLayers[map.name]);
38+
console._log(tileLayers[map.name]);
3939
});
4040

4141
CurrentLayer = tileLayers[Object.keys(tileLayers)[0]];
@@ -73,8 +73,8 @@ function mapInit(elementID) {
7373
});
7474

7575
Map.on('preclick', function (e) {
76-
console.log("Preclick!");
77-
console.log(e);
76+
console._log("Preclick!");
77+
console._log(e);
7878
});
7979
}
8080

@@ -85,12 +85,12 @@ function createMarker(animated, draggable, objectRef, title) {
8585
name = "@Locator";
8686
}
8787
objectRef.position = stringCoordToFloat(objectRef.position);
88-
//console.log(objectRef.position);
88+
//console._log(objectRef.position);
8989
var coord = convertToMapLeaflet(objectRef.position.x, objectRef.position.y);
90-
//console.log(coord);
90+
//console._log(coord);
9191
var markerType = objectRef.type;
9292

93-
//console.log(JSON.stringify(locationType));
93+
//console._log(JSON.stringify(locationType));
9494

9595
var html = '<div class="row info-body-row"><strong>Position:</strong>&nbsp;X {' + objectRef.position.x.toFixed(2) + "} Y {" + objectRef.position.y.toFixed(2) + "} Z {" + objectRef.position.z.toFixed(2) + "}</div>";
9696

@@ -101,8 +101,8 @@ function createMarker(animated, draggable, objectRef, title) {
101101
var infoContent = '<div class="info-window"><div class="info-header-box"><div class="info-header">' + name + '</div></div><div class="clear"></div><div class=info-body>' + html + "</div></div>";
102102

103103
var image = L.icon(markerType);
104-
//console.log(image);
105-
//console.log("image: " + JSON.stringify(image));
104+
//console._log(image);
105+
//console._log("image: " + JSON.stringify(image));
106106

107107
var marker = L.marker(coord, {
108108
title: title,

js/src/markers.1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ window.MarkerTypes = {};
2424
var blipCss = "";
2525

2626
function initMarkers(){
27-
console.log("initialising markers");
27+
console._log("initialising markers");
2828
window.MarkerTypes = {
2929
0: {
3030
iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAFElEQVR4XgXAAQ0AAABAMP1L30IDCPwC/o5WcS4AAAAASUVORK5CYII=',
@@ -242,7 +242,7 @@ function generateBlipControls(){
242242
$("#blip-control-container").append(`<a data-blip-number="${nameToId[blipName]}" id="blip_${blipName}_link" class="blip-button-a list-group-item d-inline-block collapsed blip-enabled" href="#"><span class="blip blip-${blipName}"></span></a>`);
243243

244244
if(config.debug){
245-
console.log("Added ahref for " + blipName);
245+
console._log("Added ahref for " + blipName);
246246
}
247247
}
248248

js/src/socket.1.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function connect(connectionString) {
3838

3939
function onOpen(e) {
4040
if (config.debug) {
41-
console.log("_isConnected: " + webSocket.readyState == WebSocket.OPEN);
41+
console._log("_isConnected: " + webSocket.readyState == WebSocket.OPEN);
4242
}
4343

4444
$("#connection").removeClass("badge-danger")
@@ -59,8 +59,8 @@ function onMessage(e) {
5959
var byteSize = e.data.length + (m ? m.length : 0);
6060

6161
if (config.debug) {
62-
console.log("recieved message (" + byteSize / 1024 + " kB)");
63-
console.log("data: " + e.data);
62+
console._log("recieved message (" + byteSize / 1024 + " kB)");
63+
console._log("data: " + e.data);
6464
}
6565

6666
var data = JSON.parse(e.data);
@@ -86,12 +86,12 @@ function onMessage(e) {
8686
updateBlip(data.payload);
8787

8888
} else if (data.type == "playerData") {
89-
//console.log("updating players(" + typeof(data.payload) + "): " + JSON.stringify(data.payload));
89+
//console._log("updating players(" + typeof(data.payload) + "): " + JSON.stringify(data.payload));
9090
var sortedPlayers = data.payload.sort(sorter);
9191
doPlayerUpdate(sortedPlayers);
9292

9393
} else if (data.type == "playerLeft") {
94-
//console.log("player left:" + data.payload);
94+
//console._log("player left:" + data.payload);
9595
playerLeft(data.payload);
9696
}
9797

@@ -271,15 +271,15 @@ function playerLeft(playerName) {
271271

272272
playerCount = Object.keys(localCache).length;
273273
if (config.debug) {
274-
console.log("Playerleft playercount: " + playerCount);
274+
console._log("Playerleft playercount: " + playerCount);
275275
}
276276
$("#player_count").text(playerCount);
277277
}
278278

279279
function getPlayerInfoHtml(plr) {
280280
var html = '<div class="row info-body-row"><strong>Position:</strong>&nbsp;X {' + plr.pos.x.toFixed(2) + "} Y {" + plr.pos.y.toFixed(2) + "} Z {" + plr.pos.z.toFixed(2) + "}</div>";
281281
for (var key in plr) {
282-
//console.log("found key: "+ key);
282+
//console._log("found key: "+ key);
283283
if (key == "name" || key == "pos" || key == "icon") { // I should probably turn this into a array or something
284284
continue; // We're already displaying this info
285285
}
@@ -299,7 +299,7 @@ function getPlayerInfoHtml(plr) {
299299
function doPlayerUpdate(players) {
300300

301301
if (config.debug) {
302-
console.log(players);
302+
console._log(players);
303303
}
304304

305305
players.forEach(function (plr) {
@@ -329,7 +329,7 @@ function doPlayerUpdate(players) {
329329
if (plr.icon) {
330330
var t = MarkerTypes[plr.icon];
331331

332-
//console.log("Got icon of :" + plr.icon);
332+
//console._log("Got icon of :" + plr.icon);
333333

334334
MarkerStore[localCache[plr.identifer].marker].setIcon(L.icon(t));
335335
}
@@ -361,7 +361,7 @@ function doPlayerUpdate(players) {
361361

362362
playerCount = Object.keys(localCache).length;
363363
if (config.debug) {
364-
console.log("playercount: " + playerCount);
364+
console._log("playercount: " + playerCount);
365365
}
366366
$("#player_count").text(playerCount);
367367
}

js/src/version-check.2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $(document).ready(function () {
3434
message: `An update is available (${window.version} -> ${p["interface"]}). Please download it <a style='color: #000;' href='https://github.com/TGRHavoc/live_map-interface'>HERE.</a>`
3535
})
3636
}else{
37-
console.log("Up to date or, a higher version");
37+
console._log("Up to date or, a higher version");
3838
}
3939

4040
}

0 commit comments

Comments
 (0)