From 677b7454a37a0152f50d40993460d8f5a071e181 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 5 Mar 2013 14:17:08 -0800 Subject: Map editor 0.1! --- css/mapeditor.css | 10 ++ includes/mapclass.php | 14 ++- index.php | 4 + js/mapspecs.js | 14 ++- pages/mapeditor.php | 283 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 318 insertions(+), 7 deletions(-) create mode 100644 css/mapeditor.css create mode 100644 pages/mapeditor.php 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 += "
"; mapgrid += "
"; } else { @@ -885,6 +891,8 @@ function mapAsHTML(map, targetWidth, demo) { } mapgrid += ''; + 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 @@ + $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')); + + +?> + + + + + +
+ +

Map Editor Beta

+ + +
+
+
+ Load Map: +
+ Load map by ID: + +
+ +
+ Load map by code: + +
+ +
+ +
+
+ +
+
+ +
+ Settings: +
+ Height: + +
+
+ Width: + +
+
+ Walls: + +
+ +
+ +
'; + continue; + } + + echo " +
+
+
"; + } + + ?> + + +
+
+ Edit Map: +
+ Loading... +
+
+
+
+ +
+
+
+ +
+
+ Returned map goes here. +
+
+ + + \ No newline at end of file -- cgit v1.2.3