summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2013-03-05 14:17:08 -0800
committerPatrick Davison <snapwilliam@gmail.com>2013-03-05 14:17:08 -0800
commit677b7454a37a0152f50d40993460d8f5a071e181 (patch)
treedc664e700b4aa4d0c1ab54ff7c99798dd9b623da
parentd1209f8d15c83a1d8d29beafc085d927be7d2bcd (diff)
downloadpathery-677b7454a37a0152f50d40993460d8f5a071e181.tar.xz
Map editor 0.1!
-rw-r--r--css/mapeditor.css10
-rw-r--r--includes/mapclass.php14
-rw-r--r--index.php4
-rw-r--r--js/mapspecs.js14
-rw-r--r--pages/mapeditor.php283
5 files changed, 318 insertions, 7 deletions
diff --git a/css/mapeditor.css b/css/mapeditor.css
new file mode 100644
index 0000000..60a6e78
--- /dev/null
+++ b/css/mapeditor.css
@@ -0,0 +1,10 @@
+
+
+
+.plusMinus {
+ float:left;
+ width:130px;
+ border:1px solid gray;
+ padding:2px;
+ margin:2px;
+} \ No newline at end of file
diff --git a/includes/mapclass.php b/includes/mapclass.php
index 9e91d3f..bc5a6e5 100644
--- a/includes/mapclass.php
+++ b/includes/mapclass.php
@@ -43,8 +43,15 @@ class map {
public function __construct($code = NULL, $mapID = NULL) {
//TODO: Use new code by default.
if ($mapID !== NULL) $this->ID = $mapID;
- if ($code !== NULL) $this->applyMapFromOldCode($code);
- //$this->applyMapFromCode($code);
+ if ($code !== NULL) {
+ $dimensions = explode('.', explode(':', $code)[0])[0];
+ if (strpos($dimensions, 'x') == true) {
+ $this->applyMapFromOldCode($code);
+ } else {
+ $this->applyMapFromCode($code);
+ }
+ }
+
}
public function applyMapFromOldCode($code) {
@@ -218,8 +225,7 @@ class map {
//Outputs the new code.
public function getCode() {
//If we already have the code on hand...
- if ($this->code)
- return $this->code;
+ //if ($this->code) return $this->code;
//Otherwise we need to build the code:
$headers[0] = $this->width;
$headers[1] = $this->height;
diff --git a/index.php b/index.php
index 9a5f7d7..f909306 100644
--- a/index.php
+++ b/index.php
@@ -212,6 +212,10 @@ switch ($request) {
require 'pages/chat.php';
break;
+ case "mapeditor":
+ require 'pages/mapeditor.php';
+ break;
+
case "admin":
if ($_SESSION['isAdmin'] == true) {
require 'pages/admin.php';
diff --git a/js/mapspecs.js b/js/mapspecs.js
index 2387a00..443ddfe 100644
--- a/js/mapspecs.js
+++ b/js/mapspecs.js
@@ -92,6 +92,12 @@ function grid_click(obj) {
y = tmp[1];
x = tmp[2];
+
+ if(mapdata[mapid].editMap == true) {
+ mapClick(obj);
+ return;
+ }
+
//The users solution - prepare it if it's not started
if (solution[mapid] == undefined) {
getmapdata(mapid);
@@ -838,7 +844,7 @@ var Tile = {
"x" : "Single-Path-Rock"};
//Map as object. If target width is NULL or False, default width is used.
-function mapAsHTML(map, targetWidth, demo) {
+function mapAsHTML(map, targetWidth, mapEditor) {
map.mapid = map.ID;
//console.log("MapID:", map.mapid);
@@ -872,9 +878,9 @@ function mapAsHTML(map, targetWidth, demo) {
// GOAL WOULD BE THIS LINE INSTEAD.. As it's not retarded.
//var idHandle = map.ID+','+x+','+y;
-
+
//oldy is used for Position too... for now
- if (type == 'o') {
+ if (type == 'o' || mapEditor == true) {
mapgrid += "<div style='float:left; width:"+tileWidth+"px; height:"+tileWidth+"px; ' class='mapcell "+type+value+"' title='Position: "+x+","+oldy+"' id='"+idHandle+"' onClick='grid_click(this)' >";
mapgrid += "<div id='child_"+idHandle+"' class='child'></div></div>";
} else {
@@ -885,6 +891,8 @@ function mapAsHTML(map, targetWidth, demo) {
}
mapgrid += '</div>';
+ if (mapEditor == true) return mapgrid;
+
var r = '';
//TODO: Track down where that 1 pixel is comingfrom, width-1 is a hack.
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