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/dateformat.js | 125 +++++++++++++++++++++++++++++++ js/globe.js | 35 +++++++++ js/mapspecs.js | 76 +++---------------- js/scores.js | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 391 insertions(+), 66 deletions(-) create mode 100644 js/dateformat.js create mode 100644 js/globe.js create mode 100644 js/scores.js (limited to 'js') diff --git a/js/dateformat.js b/js/dateformat.js new file mode 100644 index 0000000..f8920d8 --- /dev/null +++ b/js/dateformat.js @@ -0,0 +1,125 @@ +/* + * Date Format 1.2.3 + * (c) 2007-2009 Steven Levithan + * MIT license + * + * Includes enhancements by Scott Trenda + * and Kris Kowal + * + * Accepts a date, a mask, or a date and a mask. + * Returns a formatted version of the given date. + * The date defaults to the current date/time. + * The mask defaults to dateFormat.masks.default. + */ + +var dateFormat = function () { + var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, + timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, + timezoneClip = /[^-+\dA-Z]/g, + pad = function (val, len) { + val = String(val); + len = len || 2; + while (val.length < len) val = "0" + val; + return val; + }; + + // Regexes and supporting functions are cached through closure + return function (date, mask, utc) { + var dF = dateFormat; + + // You can't provide utc if you skip other args (use the "UTC:" mask prefix) + if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { + mask = date; + date = undefined; + } + + // Passing date through Date applies Date.parse, if necessary + date = date ? new Date(date) : new Date; + if (isNaN(date)) throw SyntaxError("invalid date"); + + mask = String(dF.masks[mask] || mask || dF.masks["default"]); + + // Allow setting the utc argument via the mask + if (mask.slice(0, 4) == "UTC:") { + mask = mask.slice(4); + utc = true; + } + + var _ = utc ? "getUTC" : "get", + d = date[_ + "Date"](), + D = date[_ + "Day"](), + m = date[_ + "Month"](), + y = date[_ + "FullYear"](), + H = date[_ + "Hours"](), + M = date[_ + "Minutes"](), + s = date[_ + "Seconds"](), + L = date[_ + "Milliseconds"](), + o = utc ? 0 : date.getTimezoneOffset(), + flags = { + d: d, + dd: pad(d), + ddd: dF.i18n.dayNames[D], + dddd: dF.i18n.dayNames[D + 7], + m: m + 1, + mm: pad(m + 1), + mmm: dF.i18n.monthNames[m], + mmmm: dF.i18n.monthNames[m + 12], + yy: String(y).slice(2), + yyyy: y, + h: H % 12 || 12, + hh: pad(H % 12 || 12), + H: H, + HH: pad(H), + M: M, + MM: pad(M), + s: s, + ss: pad(s), + l: pad(L, 3), + L: pad(L > 99 ? Math.round(L / 10) : L), + t: H < 12 ? "a" : "p", + tt: H < 12 ? "am" : "pm", + T: H < 12 ? "A" : "P", + TT: H < 12 ? "AM" : "PM", + Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), + o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), + S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10] + }; + + return mask.replace(token, function ($0) { + return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); + }); + }; +}(); + +// Some common format strings +dateFormat.masks = { + "default": "ddd mmm dd yyyy HH:MM:ss", + shortDate: "m/d/yy", + mediumDate: "mmm d, yyyy", + longDate: "mmmm d, yyyy", + fullDate: "dddd, mmmm d, yyyy", + shortTime: "h:MM TT", + mediumTime: "h:MM:ss TT", + longTime: "h:MM:ss TT Z", + isoDate: "yyyy-mm-dd", + isoTime: "HH:MM:ss", + isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", + isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" +}; + +// Internationalization strings +dateFormat.i18n = { + dayNames: [ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" + ], + monthNames: [ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" + ] +}; + +// For convenience... +Date.prototype.format = function (mask, utc) { + return dateFormat(this, mask, utc); +}; \ No newline at end of file diff --git a/js/globe.js b/js/globe.js new file mode 100644 index 0000000..7fcd6a7 --- /dev/null +++ b/js/globe.js @@ -0,0 +1,35 @@ + +// !! Remember to preload images + + +function showSignin() { + var div = document.createElement('div'); + var pref = '
'; + pref += ' '; + pref += '
'; + var suff = '
'; + //var suff = ''; + div.innerHTML = pref+html+suff; + document.body.appendChild(div.firstChild); +} + + +var signinDiv = '
+

Sign in

+
+

Do you have an account here?

+ Sign in with Google + Sign in with Yahoo + Learn more about OpenID +
+
'; + + + + + + + + + diff --git a/js/mapspecs.js b/js/mapspecs.js index 6d3e4af..87bc173 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -27,7 +27,6 @@ var blocks = new Array(); var count = new Array(); var mapdata = new Array(); var mapjson = new Array(); -var htmlscores = ''; var htmlnotification = ''; var jsonmapdata = new Object; //var jsonmapdata.solutions = new Array(); @@ -256,7 +255,8 @@ function resetwalls(mapid) { function request_path_done() { var JO = decryptJSON(ajax.response); - mapjson[JO.mapid] = JO; + var mapid = JO.mapid; + mapjson[mapid] = JO; var speedbox = document.getElementById(mapid+',speed'), speed = speedbox.options[speedbox.selectedIndex].text, @@ -273,9 +273,6 @@ function request_path_done() { 'response time': responseTime }); - if (JO.scores) - updateDsp(JO.mapid, 'dspScore', JO.scores); - for(var i in JO.error) console.error('\n JO error ' + JO.error[i]); @@ -288,34 +285,7 @@ function request_path_done() { updateDsp(JO.mapid, 'dspID', disptext); animatePath(JO.path, JO.mapid, JO.start); - - //Get score update. - ajax.requestFile = "do.php?checkachieve=true&r=getscores&mapid="+JO.mapid; //prepare strdata - ajax.onCompletion = request_scores_done; // Specify function to be executed on response. - ajax.runAJAX();// Do it! -} - -// Used at the start -// Force score update. -function updateScoresReq(mapid, type) { - //Get score update. - ajax.requestFile = "do.php?r=getscores&mapid="+mapid; //prepare strdata - ajax.onCompletion = updateScoresGet; // Specify function to be executed on response. - ajax.runAJAX();// Do it! - mapType = type; } -function updateScoresGet() { - var JO = decryptJSON(ajax.response); - updateDsp(JO.mapid, 'dspScore', JO.scores); -} - -function reqScoresDone() { - - var JO = decryptJSON(ajax.response); - updateDsp(JO.mapid, 'dspScore', JO.scores); -} -//function addscorepage - function decryptJSON(text) { if (typeof(JSON) == 'undefined') { @@ -343,40 +313,14 @@ function animatePath(path, mapid, start) { } function animatePathDone(mapid) { + // console.log('Animate Path Done', mapid); + scoresRequestPage(mapid, currentPage[mapid]); document.getElementById(mapid+',btn').disabled = false; - if (htmlscores) { - updateDsp(mapid, 'dspScore', htmlscores); - htmlscores = ''; - } - if (htmlnotification) { - //setTimeout("showNotification('"+htmlnotification+"');", 300); - showNotification(htmlnotification); - if (checkSound(mapid)) { - soundManager.setVolume('achieve', 50); - setTimeout("soundManager.play('achieve');", 350); - } - htmlnotification = ''; - } if (isChallenge == true) { challengeGo(mapid); } } -function request_scores_done() { - - //Get scores. - if (typeof(JSON) == 'undefined') { - text = ajax.response; - var JO = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')'); - //mapdata[mapid] = eval(document.getElementById(mapid+',mapdata').innerHTML); - } else { - var JO = JSON.parse(ajax.response); - } - htmlscores = JO.scores; - htmlnotification = JO.notificationtext; -} - - function checkSound(mapid) { if (document.getElementById(mapid+',mute').checked) { return false; @@ -632,25 +576,25 @@ function doanimate(x, y, p, c, mapid) { snake[mapid]['color'] = '#F777FF'; break; case 'b': - rs = rs + 500; + rs = rs + 410; snake[mapid]['color'] = '#FFFF11'; //handle.style.backgroundColor = "#000000"; break; case 'c': - rs = rs + 500; + rs = rs + 410; snake[mapid]['color'] = '#FF4466'; break; case 'd': - rs = rs + 500; + rs = rs + 410; snake[mapid]['color'] = '#ff9911'; break; case 'e': - rs = rs + 500; + rs = rs + 410; snake[mapid]['color'] = '#00FFFF'; break; //Finish target case 'f': - rs = rs + 500; + rs = rs + 410; snake[mapid]['color'] = '#ccc'; break; @@ -681,7 +625,7 @@ function doanimate(x, y, p, c, mapid) { //The path once teleported - and an r to indicate to gray the teleport-out too. p = 'q'+tmp[2]; //Slow down - rs = rs + 1500; + rs = rs + 1200; setTimeout("doanimate("+x+","+y+",'"+p+"','"+t+"',"+mapid+")",rs); return; break; 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