diff options
author | BlueRaja <BlueRaja.admin@gmail.com> | 2013-01-26 03:31:52 -0600 |
---|---|---|
committer | BlueRaja <BlueRaja.admin@gmail.com> | 2013-01-26 03:31:52 -0600 |
commit | 20e2aadc5bec3a0282183354d81bee215e647d1f (patch) | |
tree | 66fb117df1edffa748b40738fefe04d55edeeb3f /includes | |
parent | 5dfe3b8c21ca79300a1851d7658f8aa389b2733f (diff) | |
parent | 0879eecfe919597de05895087327bfb0b1a6e9bd (diff) | |
download | pathery-20e2aadc5bec3a0282183354d81bee215e647d1f.tar.xz |
Merge branch 'master' of git.raylu.net:pathery
Diffstat (limited to 'includes')
-rw-r--r-- | includes/mapclass.php | 103 |
1 files changed, 95 insertions, 8 deletions
diff --git a/includes/mapclass.php b/includes/mapclass.php index 03bbedd..fa4d865 100644 --- a/includes/mapclass.php +++ b/includes/mapclass.php @@ -20,22 +20,29 @@ define("TileUnbuildable", 'q'); define("TileSinglePath", 'x'); class map { - public $name; public $tiles; - public $teleports; public $checkpoints; - public $height; + + //These are headers actually used in the mapCode public $width; + public $height; + public $walls; + public $name; + public $flags; + public $dateCreated; + public $dateExpires; + public $isBlind; public $isMultiPath; public $code; public function __construct($code = NULL) { + //TODO: Use new code by default. if ($code !== NULL) $this->applyMapFromOldCode($code); - //echo "Construct complete"; + //$this->applyMapFromCode($code); } public function applyMapFromOldCode($code) { @@ -49,6 +56,7 @@ class map { $dimensions = explode( 'x', $headers[0]); $this->width = $dimensions[0]; $this->height = $dimensions[1]; + $this->walls = substr($headers[3], 1); $this->name = $headers[5]; //Map Name //Make assumptions: @@ -116,17 +124,96 @@ class map { } } - //Creates the map based on a new code. - public function applyMapFromNewCode($code) { - $this->code = $code; + //From the newer mapcode. + public function applyMapFromCode($code) { + //TODO: Uncomment this when testing is complete; to boost getCode() speed; + //$this->$code = $code; + unset($this->tiles); + + $tmp = explode( ":", $code); + $headers = explode( '.', $tmp[0]); + $splitCode = explode( '.', $tmp[1]); + + $this->width = $headers[0]; + $this->height = $headers[1]; + $this->walls = $headers[2]; + $this->name = $headers[3]; + $this->flags = $headers[4]; + $this->dateCreated = $headers[5]; + $this->dateExpires = $headers[6]; + + //switch FLAGS. + $this->isBlind = false; + + //Make assumptions: + $this->isMultiPath = false; + $this->teleports = 0; + $this->checkpoints = 0; + + $distance = -1; + + //First Element + $index = 0; + $codePart = explode(',', $splitCode[$index]); + $next = $codePart[0]; + + for ($y = 0; $y < $this->height; $y++) { //Number of Rows + for ($x = 0; $x < $this->width; $x++) { //Number of Columns + $distance++; + if ($distance == $next) { + + $type = $codePart[1][0]; + $value = substr($codePart[1], 1); + if ($value <= 1) $value = ''; + + $this->tiles[$y][$x][TileType] = $type; + $this->tiles[$y][$x][TileValue] = $value; + + //Next Element + $index++; + $codePart = explode(',', $splitCode[$index]); + $next = $codePart[0]; + if ($next == '') $next = 0; + + //Start from 0 again. + $distance = -1; + } else { + $this->tiles[$y][$x][TileType] = TileEmpty; + } + } + } } - + //Outputs the new code. public function getCode() { //If we already have the code on hand... if ($this->code) return $this->code; //Otherwise we need to build the code: + $headers[0] = $this->width; + $headers[1] = $this->height; + $headers[3] = $this->walls; + $headers[4] = $this->name; + $headers[5] = $this->flags; + $headers[6] = $this->dateCreated; + $headers[7] = $this->dateExpires; + + $code = implode(".", $headers).':'; + + for ($y = 0; $y < $this->height; $y++) { //Number of Rows + for ($x = 0; $x < $this->width; $x++) { //Number of Columns + if ($this->tiles[$y][$x][TileType] !== TileEmpty) { + $positionOutput = $position; + if ($position == 0) + $positionOutput = ''; + $code .= $positionOutput.','.$this->tiles[$y][$x][TileType].$this->tiles[$y][$x][TileValue].'.'; + $position = -1; + } + $position++; + } + } + $this->code = $code; + return $code; } //Other "Magical" functions. |