diff options
Diffstat (limited to 'pages/scores.php')
-rw-r--r-- | pages/scores.php | 196 |
1 files changed, 106 insertions, 90 deletions
diff --git a/pages/scores.php b/pages/scores.php index f3ce459..90c87bb 100644 --- a/pages/scores.php +++ b/pages/scores.php @@ -1,6 +1,6 @@ <?php
htmlHeader(
- array('stats', 'challenge'), 'Scores',
+ array('stats'), 'Scores',
'Score history for Pathery',
array('scores', 'dateformat')
);
@@ -15,13 +15,13 @@ if (isset($_GET['date'])) { } else $dateLookup = $dateDisplay;
-$dateNextDay = date('Y-m-d', strtotime("+1 day", $dateAgo));
-
-//!! TODO:
-$timeUntilNewDailyMap = strtotime("tomorrow") - strtotime("now");
+$jsYear = date("Y");
+//The part where you face palm...
+$jsMonth = date("n") - 1;
+$jsDay = date("j");
+$jsDate = "$jsYear,$jsMonth,$jsDay";
?>
-
<script type="text/javascript" src="js/jquery.keystrokes.min.js"></script>
<script type="text/javascript">
@@ -30,18 +30,12 @@ playerWallEmblem = '<?PHP echo isset($wallEmblem) ? $wallEmblem : ''; ?>'; </script>
<script>
+var startOfPathery = new Date(2011,2,13);
-
-var tomorrow = new Date();
-tomorrow.setTime(tomorrow.getTime() + <? echo $timeUntilNewDailyMap; ?> * 1000);
-var serverTomorrow = '<? echo $dateNextDay; ?>';
-
-var serverTime = new Date();
-serverTime.setTime(<? echo time() * 1000; ?>);
+var serverToday = new Date(<? echo $jsDate; ?>);
var pointerTime = new Date();
-pointerTime.setTime(serverTime.getTime())
-
+pointerTime.setTime(serverToday.getTime())
setTimeout("start();", 500);
@@ -55,12 +49,28 @@ function start() { if (typeof(hashParts[1]) !== 'undefined') {
pointerMapID = hashParts[1];
}
+ if (typeof(hashParts[2]) !== 'undefined' && hashParts[2]-0 > 0) {
+ pointerPage = hashParts[2];
+ } else pointerPage = 1;
+ if (typeof(hashParts[3]) !== 'undefined') {
+ pointerUserID = hashParts[3];
+ }
//+1 because i'm gonna use prev.
pointerTime = new Date(dateSplit[0],dateSplit[1]-1,dateSplit[2]-0+1);
}
getMapIDs('prev');
}
-//$(window).on('hashchange', function() {
+
+function addDay(dateObj) {
+ var d = dateObj;
+ d.setDate(d.getDate()+1);
+ return d;
+}
+function minusDay(dateObj) {
+ var d = dateObj;
+ d.setDate(d.getDate()-1);
+ return d;
+}
//Contra
$(document).bind('keystrokes', {
@@ -80,47 +90,80 @@ function displayMapScores(mapID) { $('#scoreDisplay').empty();
newDiv.prependTo('#scoreDisplay');
}
- scoresShowPage(1, mapID);
+
+ //Set the 'selectedMap' class
+ $('.selectedMap').removeClass('selectedMap');
+ var currentMapDiv = $('#thumb_'+mapID).children();
+ currentMapDiv.addClass('selectedMap');
+
+ //Hack: display the "current map" div for currently running maps
+ //Relies on the fact that the #thumb_<mapId> div has a single child with the 'current' class..
+ var showCurrentMapMessage = currentMapDiv.hasClass('currentlyRunning');
+ $('#currentlyRunningMessage').toggle(showCurrentMapMessage);
+
$("#mapDisplay").fadeOut('fast');
- displayMap(mapID, "mapDisplay", 622);
+ displayMap(mapID, "mapDisplay", 682);
+ scoresShowPage(pointerPage, mapID);
+ //console.log(pointerPage, mapID);
}
-
function updateHash() {
var tmp = document.location + '';
tmp = tmp.split("#");
var anchorTag = tmp[0]+'#'+pointerDate;
anchorTag += "_"+pointerMapID;
+ if (pointerPage) anchorTag += "_"+pointerPage;
+ else anchorTag += "_";
+ if (pointerUserID) anchorTag += "_"+pointerUserID;
+ else anchorTag += "_";
document.location=anchorTag;
}
+var pointerPage = 1, pointerUserID
+function saveScoreLocation(page, userID) {
+ pointerPage = page;
+ pointerUserID = userID;
+ updateHash();
+ console.log("SaveScoreLoc");
+}
+
var pointerDate;
function getMapIDs(request) {
switch (request) {
case "next":
- if (pointerTime.getTime() + (24*60*60*1000) < serverTime.getTime()) {
- pointerTime.setTime(pointerTime.getTime() + (24*60*60*1000));
+ if (pointerTime.getTime() < serverToday.getTime()) {
+ addDay(pointerTime);
pointerDate = pointerTime.format("yyyy-mm-dd");
} else return;
break;
case "prev":
- if (pointerTime.getTime() + (24*60*60*1000) > 1) {
- pointerTime.setTime(pointerTime.getTime() - (24*60*60*1000));
+ if (pointerTime.getTime() > startOfPathery.getTime()) {
+ minusDay(pointerTime);
pointerDate = pointerTime.format("yyyy-mm-dd");
} else return;
break;
}
- $('#displayDate').html(pointerTime.format("dddd, mmmm dS, yyyy"));
- if (pointerTime.getTime() + (1*24*60*60*1000) > serverTime.getTime()) {
+ var timeDisplayPrefix = '';
+ if (pointerTime.getTime() >= serverToday.getTime()) {
$('#mapNavRight').removeClass('mapNavActive');
$('#mapNavRight').addClass('mapNavDisabled');
+ timeDisplayPrefix = '<i title="(Server Time)">Today </i>';
} else {
$('#mapNavRight').addClass('mapNavActive');
$('#mapNavRight').removeClass('mapNavDisabled');
}
+ if (pointerTime.getTime() <= startOfPathery.getTime()) {
+ $('#mapNavLeft').removeClass('mapNavActive');
+ $('#mapNavLeft').addClass('mapNavDisabled');
+ timeDisplayPrefix = '<i title="The start!">Pathery Started </i>';
+ } else {
+ $('#mapNavLeft').addClass('mapNavActive');
+ $('#mapNavLeft').removeClass('mapNavDisabled');
+ }
+ $('#displayDate').html(timeDisplayPrefix+pointerTime.format("dddd, mmmm dS, yyyy"));
- var urlString = "ajax/scores.ajax.php?getmapidsbydate="+pointerDate;
+ var urlString = "a/mapsbydate/"+pointerDate+'.js';
updateHash();
$.ajax({
type: "GET",
@@ -152,15 +195,18 @@ function getMapIDsResponse(response) { //Add non-existing maps
//console.log("going through json", json);
+ var lastMapID = 0;
$.each(json, function(key, mapID) {
//console.log("add: compare:", mapID, mapsInNav);
if (jQuery.inArray(mapID, mapsInNav) == -1) {
addMapToNav(mapID);
- if (goToPointer == true && pointerMapID < 0) {
- pointerMapID = mapID;
- }
+ lastMapID = mapID;
}
});
+ if (goToPointer == true && pointerMapID < 0) {
+ pointerMapID = lastMapID;
+ }
+
//Don't queue animations...
if ($('#mapNavigation').is(':animated')) {
$("#mapNavigation").show(0);
@@ -176,12 +222,9 @@ function addMapToNav(mapID) { //console.log("adding map to nav:", mapID);
var $newdiv1 = $("<div style='float:left;min-width:120px;' id='thumb_"+mapID+"'/>");
- //$("#mapNavigation").append($newdiv1);
$("#mapNavigation").prepend($newdiv1);
-
- //var URLString = 'map/'+mapID+'.js';
- var URLString = 'map/'+mapID;
-
+
+ var URLString = 'a/map/'+mapID+'.js';
$.ajax({
type: "GET",
url: URLString,
@@ -189,70 +232,43 @@ function addMapToNav(mapID) { data: '',
fail: function() { alert("error"); },
complete: function(data) {
- $("#thumb_"+mapID).html(mapThumbnailHTML(decryptJSON(data.responseText), 120)).show();
+ var map = decryptJSON(data.responseText);
+ var mapDate = new Date(map.dateExpires*1000);
+ isActive = mapDate.getTime() > serverToday.getTime();
+
+
+ $("#thumb_"+mapID).html(formatMapThumbForNav(data.responseText)).show();
+ //$("#thumb_"+mapID).html(mapThumbnailHTML(map, 120, isActive)).show();
}
});
mapsInNav.unshift(mapID);
}
-function removeMapFromNav(mapID) {
- //console.log("remove map:", mapID, mapsInNav.indexOf(mapID));
- $("#thumb_"+mapID).hide('fast', function(){ $("#thumb_"+mapID).remove(); });
-}
-
-var Tile = {"Wall" : "w",
-"Empty" : "o",
-"Start" : "o",
-"Finish" : "o",
-"Checkpoint" : "o",
-"TileRock" : "o",
-"TeleportIn" : "o",
-"TeleportOut" : "o",
-"Unbuildable" : "o",
-"SinglePath" : "o"};
-
-function mapThumbnailHTML(map, targetWidth) {
- if (!targetWidth) targetWidth = 120;
- var scale = map.width / targetWidth;
-
- var width = parseInt(map.width / scale);
- var height = parseInt(map.height / scale);
- var tileWidth = parseInt(width / map.width);
-
- width = tileWidth * map.width;
- height = tileWidth * map.height;
-
- var mapgrid = '';
-
+function formatMapThumbForNav(json) {
+ var map = decryptJSON(json);
+ var mapDate = new Date(map.dateExpires*1000);
var mapClass = '';
var toolTip = 'Inactive map';
- var mapDate = new Date(map.dateExpires*1000);
- if (mapDate.getTime() > serverTime.getTime()) {
- mapClass = ' current';
+
+ var isCurrentlyRunning = mapDate.getTime() > serverToday.getTime();
+
+ if (isCurrentlyRunning) {
+ mapClass = ' currentlyRunning';
toolTip = 'This map can still be played.';
}
-
+
var r = '';
r += "<div class='mapThumbnail"+mapClass+"' title='"+toolTip+"'; onclick='displayMapScores("+map.ID+")'>";
- r += map.name;
-
- mapgrid += '<div class="map" style="width:'+width+'px; height:'+height+'px">';
- for (var y in map.tiles) {
- for (var x in map.tiles[y]) {
- var type = map.tiles[y][x][0];
- var value = map.tiles[y][x][1];
- if (!value) value = '';
-
- mapgrid += "<div style='float:left; width:"+tileWidth+"px; height:"+tileWidth+"px; ' class='mapcell "+type+value+"'>";
- mapgrid += "</div>";
- }
- }
- mapgrid += '</div>';
-
- r += mapgrid;
+ r += mapThumbnailHTML(map, 120, isActive);
r += '</div>';
return r;
+
+}
+
+function removeMapFromNav(mapID) {
+ //console.log("remove map:", mapID, mapsInNav.indexOf(mapID));
+ $("#thumb_"+mapID).hide('fast', function(){ $("#thumb_"+mapID).remove(); });
}
</script>
@@ -265,22 +281,22 @@ topbar($Links); <div class="wrapper">
- <div style='font-size: 105%;text-align:center;padding-bottom:7px;' id='displayDate'>
+ <div id='displayDate'>
Loading...
</div>
<div class='mapNavCon'>
- <div id='mapNavLeft' class='mapNavLeft mapNavActive' onclick='javascript:getMapIDs("prev");'><</div>
- <div id='mapNavRight' class='mapNavRight mapNavActive' onclick='javascript:getMapIDs("next");'>></div>
+ <a id='mapNavLeft' class='mapNavLeft mapNavActive unselectable' href='javascript:getMapIDs("prev");'><</a>
+ <a id='mapNavRight' class='mapNavRight mapNavActive unselectable' href='javascript:getMapIDs("next");'>></a>
<div class='mapNavCenter'>
<div id='mapNavigation'></div>
</div>
</div>
-
+ <div id="currentlyRunningMessage"><span>This map hasn't completed yet, so points/solutions are not available</span></div>
<div style='clear:both'></div>
<div>
- <div id='scoreDisplay' style="float:left;"></div>
- <div id='mapDisplay' style='display:none; float:left;' class="col2"></div>
+ <div class='scoreCol' id='scoreDisplay'></div>
+ <div class="mapCol" id='mapDisplay' style='display:none; float:left;'></div>
</div>
|