diff --git a/content/scenes/B00001002.tpl b/content/scenes/B00001002.tpl index 309d6c8..719c329 100644 --- a/content/scenes/B00001002.tpl +++ b/content/scenes/B00001002.tpl @@ -1,56 +1,56 @@
{$xyz = explode(',', substr($CurrentPerso->location_local, 1, -1))} {$x = $xyz[0]}{$y = $xyz[1]}{$z = $xyz[2]} - {#Sector#} C{GeoOctocube::get_sector($x, $y, $z)} + {#Sector#} C{GeoOctocube::getSector($x, $y, $z)}
{#Zone#} {abs($x)}-{abs($y)}
{#Level#} {abs($z)}
{if $zone} {if $zone->type == "hotglue"} {else}

{#CantRender#}

{dprint_r($zone)} {/if} {else}

{#Builder#}

{#BuildInfo#}

{#StartBuild#}

{#GoNorth#}
{#GoEast#}
{#GoSouth#}
{#GoWest#}

{#GoUp#}
{#GoDown#}

{#ViewMap#}

{#GoTower#}

{/if} diff --git a/controllers/builder.php b/controllers/builder.php index 1254627..c5014bc 100644 --- a/controllers/builder.php +++ b/controllers/builder.php @@ -1,135 +1,135 @@ * @copyright 2010 SĂ©bastien Santoro aka Dereckson * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2 * @version 0.1 * @link http://scherzo.dereckson.be/doc/zed * @link http://zed.dereckson.be/ * @filesource */ require_once('includes/content/zone.php'); // // Helper methods // /** * Determines if a specified location is buildable * * @param GeoLocation $location the location to check * @param string if the location isn't buidable, a textual description of why. * @return bool true if the location is buildable ; otherwise, false * * @todo create a build.xml document to set what's buildable, and by who */ function is_buildable ($location, &$error = '') { //We currently allow build only in the hypership tower and core. if (!$location->body->hypership) { $error = "You can only invoke the HyperShip builder facilities inside the HyperShip."; return false; } //if ($build_location->place->code == "001") { // //Don't allow custom builds in the corridor (T?C?) //} if ($build_location->place->code == "003") { message_die("Bays aren't buildable."); return false; } return true; } // // Determines mode and initializes resources // switch ($build_mode = $url[1]) { case 'map': require_once('includes/geo/octocube.php'); $build_mode = 'map'; //Get zones at this floor if ($CurrentPerso->location->global == 'B00001002') { $point = GeoPoint3D::fromString($CurrentPerso->location->local); - $sector = GeoOctocube::get_sector_from_point3D($point); - $pattern = GeoOctocube::get_rlike_pattern_from_sector($sector, $point->z); + $sector = GeoOctocube::getSectorFromPoint3D($point); + $pattern = GeoOctocube::getRlikePatternFromSector($sector, $point->z); $zones = ContentZone::search($CurrentPerso->location->global, $pattern, true); } else { message_die(GENERAL_ERROR, "Can't map this area.", "Builder :: Map"); } //Template define('DOJO', true); $smarty->assign('zones', $zones); $template = "builder_map.tpl"; break; case '': case 'hotglue': //Temporary initialization code, to allow some build during the Zed alphatest $build_location = $CurrentPerso->location; $build_mode = 'hotglue'; $error = ''; if (!is_buildable($build_location, $error)) { message_die(GENERAL_ERROR, $error, "Can't build"); } //Gets or creates a new zone at build location $zone = ContentZone::at($build_location->global, $build_location->local, true); switch ($zone->type) { case 'hotglue': //All rulez break; case '': //New zone $zone->title = "Sandbox hotglue zone for $build_location->global $build_location->local"; $zone->type = 'hotglue'; $zone->save_to_database(); break; default: message_die("This isn't a zone managed by hotglue."); } unset($error); //Template $smarty->assign('location', $build_location); $smarty->assign('zone', $zone); $smarty->assign('IFRAME_SRC', '/apps/hotglue/index.php?zone_' . $zone->id . '/edit'); $template = 'builder_hotglue.tpl'; break; default: message_die(GENERAL_ERROR, "Unknown build mode: $build_mode"); } // // HTML output // //Serves header $smarty->assign('PAGE_TITLE', 'Builder'); include('header.php'); //Serves content $smarty->display($template); //Serves footer include('footer.php'); diff --git a/dev/tests/GeoOctocubeTest.php b/dev/tests/GeoOctocubeTest.php index bc49440..db598db 100644 --- a/dev/tests/GeoOctocubeTest.php +++ b/dev/tests/GeoOctocubeTest.php @@ -1,43 +1,43 @@ * @copyright 2010 Sébastien Santoro aka Dereckson * @license http://www.opensource.org/licenses/bsd-license.php BSD * @version 0.1 * @link http://scherzo.dereckson.be/doc/zed * @link http://zed.dereckson.be/ * @filesource */ require_once('../../includes/geo/octocube.php'); /** * Test cases for the class GeoPlace */ class GeoOctocubeTest extends PHPUnit_Framework_TestCase { /** * Tests the GeoPlace::is_valid_local_location($local_location) method. */ public function testGetSector () { //Testing HyperShip Tower T2C3 format - $this->assertTrue(GeoOctocube::get_sector(0, 0, 0) == 0); - $this->assertTrue(GeoOctocube::get_sector(-10, 6, -4) == 1); - $this->assertTrue(GeoOctocube::get_sector(10, 6, -4) == 2); - $this->assertTrue(GeoOctocube::get_sector(-10, -6, -4) == 3); - $this->assertTrue(GeoOctocube::get_sector(10, -6, -4) == 4); - $this->assertTrue(GeoOctocube::get_sector(-10, 6, 4) == 5); - $this->assertTrue(GeoOctocube::get_sector(10, 6, 4) == 6); - $this->assertTrue(GeoOctocube::get_sector(-10, -6, 4) == 7); - $this->assertTrue(GeoOctocube::get_sector(10, -6, 4) == 8); + $this->assertTrue(GeoOctocube::getSector(0, 0, 0) == 0); + $this->assertTrue(GeoOctocube::getSector(-10, 6, -4) == 1); + $this->assertTrue(GeoOctocube::getSector(10, 6, -4) == 2); + $this->assertTrue(GeoOctocube::getSector(-10, -6, -4) == 3); + $this->assertTrue(GeoOctocube::getSector(10, -6, -4) == 4); + $this->assertTrue(GeoOctocube::getSector(-10, 6, 4) == 5); + $this->assertTrue(GeoOctocube::getSector(10, 6, 4) == 6); + $this->assertTrue(GeoOctocube::getSector(-10, -6, 4) == 7); + $this->assertTrue(GeoOctocube::getSector(10, -6, 4) == 8); } } diff --git a/includes/geo/octocube.php b/includes/geo/octocube.php index f038445..0ea74d9 100755 --- a/includes/geo/octocube.php +++ b/includes/geo/octocube.php @@ -1,141 +1,141 @@ * @copyright 2010 Sébastien Santoro aka Dereckson * @license http://www.opensource.org/licenses/bsd-license.php BSD * @version 0.1 * @link http://scherzo.dereckson.be/doc/zed * @link http://zed.dereckson.be/ * @filesource */ /** * Geo octocube class * * An octocube is a cube divided in 8 parts (sliced in two in x, y and z) * * The coordinates (0, 0, 0) represents the octocube center. */ class GeoOctocube { /** * Gets the sector from the (x, y, z) specified coordinates * * Sector will be: * * // _____ _____ * // / 5 / 6 /| * // /- - -/- - -/ | * // /_____/____ /| | * // | | | |/| * // | 7 | 8 | / | 2 * // |_____|_____|/| | * // | | | |/ * // | 3 | 4 | / * // |_____|_____|/ * * * @param int $x the x coordinate * @param int $y the y coordinate * @param int $z the z coordinate * @return int the number of the sector (0 if x = y = z = 0 ; otherwise, 1 to 8) */ - static function get_sector ($x, $y, $z) { + static function getSector ($x, $y, $z) { //Cube center if ($x == 0 && $y == 0 && $z == 0) return 0; //One of the 8 cubes $sector = 1; if ($x >= 0) $sector++; //we're at right if ($y < 0) $sector += 2; //we're at bottom if ($z >= 0) $sector += 4; //we're on the top layer return $sector; } /** * Gets the sector from the (x, y, z) specified coordinates - * @see get_sector + * @see getSector * * @param mixed $pt a GeoPoint3D object for the x, y, z coordinates or a parsable string * @return int the number of the sector (0 if x = y = z 0 ; otherwise, 1 to 8) */ - static function get_sector_from_point3D ($pt) { + static function getSectorFromPoint3D ($pt) { if (is_string($pt)) { $pt = GeoPoint3D::fromString($pt); } - return self::get_sector($pt->x, $pt->y, $pt->z); + return self::getSector($pt->x, $pt->y, $pt->z); } /** * Gets the base vector for the specified sector * * Example code: * - * $vector = GeoOctocube::get_base_vector(4); + * $vector = GeoOctocube::getBaseVector(4); * //$vector is a (1, -1, -1) array * * @param int $sector the sector number (0-8) * @return array if the sector is 0, (0, 0, 0) ; otherwise, an array with three signed 1 values. */ - static function get_base_vector ($sector) { + static function getBaseVector ($sector) { switch ($sector) { case 0: return array(0, 0, 0); case 1: return array(-1, 1, -1); case 2: return array(1, 1, -1); case 3: return array(-1, -1, -1); case 4: return array(1, -1, -1); case 5: return array(-1, 1, 1); case 6: return array(1, 1, 1); case 7: return array(-1, -1, 1); case 8: return array(1, -1, 1); - default: message_die(GENERAL_ERROR, "Invalid sector: $sector", "GeoOctocube::get_base_vector"); + default: message_die(GENERAL_ERROR, "Invalid sector: $sector", "GeoOctocube::getBaseVector"); } } /** * Gets SQL RLIKE pattern for the specified sector * * @param int $sector the sector number (0-8) * @param int $z if not null, limits the query to the specified z coordinate [optional] * @return string a SQL clause like "([0-9]+, -[0,9]+, [0,9]+)" */ - static function get_rlike_pattern_from_sector ($sector, $z = null) { + static function getRlikePatternFromSector ($sector, $z = null) { if ($sector == 0) return "(0, 0, 0)"; - $vector = self::get_base_vector($sector); + $vector = self::getBaseVector($sector); //x if ($vector[0] == 1) $query = "([0-9]+, "; else $query = "(-[0-9]+, "; //y if ($vector[1] == 1) $query .= "[0-9]+, "; else $query .= "-[0-9]+, "; //z if ($z !== null) { $query .= "$z)"; } elseif ($vector[2] == "1") { $query .= "[0-9]+)"; } else { $query .= "-[0-9]+)"; } return $query; } } diff --git a/skins/zed/builder_map.tpl b/skins/zed/builder_map.tpl index 211e6f3..dbdba27 100644 --- a/skins/zed/builder_map.tpl +++ b/skins/zed/builder_map.tpl @@ -1,49 +1,49 @@
{$xyz = explode(',', substr($CurrentPerso->location_local, 1, -1))} {$x = $xyz[0]}{$y = $xyz[1]}{$z = $xyz[2]} - Sector C{GeoOctocube::get_sector($x, $y, $z)} + Sector C{GeoOctocube::getSector($x, $y, $z)}
Zone {abs($x)}-{abs($y)}
Niveau {abs($z)}
{if $zones}
{else}
This area is empty.
{/if}