From df11c5da2c6e91a2c079308d62110995352d76f5 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 9 Apr 2013 01:08:02 -0700 Subject: MapEditor improvements --- includes/mapclass.php | 3 +++ includes/maps.php | 1 + pages/mapeditor.php | 64 +++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/includes/mapclass.php b/includes/mapclass.php index 24b9108..c4d95e9 100644 --- a/includes/mapclass.php +++ b/includes/mapclass.php @@ -295,6 +295,9 @@ class map { $oldNames['r'] = 'r'; $oldNames['r2'] = 'R'; + + $oldNames['q'] = 'q'; + $oldNames['p'] = 'p'; for( $i = 0; $i < $this->height; $i++) { for( $j = 0; $j < $this->width; $j++) { diff --git a/includes/maps.php b/includes/maps.php index 1af64a2..ec338d7 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -355,6 +355,7 @@ function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = if ($tp == -1) $tp = rand(0, 2); $tp = $tp * 2; //Requires an out-teleport. + if ($rockchance < 2) $rockchance = 2; //== Possibility of inf loop here, if the map is too small. do { diff --git a/pages/mapeditor.php b/pages/mapeditor.php index 0d6cf94..3134d51 100644 --- a/pages/mapeditor.php +++ b/pages/mapeditor.php @@ -23,6 +23,17 @@ if ($_REQUEST['mapByMap']) { exit; } +if ($_REQUEST['genMap']) { +//function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1, $mapName = '') { + $map = GenerateMap($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['rockChance'], $_REQUEST['wallCount'], $_REQUEST['checkpoints'] % 6, $_REQUEST['teleports'] % 6); + //$map = GenerateMap($_REQUEST['height'], $_REQUEST['width'], $_REQUEST['rockChance'], 0, 0, 0); + //$map = insertPoint($map, $_REQUEST['points'], 'o'); + $code = GenerateMapCode($map); + $map = new map($code); + echo json_encode($map); + exit; +} + htmlHeader(array('stats', 'mapeditor'), 'Map Editor', 'Map Editor', @@ -113,16 +124,20 @@ function minusWalls() { reloadMap(); } function plusWidth() { - changeDimensions(testMap.width - 0 + 1, testMap.height) + changeDimensions(testMap.width - 0 + 1, testMap.height); } function minusWidth() { - changeDimensions(testMap.width - 1, testMap.height) + changeDimensions(testMap.width - 1, testMap.height); } function plusHeight() { - changeDimensions(testMap.width, testMap.height - 0 + 1) + changeDimensions(testMap.width, testMap.height - 0 + 1); } function minusHeight() { - changeDimensions(testMap.width, testMap.height - 1) + changeDimensions(testMap.width, testMap.height - 1); +} +function updateName() { + testMap.name = $('#mapName').val(); + mapHasChanged = true; } function changeDimensions(width, height) { @@ -151,12 +166,13 @@ function loadPlayableMap() { if (isLoadingMap == true) return; isLoadingMap = true; - var URLString = 'mapeditor?mapByMap='+JSON.stringify(testMap); + //var URLString = 'mapeditor?mapByMap='+JSON.stringify(testMap); + var URLString = 'mapeditor'; $.ajax({ - type: "GET", + type: "POST", url: URLString, cache: true, - data: '', + data: 'mapByMap='+JSON.stringify(testMap), fail: function() { alert("error"); }, complete: function(data) { playableMap = decryptJSON(data.responseText); @@ -179,6 +195,20 @@ function loadMap(by) { } else if (by == 'code') { mapCode = $('#mapCode').val(); URLString = 'mapeditor?mapByCode='+mapCode; + } else if (by == 'gen') { + mapCode = $('#mapCode').val(); + URLString = 'mapeditor?genMap=true'+mapCode; + var height = $('#genMapHeight').val(); + var width = $('#genMapWidth').val(); + var rockChance = $('#genMapRockChance').val(); + var checkpoints = $('#genMapCheckpoints').val(); + var teleports = $('#genMapTeleports').val(); + URLString += '&height='+height; + URLString += '&width='+width; + URLString += '&wallCount='+testMap.walls; + URLString += '&rockChance='+rockChance; + URLString += '&checkpoints='+checkpoints; + URLString += '&teleports='+teleports; } $.ajax({ type: "GET", @@ -233,6 +263,17 @@ function constructTiles(width, height, baseMap) {
Load map by code: +
+ +
+ Generate a random map: +
Height: +
Width: +
Rockchance 1 in: +
Checkpoints: (Max 5) +
Teleports: (Max 5) + +
@@ -241,10 +282,15 @@ function constructTiles(width, height, baseMap) {
-
+
Settings: +
+ Map Name: +
+ +
Height: @@ -262,7 +308,7 @@ function constructTiles(width, height, baseMap) {