From 2d290b23c402561ef30c1de665895c120dd79483 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 31 Jul 2012 22:34:08 -0700 Subject: Everything related to the scoreboard. New feedback page. Changed the speed of the pauses on checkpoints during a path animation. Changed how notifications are recieved. --- js/scores.js | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 js/scores.js (limited to 'js/scores.js') diff --git a/js/scores.js b/js/scores.js new file mode 100644 index 0000000..9985da1 --- /dev/null +++ b/js/scores.js @@ -0,0 +1,221 @@ +var scorePages = new Object; +var currentPage = new Object; + +function scoresRequestPage(mapid, page) { + // console.log('scoresRequestPage', mapid, page); + if (typeof(ajax) != 'object') { + setTimeout(function() {scoresRequestPage(mapid, page)},200); + return false; + } + // Ask again if it's busy. + switch (ajax.xmlhttp.readyState) { + case 4: + case 0: + break; + default: + setTimeout(function() {scoresRequestPage(mapid, page)},300); + return false; + } + + //console.log("Requesting Page", mapid, page, ajax.inUse); + + // == Additionally, check for achievements. + ajax.requestFile = "do.php?checkachieve=true&r=reqScorePage&mapid="+mapid+"&reqPage="+page; + ajax.onCompletion = scoresRequestPageDone; // Specify function to be executed on response. + //ajax.onLoading = ''; + //ajax.onLoaded = ''; + //ajax.onFail = ''; + ajax.runAJAX();// Do it! + return true; +} +function scoresRequestLoading() { + //Signify that it's working in some manner? + //console.log("I'm loading teh page..."); +} +function scoresRequestPageDone() { + //console.log("Request Page Done", ajax.response); + var JO = decryptJSON(ajax.response); + if (JO == undefined) + return; + scoresUpdatePage(JO.mapid, JO.page, scoresFormatPage(JO)); + if (JO.notificationtext != undefined) { + showNotification(JO.notificationtext); + if (checkSound(JO.mapid)) { + soundManager.setVolume('achieve', 50); + setTimeout("soundManager.play('achieve');", 350); + } + } +} +function scoresUpdatePage(mapid, page, html) { + // console.log("Updating Page", mapid, page); + scoresPreparePage(mapid, page); + scorePages[mapid][page].html = html; + //if (scorePages[mapid][page] == currentPage[mapid]) { + if (page == currentPage[mapid]) { + scoresShowPage(mapid, page); + } +} +function scoresShowMyPage(mapid) { + //Future use +} + +function scoresShowPage(mapid, page) { + mapid = mapid - 0; + page = page - 0; + // console.log('scoresShowPage', mapid, page); + if (scoresPreparePage(mapid, page) == false) { + currentPage[mapid] = page; + // currentPage[mapid] = scorePages[mapid][page]; + //Signify some sort of loadingness? + //Request Page + scoresRequestPage(mapid, page); + } + + if (typeof(scorePages[mapid][page].html) === 'undefined') { + scoresRequestPage(mapid, page); + currentPage[mapid] = page; + return; + } + // console.log('scorpages', scorePages[mapid][page].html); + updateDsp(mapid, 'dspScore', scorePages[mapid][page].html); + //Also; update the page + // console.log('here', scorePages[mapid][page], currentPage[mapid], scorePages[mapid][page] != currentPage[mapid]); + + if (page != currentPage[mapid]) { + scoresRequestPage(mapid, page); + } + currentPage[mapid] = page; + //currentPage[mapid] = scorePages[mapid][page]; +} + +function scoresPreparePage (mapid, page) { + if (typeof(scorePages[mapid]) != 'object') { + scorePages[mapid] = new Object; + scorePages[mapid][page] = new Object; + return false; + } + if (typeof(scorePages[mapid][page]) != 'object') { + scorePages[mapid][page] = new Object; + return false; + } + return true; +} +function scoresFormatPage(JO) { + // console.log("Formating page"); + + var p = ""; + if (JO.pageCount > 1) { + var navi = scoresFormatPageNavi(JO); + p = p+""; + } + p = p+""; + p = p+""; + p = p+""; + p = p+""; + p = p+""; + + var showedLastUser = true; + var x = 0; + + var previousI = 0; + + for (var i in JO.users) { + var u = JO.users[i]; + var scoredLocalTime = new Date(); + scoredLocalTime.setTime(scoredLocalTime.getTime() - u.secondsSinceScored * 1000); + + var styleClass = ''; + + if (previousI != i + 1) + if (previousI < i - 1 && previousI != 0) + styleClass = 'border-top: 6px solid #777799;'; + + p = p+ ""; + p = p+ ""; + p = p+ ""; + + //Medals commented out 'till able to use them in a more friendly way. + // !! Don't forget to make sure these images are cached; + // if (u.medal == 'gold') { + // p = p+ ""; + // } else if (u.medal == 'silver') { + // p = p+ ""; + // } else { + // p = p+ ""; + // } + p = p+ ""; + p = p+ ""; + + previousI = i; + } + + //p = p+""; + p = p+"
"+navi+"
RankNameMoves
"; + + // !! Don't forget to make sure these images are cached; + if (u.medal == 'gold') { + p = p+ ""; + } else if (u.medal == 'silver') { + p = p+ ""; + } + //p = p+ ""; + + p = p+ i+ ""; + p = p+ "
"; + p = p+ "
"; + p = p+ "
"; + p = p+ "
"; + p = p+ ""; + p = p+ ""+u.display+""; + p = p+ "
"+u.moves+""+u.moves+""+u.moves+""+u.moves+"
"+navi+"
"; + + var nextPage = JO.page - 0 + 1; + var prevPage = JO.page - 1; + + if (JO.pageCount > 1) { + if (JO.page < JO.pageCount) { + p = p+">"; + } else + p = "
>
"+p; + if (JO.page > 1) { + p = "<"+p; + } else + p = "
<
"+p; + } + p = "
"+p+"
"; + + //console.log(p); + //console.log('jo page', JO.page); + //console.log('jo pagecount', JO.pageCount); + //javascript:scoresShowPage($mapid, $x) + //p = JO.navi+p; + return p; +} +function scoresFormatPageNavi(JO) { + var r = ''; + var showedPrevPage = true; + for (var i = 1; i <= JO.pageCount; i++) { + if ( + (JO.page > i - 3 && JO.page < i + 3) + || (i == 1) + || (i == JO.pageCount) + || (i == JO.userPage) + ) { + + if (!showedPrevPage) + r = r + ' ... '; + if (JO.page == i) { + r = r + " " + i + ""; + } else if (i == JO.userPage) { + r = r + " " + i + ''; + } else { + r = r + " " + i + ''; + } + showedPrevPage = true; + } else { + showedPrevPage = false; + } + } + + return r; +} \ No newline at end of file -- cgit v1.2.3