From 7b88927f53998da4544b481849bd72728688e282 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 23 Apr 2013 02:22:00 -0700 Subject: Map thumbnail, partial animation of blocked path. --- includes/maps.php | 1 + js/mapspecs.js | 26 +++++++++++++++++--------- pages/scores.php | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/includes/maps.php b/includes/maps.php index 6b8ba07..1dfb3a6 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -1072,6 +1072,7 @@ function routePath($mygrid, $validate = false, $traverseBackwards = false) { if ($blocked) { $r['blocked'] = true; $r['lastTarget'] = $t; + $r['path'] = $tpath; return $r; } diff --git a/js/mapspecs.js b/js/mapspecs.js index 31370e3..446bc53 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -294,7 +294,7 @@ function request_path_done() { if (lastTarget == 'f') lastTarget = 'finish'; alert("The path is blocked, can't reach "+lastTarget); - return; + //return; } @@ -962,16 +962,24 @@ function mapAsHTML(map, targetWidth, mapEditor) { return r; } -function mapThumbnailHTML(map, targetWidth, isActive) { +function mapThumbnailHTML(map, targetWidth, targetHeight) { if (!targetWidth) targetWidth = 120; - var scale = map.width / targetWidth; + if (!targetHeight) targetHeight = 320; + + var heightScale = map.height / targetHeight; + var widthScale = map.width / targetWidth; - var width = parseInt(map.width / scale); - var height = parseInt(map.height / scale); - var tileWidth = parseInt(width / map.width); + //Size based on target width + var tileSize = Math.floor(map.width / widthScale / map.width); + //Too tall using width? + if (tileSize * map.height > targetHeight) { + //Use target height + tileSize = Math.floor(map.height / heightScale / map.height); + } + //console.log('tw', tileSize * map.height, targetHeight); - width = tileWidth * map.width; - height = tileWidth * map.height; + var width = tileSize * map.width; + var height = tileSize * map.height; var mapgrid = ''; var r = ''; @@ -984,7 +992,7 @@ function mapThumbnailHTML(map, targetWidth, isActive) { var value = map.tiles[y][x][1]; if (!value) value = ''; - mapgrid += "
"; + mapgrid += "
"; mapgrid += "
"; } } diff --git a/pages/scores.php b/pages/scores.php index fc86b4f..54ac027 100644 --- a/pages/scores.php +++ b/pages/scores.php @@ -275,7 +275,7 @@ function formatMapThumbForNav(json) { var r = ''; r += "
"; - r += mapThumbnailHTML(map, 120, isActive); + r += mapThumbnailHTML(map, 120); r += '
'; return r; } -- cgit v1.2.3