Skip to content

Commit d732ffa

Browse files
committed
Update compiled library file
Update compiled library file
1 parent 8106851 commit d732ffa

File tree

1 file changed

+75
-18
lines changed

1 file changed

+75
-18
lines changed

bin/lcdgame.js

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ LCDGame.Menu = function (lcdgame, name) {
237237

238238
var SCORE_HTML =
239239
'<div class="infobox" id="scorebox">' +
240+
' <div id="scoreheader">' +
241+
' </div>' +
240242
' <div id="scorecontent">' +
241243
' One moment...' +
242244
' </div>' +
@@ -269,6 +271,7 @@ LCDGame.HighScores = function (lcdgame, gametitle, gametypes) {
269271
// display variables
270272
this.gametitle = gametitle;
271273
this.gametypes = gametypes;
274+
this.gametype = 1;
272275

273276
// highscore variables
274277
this._scorecache = [];
@@ -281,8 +284,7 @@ LCDGame.HighScores.prototype = {
281284
getGametype: function () {
282285
var res = "";
283286
if (this.gametypes) {
284-
this.lcdgame.gametype-1
285-
res = this.gametypes[this.lcdgame.gametype-1];
287+
res = this.gametypes[this.gametype-1];
286288
};
287289
return res;
288290
},
@@ -366,6 +368,9 @@ LCDGame.HighScores.prototype = {
366368
};
367369
var language = navigator.language;
368370
var clientguid = this.getClientGUID();
371+
372+
// set gametype for higscores
373+
this.gametype = typ;
369374

370375
// reserved characters in url
371376
//var gametitle = gametitle.replace(/\&/g, "%26"); // & -> %26
@@ -450,7 +455,7 @@ LCDGame.HighScores.prototype = {
450455
refreshGlobalHS: function () {
451456
var url = HS_URL + "geths.php" +
452457
"?gamename=" + this.gametitle + // highscore data
453-
"&gametype=" + this.lcdgame.gametype;
458+
"&gametype=" + this.gametype;
454459

455460
var xmlHttp = new XMLHttpRequest();
456461
xmlHttp.open("GET", url, true); // true for asynchronous
@@ -477,6 +482,38 @@ LCDGame.HighScores.prototype = {
477482
this.refreshHTML();
478483
},
479484

485+
onFilterButton: function (dv) {
486+
var label = dv.currentTarget.innerHTML;
487+
488+
if (dv.currentTarget.dataset) {
489+
var typ = parseInt(dv.currentTarget.dataset.gametype);
490+
491+
if (this.gametype != typ) {
492+
this.gametype = typ;
493+
this.refreshGlobalHS();
494+
};
495+
};
496+
},
497+
498+
buildHeaderHTML: function () {
499+
500+
// game name and column headers
501+
var str = '<h1 id="scoretitle">' + this.gametitle + '</h1>';
502+
503+
for (var i = this.gametypes.length-1; i >= 0; i--) {
504+
str = str + '<a class="filter" data-gametype="' + (i + 1) + '" id="filtertype' + i + '">' + this.gametypes[i] + '</a>';
505+
};
506+
507+
// refresh score filter buttons
508+
document.getElementById("scoreheader").innerHTML = str;
509+
510+
// attach click events to all buttons
511+
for (var i = 0; i < this.gametypes.length; i++) {
512+
var btn = document.getElementById("filtertype"+i);
513+
btn.addEventListener("click", this.onFilterButton.bind(this));
514+
};
515+
},
516+
480517
refreshHTML: function () {
481518
// build highscore rows
482519
var rows = "";
@@ -491,17 +528,18 @@ LCDGame.HighScores.prototype = {
491528
};
492529

493530
// game name and column headers
494-
var mod = this.getGametype();
495-
mod = (mod == "" ? mod : " (" + mod + ")");
496531
var str =
497-
"<h1>" + this.gametitle + mod + "</h1>" +
498532
"<table>" +
499533
" <tr><td>Rk.</td><td>Name</td><td>Score</td></tr>" +
500534
rows +
501535
" </table>";
502536

503537
// refresh html content
504538
this.lcdgame.scorecontent.innerHTML = str;
539+
540+
// refresh header html
541+
str = this.gametitle + ' (' + this.getGametype() + ')';
542+
document.getElementById("scoretitle").innerHTML = str;
505543
},
506544

507545
//uuidv4: function () {
@@ -1031,6 +1069,7 @@ LCDGame.Game.prototype = {
10311069

10321070
// highscores
10331071
this.highscores = new LCDGame.HighScores(this, title, gametypes);
1072+
this.highscores.buildHeaderHTML();
10341073
this.highscores.loadHighscores(this.gametype);
10351074
this.highscores.refreshGlobalHS();
10361075
},
@@ -1177,8 +1216,7 @@ LCDGame.Game.prototype = {
11771216
// center position
11781217
this.resizeCanvas();
11791218

1180-
hideInfobox();
1181-
hideScorebox();
1219+
displayInfobox();
11821220

11831221
this.raf.start();
11841222

@@ -1269,14 +1307,26 @@ LCDGame.Game.prototype = {
12691307
// if sound is playing then stop it now
12701308
if (this.gamedata.sounds[idx].audio.paused == false) {
12711309
this.gamedata.sounds[idx].audio.pause();
1272-
this.gamedata.sounds[idx].audio.currentTime = 0;
1310+
// fix for IE11
1311+
if (!isNaN(this.gamedata.sounds[idx].audio.duration)) {
1312+
this.gamedata.sounds[idx].audio.currentTime = 0;
1313+
};
12731314
};
12741315
// start playing sound
12751316
this.gamedata.sounds[idx].audio.play();
12761317
};
12771318
};
12781319
},
12791320

1321+
// -------------------------------------
1322+
// random integer
1323+
// -------------------------------------
1324+
randomInteger: function(min, max) {
1325+
max = max - min + 1;
1326+
var r = Math.floor(Math.random() * max) + min;
1327+
return r;
1328+
},
1329+
12801330
// -------------------------------------
12811331
// function for shapes and sequences
12821332
// -------------------------------------
@@ -1707,21 +1757,21 @@ LCDGame.Game.prototype = {
17071757

17081758
evt.preventDefault();
17091759

1710-
// evt.changedTouches is changed touches in this event, not all touches at this moment
1711-
for (var i = 0; i < event.changedTouches.length; i++)
1712-
{
1760+
// evt.changedTouches is changed touches in this event, not all touches at this moment
1761+
for (var i = 0; i < event.changedTouches.length; i++)
1762+
{
17131763
this.onmousedown(event.changedTouches[i]);
1714-
}
1764+
}
17151765
},
17161766

17171767
ontouchend: function(evt) {
17181768
evt.preventDefault();
17191769

1720-
// evt.changedTouches is changed touches in this event, not all touches at this moment
1721-
for (var i = 0; i < evt.changedTouches.length; i++)
1722-
{
1770+
// evt.changedTouches is changed touches in this event, not all touches at this moment
1771+
for (var i = 0; i < evt.changedTouches.length; i++)
1772+
{
17231773
this.onmouseup(evt.changedTouches[i]);
1724-
}
1774+
}
17251775
},
17261776

17271777
onmousedown: function(evt) {
@@ -2016,7 +2066,7 @@ LCDGame.Timer.prototype = {
20162066

20172067
// timer tick
20182068
if (delta >= this.interval) {
2019-
console.log("LCDGame.Timer<"+varname+">.update() -> delta="+delta+" this.interval="+this.interval+" this.lasttime="+this.lasttime+" this.waitfirst="+this.waitfirst);
2069+
//console.log("LCDGame.Timer<"+varname+">.update() -> delta="+delta+" this.interval="+this.interval+" this.lasttime="+this.lasttime+" this.waitfirst="+this.waitfirst);
20202070
//this.lasttime = timestamp;
20212071
this.lasttime = this.lasttime + this.interval;
20222072
// game callbacks
@@ -2055,5 +2105,12 @@ LCDGame.Timer.prototype = {
20552105
pause: function() {
20562106
// initialise variables
20572107
this.enabled = false;
2108+
},
2109+
2110+
// unpause the timer; continue but do not reset the counter
2111+
unpause: function() {
2112+
this.lasttime = (this.context.lcdgame.raf.raftime || 0);
2113+
if (this.waitfirst == false) this.lasttime -= this.interval;
2114+
this.enabled = true;
20582115
}
20592116
};

0 commit comments

Comments
 (0)