diff options
Diffstat (limited to 'pages/mapeditor.php')
-rw-r--r-- | pages/mapeditor.php | 283 |
1 files changed, 283 insertions, 0 deletions
diff --git a/pages/mapeditor.php b/pages/mapeditor.php new file mode 100644 index 0000000..402f2d6 --- /dev/null +++ b/pages/mapeditor.php @@ -0,0 +1,283 @@ +<?php +include_once('./includes/maps.php'); +include_once('./includes/mapclass.php'); + +//Self-ajax. +if ($_REQUEST['mapByCode']) { + $map = new map($_REQUEST['mapByCode']); + echo json_encode($map); + exit; +} + +if ($_REQUEST['mapByMap']) { + $jsonMap = json_decode($_REQUEST['mapByMap']); + + $map = new map(); + foreach ($jsonMap as $key => $value) { + $map->$key = $value; + } + //Store the code in the object + $map->getCode(); + echo json_encode($map); + exit; +} + + +htmlHeader(array('stats', 'mapeditor'), 'Map Editor', + 'Map Editor', + array('dateformat')); + + +?> + +<body> +<?php +echo soundManager2(); +topbar($Links); + +?> +<script> + + +var testMap = new Object; + +testMap.ID = 0; +testMap.editMap = true; +testMap.width = 6; +testMap.height = 5; +testMap.tiles = constructTiles(6, 5); +testMap.name = 'Testmap'; +testMap.walls = 5; + +setTimeout("reloadMap();", 500); +function start() { + $('#testMapDisplay').html(mapAsHTML(testMap)); +} + + +var grid_clickOverride = true; +function mapClick(obj) { + + console.log("Map Click"); + tmp = obj.id.split(','); + mapid = tmp[0] - 0; + //hack hacky hack. + y = tmp[1] - 1; + x = tmp[2]; + + testMap.tiles[y][x] = Array(palleteType, palleteValue); + y++; + $(obj).attr('class', 'mapcell '+palleteType+palleteValue); + loadPlayableMap(); +} + +var palleteType = 's'; +var palleteValue = ''; +function paletteSelect(type, value) { + palleteValue = value; + palleteType = type; +} + +function plusWalls() { + testMap.walls = testMap.walls - 0 + 1; + reloadMap(); +} +function minusWalls() { + testMap.walls = testMap.walls - 1; + reloadMap(); +} +function plusWidth() { + changeDimensions(testMap.width - 0 + 1, testMap.height) +} +function minusWidth() { + changeDimensions(testMap.width - 1, testMap.height) +} +function plusHeight() { + changeDimensions(testMap.width, testMap.height - 0 + 1) +} +function minusHeight() { + changeDimensions(testMap.width, testMap.height - 1) +} + +function changeDimensions(width, height) { + + testMap.tiles = constructTiles(width, height, testMap); + //testMap.tiles[0][3] = Array('s'); + //testMap.tiles[4][3] = Array('f'); + testMap.width = width; + testMap.height = height; + console.log('rl'); + reloadMap(); +} + +var playableMap; +function reloadMap() { + $('#testMapDisplay').html(mapAsHTML(testMap, 590, true)); + //Duplicate object + var returnedMap = jQuery.extend(true, {}, testMap); + + loadPlayableMap(); +} + +function loadPlayableMap() { + + var URLString = 'mapeditor?mapByMap='+JSON.stringify(testMap); + $.ajax({ + type: "GET", + url: URLString, + cache: true, + data: '', + fail: function() { alert("error"); }, + complete: function(data) { + playableMap = decryptJSON(data.responseText); + playableMap.editMap = false; + playableMap.ID = -1; + $('#playableMapDisplay').html(mapAsHTML(playableMap, 960)); + $('#playableMapCodeDisplay').val(playableMap.code); + } + }); +} + +function loadMap(by) { + + var URLString = ''; + var mapID = 0; + if (by == 'ID') { + mapID = $('#mapID').val(); + URLString = 'a/map/'+mapID+'.js'; + } else if (by == 'code') { + mapCode = $('#mapCode').val(); + URLString = 'mapeditor?mapByCode='+mapCode; + } + $.ajax({ + type: "GET", + url: URLString, + cache: true, + data: '', + fail: function() { alert("error"); }, + complete: function(data) { + var map = decryptJSON(data.responseText); + testMap = map; + testMap.ID = 0; + testMap.editMap = true; + reloadMap(); + } + }); +} + +function constructTiles(width, height, baseMap) { + console.log('construct start'); + var tiles = new Array; + for (var y = 0; y < height; y++) { + tiles[y] = new Array; + for (var x = 0; x < width; x++) { + tiles[y][x] = new Array; + if (typeof(baseMap) !== 'undefined' && + typeof(baseMap.tiles[y]) !== 'undefined' && + typeof(baseMap.tiles[y][x]) !== 'undefined' + ) tiles[y][x] = baseMap.tiles[y][x]; + else tiles[y][x][0] = 'o'; + } + } + console.log('construct done'); + return tiles; +} + +</script> + +<div class='wrapper'> + +<h3>Map Editor Beta</h3> + + + <div class='wrapper'> + <form> + <fieldset> + <legend>Load Map:</legend> + <div class='plusMinus'> + Load map by ID:<input id='mapID' size="5" type="text" value="" class="forminput"/> + <input type="button" value="Load" class="forminput" onclick='loadMap("ID")'/> + </div> + + <div class='plusMinus' style='width:300px;'> + Load map by code:<input id='mapCode' size="30" type="text" value="" class="forminput"/> + <input type="button" value="Load" class="forminput" onclick='loadMap("code")'/> + </div> + + </fieldset> + + </form> + </div> + + <form><div> + <div class='' id='' style='float:left; width:340px;height:350px;'> + + <fieldset style='width:300px'> + <legend>Settings:</legend> + <div class='plusMinus'> + Height:<input type="button" value="+" class="forminput" onclick='plusHeight()'/> + <input type="button" value="-" class="forminput" onclick='minusHeight()'/> + </div> + <div class='plusMinus'> + <span style='width:70px;'>Width:</span><input type="button" value="+" class="forminput" onclick='plusWidth()'/> + <input type="button" value="-" class="forminput" onclick='minusWidth()'/> + </div> + <div class='plusMinus'> + <span style='width:70px;'>Walls:</span><input type="button" value="+" class="forminput" onclick='plusWalls()'/> + <input type="button" value="-" class="forminput" onclick='minusWalls()'/> + </div> + + <div style='clear:both'></div> + + <?PHP + $tilesArray = array( + 's', 's2', 'f', 'w', + 'space', + 'r', 'r2', 'o', 'q', 'x', 'x2', + 'space', + 'c', 'c2', 'c3', 'c4', 'c5', + 'space', + 't', 't2', 't3', 't4', 't5', + 'space', + 'u', 'u2', 'u3', 'u4', 'u5' + ); + + foreach($tilesArray as $key) { + if ($key == 'space') { + echo '<div style="clear:both"></div>'; + continue; + } + + echo " + <div class='tileDisplay map'> + <div class='$key' onclick=\"paletteSelect('$key[0]', '$key[1]')\"></div> + </div>"; + } + + ?> + + </fieldset> + </div> + <fieldset style='width:590px'> + <legend>Edit Map:</legend> + <div id='testMapDisplay' style='float:left;'> + Loading... + </div> + </fieldset> + </div></form> + <div style='clear:both;'></div> + + <div class="divide"></div> + <div style='clear:both;'></div> + <div class='wrapper'> + <input id='playableMapCodeDisplay' size="100" type="text" value="" class="forminput"/> + </div> + <div id='playableMapDisplay' style='float:left;'> + Returned map goes here. + </div> + <div style='clear:both;'></div> +</div> + +<?php +htmlFooter(); +?>
\ No newline at end of file |