From 303a0b1bcda0550c74dce2cc0f4ba58aa88673fb Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 28 Feb 2013 16:27:08 -0800 Subject: Fixed Challenges --- js/mapspecs.js | 55 ++++++++++++++++++++++++++++++----- pages/challengelist.php | 16 +++++++---- pages/scores.php | 76 +++++++++++++++++++------------------------------ 3 files changed, 89 insertions(+), 58 deletions(-) diff --git a/js/mapspecs.js b/js/mapspecs.js index 3f2d3f6..0ea99db 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -801,7 +801,7 @@ function restoreSolution(mapid) { showTempSolution(mapid, mapdata[mapid].savedSolution, 0, false, false); } -function displayMap(mapid, divID, goalSize, solution, moves, challengeMap) { +function displayMap(mapid, divID, goalSize, solution, moves, challengeMap, isThumb) { var stringURL = 'a/map/'+mapid+".js"; if (challengeMap == true) stringURL = 'a/challenge/'+mapid+".js"; @@ -814,18 +814,21 @@ function displayMap(mapid, divID, goalSize, solution, moves, challengeMap) { //TODO: Better fail option? fail: (function() { console.log("FAIL Map Download"); }), complete: function(data) { - $("#"+divID).html(mapAsHTML(decryptJSON(data.responseText), goalSize)).fadeIn('fast'); - //$("#"+divID).html(mapAsHTML(decryptJSON(data.responseText), goalSize)).show(); - mapdata[mapid].savedSolution = solution; - restoreSolution(mapid); + if (isThumb) { + $("#"+divID).html(mapThumbnailHTML(decryptJSON(data.responseText), goalSize)).fadeIn('fast'); + } else { + $("#"+divID).html(mapAsHTML(decryptJSON(data.responseText), goalSize)).fadeIn('fast'); + //$("#"+divID).html(mapAsHTML(decryptJSON(data.responseText), goalSize)).show(); + mapdata[mapid].savedSolution = solution; + restoreSolution(mapid); + } } }); } //Map as object. If target width is NULL or False, default width is used. function mapAsHTML(map, targetWidth, demo) { - - //console.log("loading MapHTML for ", map); + map.mapid = map.ID; //console.log("MapID:", map.mapid); //console.log("MapObj", map); @@ -916,6 +919,44 @@ function mapAsHTML(map, targetWidth, demo) { return r; } +function mapThumbnailHTML(map, targetWidth, isActive) { + 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 = ''; + + + var r = ''; + //r += "
"; + r += map.name; + + mapgrid += '
'; + 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 += "
"; + mapgrid += "
"; + } + } + mapgrid += '
'; + + r += mapgrid; + //r += '
'; + return r; +} + + + var ignoreMuteChecks = false; function setMute(value) { diff --git a/pages/challengelist.php b/pages/challengelist.php index ade47b6..51c8f69 100644 --- a/pages/challengelist.php +++ b/pages/challengelist.php @@ -82,14 +82,20 @@ function getChallengeListHtml($challengeListResultset) { $challengeMapID = $firstChallenge['challengeMapID']; //$mapCode = getMapCode($mapid); - $mapCode = $firstChallenge['mapCode']; - $map = new map($mapCode); - $thumbnail = DisplayMapThumbnail($map); + //$mapCode = $firstChallenge['mapCode']; + //$map = new map($mapCode); + //$thumbnail = DisplayMapThumbnail($map); $r .= "
"; - $r .= "$map->name"; - $r .= $thumbnail; + //$r .= "$map->name"; + //$r .= $thumbnail; + $r .= "
\n"; + $r .= "
\n"; + $r .= ""; + foreach ($challenge as $ordering => $content) { //Each challenge gets its own star if($content["dateSolved"] !== NULL) diff --git a/pages/scores.php b/pages/scores.php index 70acbaa..8797c36 100644 --- a/pages/scores.php +++ b/pages/scores.php @@ -213,7 +213,7 @@ function addMapToNav(mapID) { var $newdiv1 = $("
"); $("#mapNavigation").prepend($newdiv1); - + var URLString = 'a/map/'+mapID+'.js'; $.ajax({ type: "GET", @@ -222,12 +222,40 @@ 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 formatMapThumbForNav(json) { + var map = decryptJSON(json); + var mapDate = new Date(map.dateExpires*1000); + var mapClass = ''; + var toolTip = 'Inactive map'; + + var isActive = mapDate.getTime() > serverToday.getTime(); + + if (isActive) { + mapClass = ' current'; + toolTip = 'This map can still be played.'; + } + + var r = ''; + r += "
"; + r += mapThumbnailHTML(map, 120, isActive); + r += '
'; + + return r; + +} + function removeMapFromNav(mapID) { //console.log("remove map:", mapID, mapsInNav.indexOf(mapID)); $("#thumb_"+mapID).hide('fast', function(){ $("#thumb_"+mapID).remove(); }); @@ -244,50 +272,6 @@ var Tile = {"Wall" : "w", "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 = ''; - - var mapClass = ''; - var toolTip = 'Inactive map'; - var mapDate = new Date(map.dateExpires*1000); - if (mapDate.getTime() > serverToday.getTime()) { - mapClass = ' current'; - toolTip = 'This map can still be played.'; - } - - var r = ''; - r += "
"; - r += map.name; - - mapgrid += '
'; - 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 += "
"; - mapgrid += "
"; - } - } - mapgrid += '
'; - - r += mapgrid; - r += '
'; - - return r; -} - -- cgit v1.2.3