├── .gitignore ├── LOCAL.htm ├── LOCAL_var.php ├── README.md ├── compat.php ├── compat_53.php ├── compat_54.php ├── elmlor.htm ├── error.php ├── evol.htm ├── functions.inc.php ├── idproperties.php ├── idproperties_53.php ├── idproperties_54.php ├── imagelayer.php ├── infos.php ├── layer.php ├── local.php ├── lof-newworld.htm ├── lof.htm ├── map.php ├── object.php ├── objectlayer.php ├── online.php ├── properties.php ├── properties_53.php ├── properties_54.php ├── rot.php ├── session.php ├── stendhal.htm ├── tales.htm ├── tilelayer.php ├── tileset.php ├── tmw.htm ├── viewer.php ├── viewer_part.php ├── viewer_part_ui.php ├── viewer_ui.php └── viewer_view.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.ttf 2 | *.LNK 3 | cvs* 4 | test* 5 | *.src.php 6 | *.bak 7 | 8 | -------------------------------------------------------------------------------- /LOCAL.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /LOCAL_var.php: -------------------------------------------------------------------------------- 1 | '../../tmw/desert.tmx', 4 | 1 => '../../tmw/isometric_grass_and_water.tmx', 5 | 2 => '../../tmw/perspective_walls.tmx', 6 | 3 => '../../tmw/room.tmx', 7 | 4 => '../../tmw/sewers.tmx', 8 | 5 => '../maps/isometric.tmx', 9 | ) 10 | ?> -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | php-tmx-viewer 2 | ============== 3 | 4 | a TMX map viewer written in PHP 5 | 6 | DEPENDENCIES 7 | ============ 8 | 9 | It just needs the gd2 extension, possibly with freetype support if object names are shown. 10 | 11 | It could be done with the gMagick or iMagick / MagickWand extension, but they aren't widespread enough (I did it in the previous version). 12 | 13 | TODO 14 | ==== 15 | 16 | improve ui 17 | 18 | add cache support 19 | 20 | add other games in online list 21 | -------------------------------------------------------------------------------- /compat.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebbu2/php-tmx-viewer/f93a689711d4876628c39254733c0aab66d12920/compat.php -------------------------------------------------------------------------------- /compat_53.php: -------------------------------------------------------------------------------- 1 | _properties[]=new properties(); 14 | } 15 | public function __call($name, $args) { 16 | //print('You called the method '.$name.' with '.count($args).' arguments.
'."\r\n"); 17 | foreach($this->_properties as $prop) { 18 | if(method_exists($prop, $name)) { 19 | return call_user_func_array(array($prop, $name), $args); 20 | } 21 | } 22 | } 23 | }; 24 | 25 | class Tileset extends TilesetBase { 26 | private $_properties=array(); 27 | function __construct() { 28 | if(method_exists(get_parent_class($this), '__construct')) { 29 | parent::__construct(); 30 | } 31 | $this->_properties[]=new properties(); 32 | $this->_properties[]=new idproperties(); 33 | } 34 | public function __call($name, $args) { 35 | //print('You called the method '.$name.' with '.count($args).' arguments.
'."\r\n"); 36 | foreach($this->_properties as $prop) { 37 | if(method_exists($prop, $name)) { 38 | return call_user_func_array(array($prop, $name), $args); 39 | } 40 | } 41 | } 42 | }; 43 | 44 | class TileLayer extends TileLayerBase { 45 | private $_properties=array(); 46 | function __construct() { 47 | if(method_exists(get_parent_class($this), '__construct')) { 48 | parent::__construct(); 49 | } 50 | $this->_properties[]=new properties(); 51 | } 52 | public function __call($name, $args) { 53 | //print('You called the method '.$name.' with '.count($args).' arguments.
'."\r\n"); 54 | foreach($this->_properties as $prop) { 55 | if(method_exists($prop, $name)) { 56 | return call_user_func_array(array($prop, $name), $args); 57 | } 58 | } 59 | } 60 | }; 61 | 62 | class ObjectLayer extends ObjectLayerBase { 63 | private $_properties=array(); 64 | function __construct() { 65 | if(method_exists(get_parent_class($this), '__construct')) { 66 | parent::__construct(); 67 | } 68 | $this->_properties[]=new properties(); 69 | } 70 | public function __call($name, $args) { 71 | //print('You called the method '.$name.' with '.count($args).' arguments.
'."\r\n"); 72 | foreach($this->_properties as $prop) { 73 | if(method_exists($prop, $name)) { 74 | return call_user_func_array(array($prop, $name), $args); 75 | } 76 | } 77 | } 78 | }; 79 | 80 | class ImageLayer extends ImageLayerBase { 81 | private $_properties=array(); 82 | function __construct() { 83 | if(method_exists(get_parent_class($this), '__construct')) { 84 | parent::__construct(); 85 | } 86 | $this->_properties[]=new properties(); 87 | } 88 | public function __call($name, $args) { 89 | //print('You called the method '.$name.' with '.count($args).' arguments.
'."\r\n"); 90 | foreach($this->_properties as $prop) { 91 | if(method_exists($prop, $name)) { 92 | return call_user_func_array(array($prop, $name), $args); 93 | } 94 | } 95 | } 96 | }; 97 | 98 | class MapObject extends ObjectBase { 99 | private $_properties=array(); 100 | function __construct() { 101 | if(method_exists(get_parent_class($this), '__construct')) { 102 | parent::__construct(); 103 | } 104 | $this->_properties[]=new properties(); 105 | } 106 | public function __call($name, $args) { 107 | //print('You called the method '.$name.' with '.count($args).' arguments.
'."\r\n"); 108 | foreach($this->_properties as $prop) { 109 | if(method_exists($prop, $name)) { 110 | return call_user_func_array(array($prop, $name), $args); 111 | } 112 | } 113 | } 114 | }; 115 | ?> -------------------------------------------------------------------------------- /compat_54.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /elmlor.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /error.php: -------------------------------------------------------------------------------- 1 | getMessage(), "\n"; 7 | printf('Uncaught exception: %s on %s:%d'."\n", 8 | $exception->getMessage(), 9 | $exception->getFile(), 10 | $exception->getLine() 11 | ); 12 | } 13 | 14 | set_exception_handler('exception_handler'); 15 | 16 | function myErrorHandler($errno, $errstr, $errfile, $errline) 17 | { 18 | if (!(error_reporting() & $errno)) { 19 | // This error code is not included in error_reporting 20 | return; 21 | } 22 | 23 | global $header; 24 | $header='text/plain'; 25 | 26 | switch ($errno) { 27 | case E_USER_ERROR: 28 | echo "My ERROR [$errno] $errstr
\n"; 29 | echo "Fatal error on line $errline in file $errfile"; 30 | echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")
\n"; 31 | echo "Aborting...
\n"; 32 | exit(1); 33 | break; 34 | 35 | case E_USER_WARNING: 36 | echo "My WARNING [$errno] $errstr in $errfile:$errline
\n"; 37 | break; 38 | 39 | case E_USER_NOTICE: 40 | echo "My NOTICE [$errno] $errstr in $errfile:$errline
\n"; 41 | break; 42 | 43 | default: 44 | echo "Unknown error type: [$errno] $errstr in $errfile:$errline
\n"; 45 | break; 46 | } 47 | 48 | /* Don't execute PHP internal error handler */ 49 | return true; 50 | } 51 | 52 | $old_error_handler = set_error_handler("myErrorHandler"); 53 | 54 | ?> -------------------------------------------------------------------------------- /evol.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /functions.inc.php: -------------------------------------------------------------------------------- 1 | > 16) & 0xFF; 60 | $_g = ($rgb >> 8) & 0xFF; 61 | $_b = $rgb & 0xFF; 62 | if($r==$_r && $g==$_g && $b==$_b) { 63 | imagesetpixel($img, $j, $i, $trans); 64 | } 65 | } 66 | } 67 | } 68 | 69 | function swap(&$a, &$b) { 70 | $tmp=$a; 71 | $a=$b; 72 | $b=$tmp; 73 | } 74 | 75 | function swap_ar(&$var, $pos1, $pos2) { 76 | $tmp=$var[$pos1]; 77 | $var[$pos1]=$var[$pos2]; 78 | $var[$pos2]=$tmp; 79 | } 80 | 81 | function parse_data($data, $encoding='', $compression='') { 82 | if($encoding=='base64') { 83 | $data=base64_decode($data); 84 | } 85 | else if($encoding=='csv') { 86 | $data2=explode(chr(10),$data); 87 | //var_dump(count($data2)); 88 | $data3=array(); 89 | $i=0; 90 | $data=''; 91 | foreach($data2 as $line) { 92 | $line=trim($line, " \t\n\r\0\x0B,"); 93 | $data3[$i]=explode(',',$line); 94 | //var_dump(count($data3[$i])); 95 | ++$i; 96 | } 97 | unset($line,$data2); 98 | $irow=0; 99 | $icol=0; 100 | $icol2=0; 101 | foreach($data3 as $row) { 102 | $icol=0; 103 | foreach($row as $gid) { 104 | $data.=pack('V', $gid); 105 | ++$icol; 106 | } 107 | if($icol>$icol2) $icol2=$icol; 108 | ++$irow; 109 | } 110 | //var_dump($irow,$icol2); 111 | unset($gid,$row,$data3); 112 | } 113 | else { 114 | //$data=$data; 115 | } 116 | switch(strtolower($compression)) { 117 | case 'zlib': 118 | $data=gzuncompress($data); 119 | break; 120 | case 'gzip': 121 | //$data=gzuncompress($data); 122 | //$data=gzinflate($data); 123 | //$data=softcoded_gzdecode($data); 124 | $data=gzdecode($data); 125 | break; 126 | case 'bzip2': 127 | case 'bz2': 128 | $data=bzdecompress($data); 129 | break; 130 | case 'none': 131 | default: 132 | break; 133 | } 134 | return $data; 135 | } 136 | 137 | $opts=array( 138 | 'http'=>array( 139 | 'user_agent'=>'Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0', 140 | ), 141 | 'ssl'=>array( 142 | 'allow_self_signed'=>true, 143 | ), 144 | 'https'=>array( 145 | 'user_agent'=>'Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0', 146 | 'allow_self_signed'=>true, 147 | ), 148 | ); 149 | $ctx = stream_context_create($opts); 150 | 151 | function canonicalize($address) 152 | { 153 | $address = explode('/', $address); 154 | $keys = array_keys($address, '..'); 155 | 156 | foreach($keys AS $keypos => $key) 157 | { 158 | array_splice($address, $key - ($keypos * 2 + 1), 2); 159 | } 160 | 161 | $address = implode('/', $address); 162 | $address = str_replace('./', '', $address); 163 | return $address; 164 | } 165 | 166 | function get_url($url) { 167 | global $ctx; 168 | //$url=preg_replace('#/([^/]+)/\.\.(?=/)#','',$url);//NOTE: need to be applied multiple times 169 | $url=canonicalize($url); 170 | $data=file_get_contents($url,false,$ctx); 171 | return $data; 172 | } 173 | 174 | ?> -------------------------------------------------------------------------------- /idproperties.php: -------------------------------------------------------------------------------- 1 | = 50400) { 3 | require_once('idproperties_54.php'); 4 | } 5 | else { 6 | require_once('idproperties_53.php'); 7 | } 8 | ?> -------------------------------------------------------------------------------- /idproperties_53.php: -------------------------------------------------------------------------------- 1 | idproperties; 7 | } 8 | 9 | public function setAllProperties($idproperties=array()) { 10 | $this->idproperties=array_values(array_merge($this->idproperties, $idproperties)); 11 | } 12 | 13 | public function getIdProperties($id=NULL) { 14 | if(array_key_exists($id, $this->idproperties)) { 15 | return $this->idproperties[$id]; 16 | } 17 | else { 18 | return NULL; 19 | } 20 | } 21 | 22 | public function setIdProperties($id=NULL, $idproperties=array()) { 23 | $this->idproperties[$id]=array_values(array_merge($this->idproperties[$id], $idproperties)); 24 | } 25 | 26 | public function getIdProperty($id=NULL, $key='') { 27 | if(array_key_exists($id, $this->idproperties)) { 28 | if(array_key_exists($key, $this->idproperties)) { 29 | return $this->idproperties[$id][$key]; 30 | } 31 | else { 32 | return NULL; 33 | } 34 | } 35 | else { 36 | return NULL; 37 | } 38 | } 39 | 40 | public function setIdProperty($id=NULL, $key='', $value='') { 41 | $this->idproperties[$id][$key]=$value; 42 | } 43 | 44 | public function loadIdProperties_from_element(array $xml=NULL, $ref='') { 45 | if($xml===NULL) return; 46 | foreach($xml as $elem) { 47 | $id=(string)$elem['id']; 48 | if((bool)$elem->properties===false) continue; 49 | foreach($elem->properties->property as $prop) { 50 | $this->setIdProperty($id, (string)$prop['name'], (string)$prop['value']); 51 | } 52 | } 53 | } 54 | }; 55 | ?> -------------------------------------------------------------------------------- /idproperties_54.php: -------------------------------------------------------------------------------- 1 | idproperties; 7 | } 8 | 9 | public function setAllProperties($idproperties=array()) { 10 | $this->idproperties=array_values(array_merge($this->idproperties, $idproperties)); 11 | } 12 | 13 | public function getIdProperties($id=NULL) { 14 | if(array_key_exists($id, $this->idproperties)) { 15 | return $this->idproperties[$id]; 16 | } 17 | else { 18 | return NULL; 19 | } 20 | } 21 | 22 | public function setIdProperties($id=NULL, $idproperties=array()) { 23 | $this->idproperties[$id]=array_values(array_merge($this->idproperties[$id], $idproperties)); 24 | } 25 | 26 | public function getIdProperty($id=NULL, $key='') { 27 | if(array_key_exists($id, $this->idproperties)) { 28 | if(array_key_exists($key, $this->idproperties)) { 29 | return $this->idproperties[$id][$key]; 30 | } 31 | else { 32 | return NULL; 33 | } 34 | } 35 | else { 36 | return NULL; 37 | } 38 | } 39 | 40 | public function setIdProperty($id=NULL, $key='', $value='') { 41 | $this->idproperties[$id][$key]=$value; 42 | } 43 | 44 | public function loadIdProperties_from_element(array $xml=NULL, $ref='') { 45 | if($xml===NULL) return; 46 | foreach($xml as $elem) { 47 | $id=(string)$elem['id']; 48 | if((bool)$elem->properties===false) continue; 49 | foreach($elem->properties->property as $prop) { 50 | $this->setIdProperty($id, (string)$prop['name'], (string)$prop['value']); 51 | } 52 | } 53 | } 54 | }; 55 | ?> -------------------------------------------------------------------------------- /imagelayer.php: -------------------------------------------------------------------------------- 1 | map=$map; 26 | } 27 | public function getMap() { 28 | return $this->map; 29 | } 30 | 31 | public function load_from_element(SimpleXMLElement $xml, $ref='', $recur=true) { 32 | $this->name=(string)$xml['name']; 33 | $this->x=(string)$xml['x']; 34 | $this->y=(string)$xml['y']; 35 | $this->width=(string)$xml['width']; 36 | $this->height=(string)$xml['height']; 37 | $this->opacity=(int)$xml['opacity']; 38 | $this->visible=(int)$xml['visible']; 39 | $this->source=(string)$xml->image['source']; 40 | $this->trans=(string)$xml->image['trans']; 41 | if((bool)$xml->properties!==false) { 42 | $this->loadProperties_from_element($xml->properties, $ref); 43 | } 44 | } 45 | 46 | public function isValid() { 47 | if(!is_string($this->name)) { 48 | throw new Exception('Incorrect imagelayer name value.'); 49 | return false; 50 | } 51 | if(!is_int($this->x)) { 52 | throw new Exception('Incorrect imagelayer x value.'); 53 | return false; 54 | } 55 | if(!is_int($this->y)) { 56 | throw new Exception('Incorrect imagelayer y value.'); 57 | return false; 58 | } 59 | if(!is_int($this->width ) || $this->width <0) { 60 | throw new Exception('Incorrect imagelayer width .'); 61 | return false; 62 | } 63 | if(!is_int($this->height) || $this->height<0) { 64 | throw new Exception('Incorrect imagelayer height.'); 65 | return false; 66 | } 67 | if(!is_int($this->opacity) || ($this->opacity!=0 && $this->opacity!=1)) { 68 | throw new Exception('Incorrect imagelayer opacity value.'); 69 | return false; 70 | } 71 | if(!is_int($his->visible) || ($this->visible!=0 && $this->visible!=1)) { 72 | throw new Exception('Incorrect imagelayer visible value.'); 73 | return false; 74 | } 75 | if(!is_string($this->source)) { 76 | throw new Exception('Incorrent imagelayer image source value.'); 77 | return false; 78 | } 79 | if(!is_string($this->trans)) { 80 | throw new Exception('Incorrent imagelayer image trans value.'); 81 | return false; 82 | } 83 | return true; 84 | } 85 | }; 86 | 87 | ?> -------------------------------------------------------------------------------- /infos.php: -------------------------------------------------------------------------------- 1 | 0) { 53 | foreach($matches[1] as $class) { 54 | $classes[]=$class; 55 | } 56 | unset($class); 57 | } 58 | else { 59 | $res=preg_match_all('/function\s+(\S+)\s*\(/', $data, $matches); 60 | if($res>0) { 61 | foreach($matches[1] as $function) { 62 | $functions[]=$function; 63 | } 64 | unset($function); 65 | } 66 | } 67 | unset($data); 68 | } 69 | unset($file,$res,$matches); 70 | 71 | $action='list_proj'; 72 | } 73 | require(dirname(__FILE__).'/../infos.php'); 74 | ?> -------------------------------------------------------------------------------- /layer.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /local.php: -------------------------------------------------------------------------------- 1 | '."\r\n"; 19 | //echo ' 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
39 | 40 | 41 | 42 | 138 | 139 |
142 | 143 | 144 | -------------------------------------------------------------------------------- /properties.php: -------------------------------------------------------------------------------- 1 | = 50400) { 3 | require_once('properties_54.php'); 4 | } 5 | else { 6 | require_once('properties_53.php'); 7 | } 8 | ?> -------------------------------------------------------------------------------- /properties_53.php: -------------------------------------------------------------------------------- 1 | properties; 7 | } 8 | 9 | public function setProperties($properties=array()) { 10 | $this->properties=array_values(array_merge($this->properties, $properties)); 11 | } 12 | 13 | public function getProperty($key='') { 14 | if(array_key_exists($key, $this->properties)) { 15 | return $this->properties[$key]; 16 | } 17 | else { 18 | return NULL; 19 | } 20 | } 21 | 22 | public function setProperty($key='', $value='') { 23 | $this->properties[$key]=$value; 24 | } 25 | 26 | public function loadProperties_from_element(SimpleXMLElement $xml, $ref='') { 27 | foreach($xml->property as $prop) { 28 | $this->setProperty((string)$prop['name'], (string)$prop['value']); 29 | } 30 | } 31 | }; 32 | ?> -------------------------------------------------------------------------------- /properties_54.php: -------------------------------------------------------------------------------- 1 | properties; 7 | } 8 | 9 | public function setProperties($properties=array()) { 10 | $this->properties=array_values(array_merge($this->properties, $properties)); 11 | } 12 | 13 | public function getProperty($key='') { 14 | if(array_key_exists($key, $this->properties)) { 15 | return $this->properties[$key]; 16 | } 17 | else { 18 | return NULL; 19 | } 20 | } 21 | 22 | public function setProperty($key='', $value='') { 23 | $this->properties[$key]=$value; 24 | } 25 | 26 | public function loadProperties_from_element(SimpleXMLElement $xml, $ref='') { 27 | foreach($xml->property as $prop) { 28 | $this->setProperty((string)$prop['name'], (string)$prop['value']); 29 | } 30 | } 31 | }; 32 | ?> -------------------------------------------------------------------------------- /rot.php: -------------------------------------------------------------------------------- 1 | =0 && $lid<6*9); 5 | //if($lid==-1) return -1; 6 | if($lid==0) return 0; 7 | if($lid>0 && $lid<9) return -1; 8 | $x=(int)($lid%9); 9 | $y=(int)($lid/9); 10 | //var_dump($x,$y);die(); 11 | //angles 12 | if($y==0 && $x==0) { /*do nothing*/ } 13 | else if($y==1 && ($x%3)==0) { $x+=2; } 14 | else if($y==1 && ($x%3)==2) { $y+=2; } 15 | else if($y==3 && ($x%3)==2) { $x-=2; } 16 | else if($y==3 && ($x%3)==0) { $y-=2; } 17 | //bords 18 | else if($y==1 && ($x%3)==1) { $x+=1; $y+=1; } 19 | else if($y==2 && ($x%3)==2) { $x-=1; $y+=1; } 20 | else if($y==3 && ($x%3)==1) { $x-=1; $y-=1; } 21 | else if($y==2 && ($x%3)==0) { $x+=1; $y-=1; } 22 | //middles 23 | else if($y==2 && ($x%3)==1) { /*do nothing*/ } 24 | //hole angles 25 | else if($y==4 && ($x%2)==0) { $x+=1; } 26 | else if($y==4 && ($x%2)==1) { $y+=1; } 27 | else if($y==5 && ($x%2)==1) { $x-=1; } 28 | else if($y==5 && ($x%2)==0) { $y-=1; } 29 | return $x+$y*9; 30 | } 31 | 32 | function rotate90ccw_lid($lid) { 33 | assert($lid>=0 && $lid<6*9); 34 | //if($lid==-1) return -1; 35 | if($lid==0) return 0; 36 | if($lid>0 && $lid<9) return -1; 37 | $x=(int)($lid%9); 38 | $y=(int)($lid/9); 39 | //var_dump($x,$y);die(); 40 | //angles 41 | if($y==0 && $x==0) { /*do nothing*/ } 42 | else if($y==1 && ($x%3)==0) { $y+=2; } 43 | else if($y==1 && ($x%3)==2) { $x-=2; } 44 | else if($y==3 && ($x%3)==2) { $y-=2; } 45 | else if($y==3 && ($x%3)==0) { $x+=2; } 46 | //bords 47 | else if($y==1 && ($x%3)==1) { $x-=1;$y+=1; } 48 | else if($y==2 && ($x%3)==2) { $x-=1;$y-=1; } 49 | else if($y==3 && ($x%3)==1) { $x+=1;$y-=1; } 50 | else if($y==2 && ($x%3)==0) { $x+=1;$y+=1; } 51 | //middles 52 | else if($y==2 && ($x%3)==1) { /*do nothing*/ } 53 | //hole angles 54 | else if($y==4 && ($x%2)==0) { $y+=1; } 55 | else if($y==4 && ($x%2)==1) { $x-=1; } 56 | else if($y==5 && ($x%2)==1) { $y-=1; } 57 | else if($y==5 && ($x%2)==0) { $x+=1; } 58 | return $x+$y*9; 59 | } 60 | 61 | function rotate180_lid($lid) { 62 | assert($lid>=0 && $lid<6*9); 63 | //if($lid==-1) return -1; 64 | if($lid==0) return 0; 65 | if($lid>0 && $lid<9) return -1; 66 | $x=(int)($lid%9); 67 | $y=(int)($lid/9); 68 | if($y==0 && $x==0) { /*do nothing*/ } 69 | else if($y==1 && ($x%3)==0) { $x+=2;$y+=2; } 70 | else if($y==1 && ($x%3)==2) { $x-=2;$y+=2; } 71 | else if($y==3 && ($x%3)==2) { $x-=2;$y-=2; } 72 | else if($y==3 && ($x%3)==0) { $x+=2;$y-=2; } 73 | //bords 74 | else if($y==1 && ($x%3)==1) { $y+=2; } 75 | else if($y==2 && ($x%3)==2) { $x-=2; } 76 | else if($y==3 && ($x%3)==1) { $y-=2; } 77 | else if($y==2 && ($x%3)==0) { $x+=2; } 78 | //middles 79 | else if($y==2 && ($x%3)==1) { /*do nothing*/ } 80 | //hole angles 81 | else if($y==4 && ($x%2)==0) { $x+=1;$y+=1; } 82 | else if($y==4 && ($x%2)==1) { $x-=1;$y+=1; } 83 | else if($y==5 && ($x%2)==1) { $x-=1;$y-=1; } 84 | else if($y==5 && ($x%2)==0) { $x+=1;$y-=1; } 85 | return $x+$y*9; 86 | } 87 | ?> -------------------------------------------------------------------------------- /session.php: -------------------------------------------------------------------------------- 1 | Layers not to draw'."\r\n"; 25 | if(array_key_exists('layers_nodraw',$_SESSION)) { 26 | if(is_array($_SESSION['layers_nodraw']) && count($_SESSION['layers_nodraw'])>0) { 27 | echo ''."\r\n"; 28 | foreach($_SESSION['layers_nodraw'] as $layer) { 29 | echo ' '."\r\n"; 30 | echo ' '."\r\n"; 31 | echo ' '."\r\n"; 32 | echo ' '."\r\n"; 33 | } 34 | echo '
'.$layer.'Delete
'."\r\n"; 35 | } 36 | } 37 | echo '
'."\r\n"; 38 | echo ''."\r\n"; 39 | echo '
'."\r\n"; 40 | echo ''."\r\n"; 41 | echo ''."\r\n"; 42 | echo '
'."\r\n"; 43 | //var_dump($_SESSION['layers_nodraw']); 44 | echo '

Tilesets not to draw

'."\r\n"; 45 | if(array_key_exists('tilesets_nodraw',$_SESSION)) { 46 | if(is_array($_SESSION['tilesets_nodraw']) && count($_SESSION['tilesets_nodraw'])>0) { 47 | echo ''."\r\n"; 48 | foreach($_SESSION['tilesets_nodraw'] as $tileset) { 49 | echo ' '."\r\n"; 50 | echo ' '."\r\n"; 51 | echo ' '."\r\n"; 52 | echo ' '."\r\n"; 53 | } 54 | echo '
'.$tileset.'Delete
'."\r\n"; 55 | } 56 | } 57 | echo '
'."\r\n"; 58 | echo ''."\r\n"; 59 | echo '
'."\r\n"; 60 | echo ''."\r\n"; 61 | echo ''."\r\n"; 62 | echo '
'."\r\n"; 63 | 64 | ?> -------------------------------------------------------------------------------- /stendhal.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | -------------------------------------------------------------------------------- /tales.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /tilelayer.php: -------------------------------------------------------------------------------- 1 | map=$map; 27 | } 28 | public function getMap() { 29 | return $this->map; 30 | } 31 | 32 | public function load_from_element(SimpleXMLElement $xml, $ref='', $recur=true) { 33 | $this->name=(string)$xml['name']; 34 | $this->x=(int)$xml['x']; 35 | $this->y=(int)$xml['y']; 36 | $this->width =(int)$xml['width' ]; 37 | $this->height=(int)$xml['height']; 38 | $this->encoding=(string)$xml->data['encoding']; 39 | $this->compression=(string)$xml->data['compression']; 40 | if((bool)$xml->properties!==false) { 41 | $this->loadProperties_from_element($xml->properties, $ref); 42 | } 43 | //$this->parse_data((string)trim($xml->data[0])); 44 | //var_dump((string)trim($xml->data[0]));die(); 45 | $this->data=(string)trim($xml->data[0]); 46 | if($recur) { 47 | $this->load_data(); 48 | } 49 | if($recur && strlen($this->data)<$this->map->width*$this->map->height*4) { 50 | var_dump($this->name,strlen($this->data),$this->map->width*$this->map->height*4,$xml->data,(string)trim($xml->data[0])); 51 | trigger_error('incorrect layer data', E_USER_ERROR); 52 | } 53 | } 54 | 55 | function load_data() { 56 | if( strlen($this->data) < $this->map->width*$this->map->height*4 ) { 57 | $this->data=parse_data($this->data, $this->encoding, $this->compression); 58 | } 59 | } 60 | 61 | public function get_tile($index) { 62 | if($index*4+4>strlen($this->data)) { 63 | var_dump(strlen($this->data),$index); 64 | debug_print_backtrace(); 65 | trigger_error('incorrect index or layer data (1).', E_USER_ERROR); 66 | } 67 | $cgid=substr($this->data, $index*4, 4); 68 | if(strlen($cgid)<4) { 69 | var_dump($index); 70 | debug_print_backtrace(); 71 | trigger_error('incorrect index or layer data (2).', E_USER_ERROR); 72 | }//*/ 73 | //var_dump($cgid);//die(); 74 | $cgid=unpack('V',$cgid); 75 | //var_dump($cgid[1]);//die(); 76 | return $cgid[1]; 77 | } 78 | 79 | public function get_tile_number() { 80 | return floor(strlen($this->data)/4); 81 | } 82 | 83 | public function set_tile($index, $value) { 84 | //var_dump($value);//die(); 85 | $cgid=pack('V',$value); 86 | //var_dump($cgid);//die(); 87 | assert(strlen($cgid)==4) or trigger_error('bad cgid value.', E_USER_ERROR); 88 | $this->data=substr($this->data, 0, $index*4).$cgid.substr($this->data, $index*4+4); 89 | } 90 | 91 | public function transpose() { 92 | $data2=''; 93 | for($i=0;$i<$this->width;++$i) { 94 | for($j=0;$j<$this->height;++$j) { 95 | $data2.=substr($this->data, ($j*$this->width+$i)*4, 4); 96 | } 97 | } 98 | assert(strlen($data2)===strlen($this->data)); 99 | $this->data=$data2; 100 | $tmp=$this->width; 101 | $this->width=$this->height; 102 | $this->height=$tmp; 103 | } 104 | 105 | public function reverse_row() { 106 | for($i=0;$i<$this->height;++$i) { 107 | for($j=0;$jwidth/2);++$j) { 108 | for($a=0;$a<4;++$a) swap_ar($this->data, ($i*$this->width+$j)*4+$a, (($i+1)*$this->width-1-$j)*4+$a); 109 | } 110 | } 111 | } 112 | 113 | public function reverse_col() { 114 | for($j=0;$j<$this->width;++$j) { 115 | for($i=0;$iheight/2);++$i) { 116 | for($a=0;$a<4;++$a) swap_ar($this->data, ($i*$this->width+$j)*4+$a, (($this->height-1-$i)*$this->width+$j)*4+$a); 117 | } 118 | } 119 | } 120 | 121 | public function rot90cw() { 122 | $this->transpose(); 123 | $this->reverse_row(); 124 | } 125 | 126 | public function rot90ccw() { 127 | $this->transpose(); 128 | $this->reverse_col(); 129 | } 130 | 131 | public function rot180() { 132 | $this->reverse_row(); 133 | $this->reverse_col(); 134 | } 135 | 136 | public function isValid() { 137 | if(!is_string($this->name)) { 138 | throw new Exception('Incorrect tilelayer name.'); 139 | return false; 140 | } 141 | if(!is_int($this->x)) { 142 | throw new Exception('Incorrect tilelayer x value.'); 143 | return false; 144 | } 145 | if(!is_int($this->y)) { 146 | throw new Exception('Incorrect tilelayer y value.'); 147 | return false; 148 | } 149 | if(!is_int($this->width ) || $this->width <0) { 150 | throw new Exception('Incorrect tilelayer width .'); 151 | return false; 152 | } 153 | if(!is_int($this->height) || $this->height<0) { 154 | throw new Exception('Incorrect tilelayer height.'); 155 | return false; 156 | } 157 | if(!is_int($this->visible) || ($this->visible!=0 && $this->visible!=1)) { 158 | throw new Exception('Incorrect tilelayer visible.'); 159 | return false; 160 | } 161 | if(!in_array($this->encoding, array('base64', 'csv', 'xml', 'none'))) { 162 | throw new Exception('Incorrect tilelayer encoding.'); 163 | return false; 164 | } 165 | if(!in_array($this->compression, array('zlib', 'gzip', 'bz2', 'bzip2', 'none'))) { 166 | throw new Exception('Incorrect tilelayer compression.'); 167 | return false; 168 | } 169 | if($this->map!=NULL) { 170 | //assert($this->map instanceof Map); 171 | //if( strlen($this->data) != (4*$this->map->width*$this->map->height) ) { 172 | if( strlen($this->data) != (4*$this->width*$this->height) ) { 173 | var_dump(strlen($this->data),4*$this->width*$this->height); 174 | throw new Exception('Incorrect tilelayer data.'); 175 | return false; 176 | } 177 | } 178 | return true; 179 | } 180 | }; 181 | 182 | ?> -------------------------------------------------------------------------------- /tileset.php: -------------------------------------------------------------------------------- 1 | 'https://github.com/themanaworld/tmwa-client-data/raw/master/', 36 | 'evol'=>'https://github.com/EvolOnline/clientdata-beta/raw/master/', 37 | 'tales'=>'https://github.com/tales/sourceoftales/raw/master/', 38 | 'elmlor'=>'https://github.com/KaneHart/Elmlor-Client-Data/raw/master/', 39 | 'lof'=>'https://github.com/landoffire/lof-tmwa-client-data/raw/master/', 40 | 'lof-newworld'=>'https://github.com/landoffire/lof-newworld/raw/master/', 41 | 'stendhal'=>'http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/tiled/', 42 | ); 43 | 44 | //constructors 45 | 46 | //static methods 47 | public static function load_xml_from_file($filename) { 48 | if(!file_exists($filename)) { 49 | throw new Exception('File \''.htmlentities($filename).'\' not found.'); 50 | } 51 | return simplexml_load_file($filename); 52 | } 53 | 54 | public static function load_xml_from_url($url) { 55 | //return simplexml_load_file($url); 56 | return simplexml_load_string(get_url($url)); 57 | } 58 | 59 | public static function load_xml($filename, $ref='') { 60 | if(in_array($ref, TilesetBase::$local_refs)) { 61 | return TilesetBase::load_xml_from_file($filename); 62 | //return self::load_xml_from_file($filename); 63 | } 64 | else if(array_key_exists($ref, TilesetBase::$urls)) { 65 | //else if(array_key_exists($ref, self::$urls)) { 66 | return TilesetBase::load_xml_from_url(TilesetBase::$urls[$ref].$filename); 67 | //var_dump(self::$urls[$ref].$filename); 68 | //return self::load_xml_from_url(self::$urls[$ref].$filename); 69 | } 70 | else { 71 | throw new Exception('Incorrect Tileset ref.'); 72 | } 73 | } 74 | 75 | //methods 76 | public function setMap(Map $map) { 77 | $this->map=$map; 78 | } 79 | public function getMap() { 80 | return $this->map; 81 | } 82 | 83 | public function load_from_tsx($filename, $ref='') { 84 | $this->ref=$ref; 85 | $this->filename=$filename; 86 | //$xml=Tileset::load_xml($filename, $ref); 87 | $xml=self::load_xml($filename, $ref); 88 | if($xml===false) { 89 | if($ref==='') { 90 | throw new Exception('File \''.$filename.'\' not found.'); 91 | } 92 | else { 93 | throw new Exception('File \''.$filename.'\' not found or inaccessible with ref \''.$ref.'\'.'); 94 | } 95 | } 96 | return $this->load_from_element($xml); 97 | } 98 | 99 | public function load_from_element(SimpleXMLElement $xml, $ref='', $recur=true) { 100 | $this->ref=$ref; 101 | if((bool)$xml['source']!=FALSE) { 102 | $this->sourceTSX=(string)$xml['source']; 103 | $this->firstgid=(int)$xml['firstgid']; 104 | if($recur) { 105 | $this->load_from_tsx(dirname($this->map->filename).'/'.$this->sourceTSX, $ref); 106 | } 107 | return; 108 | } 109 | if(isset($xml['firstgid'])) $this->firstgid=(int)$xml['firstgid']; 110 | if((bool)$xml['firstgid']!=FALSE) $this->firstgid=(int)$xml['firstgid']; 111 | $this->name=(string)$xml['name']; 112 | $this->tilewidth =(int)$xml['tilewidth' ]; 113 | $this->tileheight=(int)$xml['tileheight']; 114 | $this->tileoffsetx=(int)$xml->tileoffset['x']; 115 | $this->tileoffsety=(int)$xml->tileoffset['y']; 116 | $this->margin =(int)$xml['margin']; 117 | $this->spacing=(int)$xml['spacing']; 118 | $this->source=(string)$xml->image['source'];// 119 | $this->trans=(string)$xml->image['trans']; 120 | $this->width =(int)$xml->image['width' ]; 121 | $this->height=(int)$xml->image['height']; 122 | if( ($this->width ==0 || $this->height==0) && $recur ) { 123 | if($this->ref=='') { 124 | if(file_exists(dirname($this->filename).'/'.$this->source)) { 125 | $ar=getimagesize(dirname($this->filename).'/'.$this->source); 126 | $this->width =$ar[0]; 127 | $this->height=$ar[1]; 128 | unset($ar); 129 | } 130 | else { 131 | trigger_error('Image \''.$this->source.'\' not found', E_USER_NOTICE); 132 | } 133 | } 134 | else { 135 | $ar=getimagesize(TilesetBase::$urls[$ref].dirname($this->map->filename).'/'.dirname($this->filename).'/'.$this->source); 136 | $this->width =$ar[0]; 137 | $this->height=$ar[1]; 138 | unset($ar); 139 | } 140 | } 141 | $j=0; 142 | if((bool)$xml->terraintypes!=FALSE) { 143 | foreach($xml->terraintypes->terrain as $terrain) { 144 | $this->terrains[$j]=array(); 145 | $this->terrains[$j]['name']=(string)$terrain['name']; 146 | $this->terrains[$j]['tile']=(int)$terrain['tile']; 147 | $this->terrains[$j]['distances']=(string)$terrain['distances']; 148 | ++$j; 149 | } 150 | } 151 | unset($j); 152 | if((bool)$xml->tile!=FALSE) { 153 | $this->tiles=array(); 154 | foreach($xml->tile as $tile) { 155 | assert(isset($tile['id'])); 156 | $this->tiles[(string)$tile['id']]=array(); 157 | if((bool)$tile->image!=false) { 158 | if(isset($tile->image['format'])) { 159 | $this->tiles[(string)$tile['id']]['imageformat']=(string)$tile->image['format']; 160 | } 161 | if((bool)$tile->image->data!=false && isset($tile->image->data['encoding'])) { 162 | $this->tiles[(string)$tile['id']]['imageencoding']=(string)$tile->image->data['encoding']; 163 | } 164 | if((bool)$tile->image->data!=false && isset($tile->image->data['compression'])) { 165 | $this->tiles[(string)$tile['id']]['imagecompression']=(string)$tile->image->data['compression']; 166 | } 167 | if((bool)$tile->image->data!=false && isset($tile->image->data[0])) { 168 | $this->tiles[(string)$tile['id']]['imagecontent']=trim((string)$tile->image->data[0]); 169 | } 170 | if(strlen($this->tiles[(string)$tile['id']]['imagecontent'])>0) { 171 | if( strlen($this->tiles[(string)$tile['id']]['imageencoding'])>0 && strlen($this->tiles[(string)$tile['id']]['imagecompression'])>0 ) { 172 | $this->tiles[(string)$tile['id']]['imagecontent']=parse_data($this->tiles[(string)$tile['id']]['imagecontent'], $this->tiles[(string)$tile['id']]['imageencoding'], $this->tiles[(string)$tile['id']]['imagecompression']); 173 | } 174 | } 175 | if(isset($tile->image['source'])) { 176 | $this->tiles[(string)$tile['id']]['imagesource']=(string)$tile->image['source']; 177 | } 178 | } 179 | //var_dump((string)$tile['id']);//die(); 180 | //var_dump((string)$tile['terrain']);die(); 181 | if(isset($tile['terrain'])) { 182 | $this->tiles[(string)$tile['id']]['terrain']=(string)$tile['terrain']; 183 | } 184 | if(isset($tile['probability'])) { 185 | $this->tiles[(string)$tile['id']]['probability']=(double)$tile['probability']; 186 | } 187 | /*if(count($this->tiles[(string)$tile['id']])==0) { 188 | unset($this->tiles[(string)$tile['id']]); 189 | }//*/ 190 | } 191 | } 192 | if((bool)$xml->properties!==false) { 193 | $this->loadProperties_from_element($xml->properties, $ref); 194 | } 195 | if((bool)$xml->tile!==false) { 196 | $this->loadIdProperties_from_element($xml->xpath('tile'), $ref); 197 | } 198 | return $xml; 199 | } 200 | 201 | public function get_tile_from_terrain($id) { 202 | if(is_int($id)) { 203 | return $this->terrains[$id]['tile']; 204 | } 205 | else if(is_string($id)) { 206 | foreach($this->terrains as $terrain) { 207 | if($terrain['name']===$id) return $terrain['tile']; 208 | } 209 | throw new Exception('terrain not found'); 210 | } 211 | else { 212 | throw new Exception('bad terrain identifiant.'); 213 | } 214 | } 215 | 216 | public function get_tile_from_terrains($tl, $tr, $bl, $br) { 217 | $value=$tl.','.$tr.','.$bl.','.$br; 218 | foreach($this->tiles as $id=>$tile) { 219 | if($tile['terrain']===$value) return $id; 220 | } 221 | throw new Exception('terrain tile not found'); 222 | } 223 | 224 | public function isValid() { 225 | if(!is_string($this->sourceTSX)) { 226 | throw new Exception('Incorrect tileset source.'); 227 | return false; 228 | } 229 | if(!is_int($this->firstgid ) || $this->firstgid<1) { 230 | throw new Exception('Incorrect tileset firstgid.'); 231 | return false; 232 | } 233 | if(!is_string($this->name)) { 234 | throw new Exception('Incorrect tileset name.'); 235 | return false; 236 | } 237 | if(!is_int($this->tilewidth ) || $this->tilewidth <0) { 238 | throw new Exception('Incorrect tileset width .'); 239 | return false; 240 | } 241 | if(!is_int($this->tileheight) || $this->tileheight<0) { 242 | throw new Exception('Incorrect tileset height.'); 243 | return false; 244 | } 245 | if(!is_int($this->tileoffsetx )) { 246 | throw new Exception('Incorrect tileset tileoffsetx.'); 247 | return false; 248 | } 249 | if(!is_int($this->tileoffsety )) { 250 | throw new Exception('Incorrect tileset tileoffsety .'); 251 | return false; 252 | } 253 | if(!is_int($this->margin) || $this->margin<0) { 254 | throw new Exception('Incorrect tileset margin.'); 255 | return false; 256 | } 257 | if(!is_int($this->spacing) || $this->spacing<0) { 258 | throw new Exception('Incorrect tileset spacing.'); 259 | return false; 260 | } 261 | if(!is_string($this->source)) { 262 | throw new Exception('Incorrect tileset source.'); 263 | return false; 264 | } 265 | if(!is_string($this->trans) || strlen($this->trans)!=6 || strcspn($this->trans, '0123456789abcdefABCDEF')!=0 ) { 266 | throw new Exception('Incorrect tileset trans.'); 267 | return false; 268 | } 269 | if(!is_int($this->width ) || $this->width <0) { 270 | throw new Exception('Incorrect tileset width .'); 271 | return false; 272 | } 273 | if(!is_int($this->height) || $this->height<0) { 274 | throw new Exception('Incorrect tileset height.'); 275 | return false; 276 | } 277 | if(!is_array($this->terrains)) { 278 | throw new Exception('Incorrect tileset terrains.'); 279 | return false; 280 | } 281 | if(!is_array($this->tiles)) { 282 | throw new Exception('Incorrect tileset tiles.'); 283 | return false; 284 | } 285 | return true; 286 | } 287 | }; 288 | 289 | ?> 290 | -------------------------------------------------------------------------------- /tmw.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /viewer.php: -------------------------------------------------------------------------------- 1 | 'https://raw.github.com/themanaworld/tmwa-client-data/master/', 26 | 'evol'=>'https://raw.github.com/EvolOnline/clientdata-beta/master/', 27 | 'tales'=>'https://raw.github.com/tales/sourceoftales/master/', 28 | 'elmlor'=>'https://github.com/KaneHart/Elmlor-Client-Data/raw/master/', 29 | 'lof'=>'https://github.com/landoffire/lof-tmwa-client-data/raw/master/', 30 | 'lof-newworld'=>'https://github.com/landoffire/lof-newworld/raw/master/', 31 | 'stendhal'=>'http://arianne.cvs.sourceforge.net/viewvc/arianne/stendhal/tiled/', 32 | ); 33 | //constructors 34 | 35 | //methods 36 | public function setMap(Map $map) { 37 | $this->map=$map; 38 | } 39 | public function getMap() { 40 | return $this->map; 41 | } 42 | 43 | public function load_ts() { 44 | $this->ts_imgs=array(); 45 | foreach($this->map->tilesets as $i=>$ts) { 46 | if( strlen($ts->source)==0 ) { 47 | $this->ts_imgs[$i]=array(); 48 | foreach($ts->tiles as $id => $ar) { 49 | if(is_int($id)) { 50 | if(array_key_exists('imagecontent', $ar)) { 51 | $this->ts_imgs[$i][$id]=imagecreatefromstring($ar['imagecontent']); 52 | } 53 | else if(array_key_exists('imagesource', $ar)) { 54 | $this->ts_imgs[$i][$id]=create_image_from(dirname($this->map->filename).'/'.$ar['imagesource']); 55 | } 56 | else { 57 | throw new Exception('Other format of multiple image tileset not implemented yet.'); 58 | } 59 | } 60 | } 61 | //rest is... different or egal 62 | throw new Exception('Miss transparency / antialias / alphablending on multiple image tilesets.'); 63 | return; 64 | } 65 | else if( $this->map->ref != '' ) { 66 | if(array_key_exists($this->map->ref, Viewer::$urls)) { 67 | $url=Viewer::$urls[$this->map->ref].dirname($this->map->filename).'/'; 68 | if(strlen($ts->sourceTSX)>0) $url.=dirname($ts->sourceTSX).'/'; 69 | $url.=$ts->source; 70 | //$this->ts_imgs[$i]=create_image_from($url); 71 | $this->ts_imgs[$i]=imagecreatefromstring(get_url($url)); 72 | } 73 | else { 74 | $this->ts_imgs[$i]=create_image_from(dirname($this->map->filename).'/'.dirname($ts->sourceTSX).'/'.$ts->source); 75 | } 76 | } 77 | else { 78 | $this->ts_imgs[$i]=create_image_from(dirname($this->map->filename).'/'.dirname($ts->sourceTSX).'/'.$ts->source); 79 | } 80 | if(function_exists('imageantialias')) { 81 | imageantialias($this->ts_imgs[$i], false); 82 | } 83 | //imagealphablending($this->ts_imgs[$i], true); 84 | imagealphablending($this->ts_imgs[$i], false); 85 | $transc=$ts->trans; 86 | $trans = imagecolorallocatealpha($this->ts_imgs[$i], 255, 255, 255, 127);//transparent 87 | //$trans = imagecolorallocatealpha($this->ts_imgs[$i], 255, 255, 255, 0);//opaque 88 | if((bool)$transc && $transc!='') { 89 | $r=hexdec(substr($transc,0,2)); 90 | $g=hexdec(substr($transc,2,2)); 91 | $b=hexdec(substr($transc,4,2)); 92 | $color = imagecolorallocatealpha($this->ts_imgs[$i], $r, $g, $b, 0);//opaque 93 | //var_dump(imagesx($this->ts_imgs[$i]), imagesy($this->ts_imgs[$i]));die(); 94 | my_transparent($this->ts_imgs[$i], $r, $g, $b, $trans); 95 | imagecolortransparent($this->ts_imgs[$i], $color); 96 | } 97 | //$this->ts_largeur[$i]=$ly->width; 98 | $tsw=imagesx($this->ts_imgs[$i]); 99 | $tsh=imagesy($this->ts_imgs[$i]); 100 | $this->ts_largeur[$i]=0; 101 | //for( $a=0; $a<$this->map->tilesets[$i]->width-$this->map->tilesets[$i]->margin; $a+=$this->map->tilesets[$i]->tilewidth ) { 102 | for( $a=0; $a<$tsw-$this->map->tilesets[$i]->margin; $a+=$this->map->tilesets[$i]->tilewidth ) { 103 | ++$this->ts_largeur[$i]; 104 | if($this->map->tilesets[$i]->spacing>0) $a+=$this->map->tilesets[$i]->spacing; 105 | } 106 | //var_dump($this->ts_largeur[$i]); 107 | assert($this->ts_largeur[$i]>0) or trigger_error('ts_largeur == 0', E_USER_ERROR); 108 | } 109 | unset($i,$ts,$transc,$trans,$r,$g,$b,$color); 110 | } 111 | 112 | private function load_colors() { 113 | /* 114 | imagecolorallocatealpha 115 | 0 opaque 116 | 127 transparent 117 | 118 | imagecopymerge 119 | 0 nothing 120 | 100 copy 121 | 122 | imagecolortransparent 123 | 0 blanc 124 | 127 gris 125 | 255 noir 126 | */ 127 | //$this->colors['white']=imagecolorallocatealpha($this->img, 255, 255, 255, 0);//blanc 128 | $this->colors['trans']=imagecolorallocatealpha($this->img, 255, 255, 255, 127);//transparent 129 | $this->colors['default']=imagecolorallocatealpha($this->img, 0, 0, 0, 0);//noir 130 | $this->colors['ligra']=imagecolorallocatealpha($this->img, 0xcc, 0xcc, 0xcc, 0);//light gray 131 | $this->colors['red']=imagecolorallocatealpha($this->img, 255, 0, 0, 0);//rouge 132 | $this->colors['green']=imagecolorallocatealpha($this->img, 0, 255, 0, 0);//vert 133 | $this->colors['blue']=imagecolorallocatealpha($this->img, 0, 0, 255, 0);//bleu 134 | $this->colors['yellow']=imagecolorallocatealpha($this->img, 255, 255, 0, 0);//yellow 135 | $this->colors['rose']=imagecolorallocatealpha($this->img, 255, 0, 255, 0);//rose 136 | $this->colors['cyan']=imagecolorallocatealpha($this->img, 0, 255, 255, 0);//cyan 137 | $this->colors['orange']=imagecolorallocatealpha($this->img, 255, 128, 0, 0);//orange 138 | $this->colors['magenta']=imagecolorallocatealpha($this->img, 255, 0, 128, 0);//magenta 139 | $this->colors['ligre']=imagecolorallocatealpha($this->img, 128, 255, 0, 0);//light green 140 | $this->colors['purple']=imagecolorallocatealpha($this->img, 128, 0, 255, 0);//purple 141 | $this->colors['licya']=imagecolorallocatealpha($this->img, 0, 255, 128, 0);//light cyan 142 | $this->colors['violet']=imagecolorallocatealpha($this->img, 0, 128, 255, 0);//violet 143 | } 144 | 145 | public function init_draw($x=0, $y=0, $w=PHP_INT_MAX, $h=PHP_INT_MAX) { 146 | $_w=$this->map->width *$this->map->tilewidth ; 147 | $_h=$this->map->height*$this->map->tileheight; 148 | $_w=min($_w+$this->ox, $w*$this->map->tilewidth ); 149 | $_h=min($_h+$this->oy, $h*$this->map->tileheight); 150 | if($this->map->orientation=='isometric') { 151 | $_h+=$this->map->tileheight/2; 152 | } 153 | $_w*=$this->zoom; 154 | $_h*=$this->zoom; 155 | $this->img=imagecreatetruecolor($_w, $_h); 156 | //$img=imagecreatetruecolor($width*$tilewidth/2, $height*$tileheight/2); 157 | 158 | if(function_exists('imageantialias')) { 159 | imageantialias($this->img, false); 160 | } 161 | imagealphablending($this->img, true); 162 | //imagealphablending($this->img, false); 163 | 164 | $this->load_colors(); 165 | 166 | if(strlen($this->map->backgroundcolor)>0) { 167 | $r=hexdec(substr($this->map->backgroundcolor,0,2)); 168 | $g=hexdec(substr($this->map->backgroundcolor,2,2)); 169 | $b=hexdec(substr($this->map->backgroundcolor,4,2)); 170 | $color = imagecolorallocatealpha($this->img, $r, $g, $b, 0);//opaque 171 | imagefill($this->img, 0, 0, $color); 172 | unset($r,$g,$b,$color); 173 | } 174 | else { 175 | imagefill($this->img, 0, 0, $this->colors['trans']); 176 | } 177 | } 178 | 179 | public function draw($x=0, $y=0, $w=PHP_INT_MAX, $h=PHP_INT_MAX) { 180 | return $this->draw_layers($x, $y, $w, $h); 181 | } 182 | 183 | private function draw_tile(&$ly, $cgid, $i=NULL, $j=NULL, &$o=NULL) { 184 | if($cgid==0) return; 185 | $ti=$this->map->get_tileset_index($cgid); 186 | if($ti==-1) { 187 | var_dump($j,$i,$cgid); 188 | trigger_error('incorrect gid.', E_USER_ERROR); 189 | //die(); 190 | } 191 | if(!is_object($o)) { 192 | if(strlen($this->map->tilesets[$ti]->name)>0&&in_array($this->map->tilesets[$ti]->name, $_SESSION['tilesets_nodraw'])) return; 193 | } 194 | $lid=$cgid-$this->map->tilesets[$ti]->firstgid; 195 | $multiple=false; 196 | //var_dump($lid);print('
'."\n");return; 197 | $tx=$lid%($this->ts_largeur[$ti]); 198 | $tx2=0; 199 | if($this->map->tilesets[$ti]->spacing>0) $tx2+=$this->map->tilesets[$ti]->spacing*$tx; 200 | if($this->map->tilesets[$ti]->margin>0) $tx2+=$this->map->tilesets[$ti]->margin; 201 | $ty=(int)($lid/$this->ts_largeur[$ti]); 202 | $ty2=0; 203 | if($this->map->tilesets[$ti]->spacing>0) $ty2+=$this->map->tilesets[$ti]->spacing*$ty; 204 | if($this->map->tilesets[$ti]->margin>0) $ty2+=$this->map->tilesets[$ti]->margin; 205 | //var_dump($tx,$tx2,$ty,$ty2);die(); 206 | $tsimg=$this->ts_imgs[$ti]; 207 | if(is_array($tsimg)) { 208 | $tsimg=$tsimg[$lid]; 209 | $multiple=true; 210 | $tsw=imagesx($tsimg); 211 | $tsh=imagesy($tsimg); 212 | } 213 | else { 214 | $tsw=$this->map->tilesets[$ti]->tilewidth ; 215 | $tsh=$this->map->tilesets[$ti]->tileheight; 216 | if($ty>$this->map->tilesets[$ti]->height) { 217 | var_dump($j,$i,$cgid,$lid,$tx,$ty,$this->map->tilesets[$ti]->height); 218 | trigger_error('incorrect tile position.', E_USER_ERROR); 219 | } 220 | } 221 | 222 | if($this->map->orientation=='orthogonal') { 223 | if(is_object($o)) { 224 | $dx=$o->x; 225 | $dy2=$o->y-$tsh; 226 | } 227 | else { 228 | $dx=$i*$this->map->tilewidth; 229 | $dy2=($j+1)*$this->map->tileheight-$tsh; 230 | } 231 | $dy=max($dy2, 0); 232 | if(!$multiple) { 233 | $sx=$tx2+$tx*$tsw; 234 | $sy=$ty2+$ty*$tsh; 235 | $sw=$tsw; 236 | $sh=$tsh; 237 | if($sx>imagesx($tsimg)) { 238 | var_dump($j, $i, $cgid, $ti, $lid); 239 | trigger_error('width exceeded.', E_USER_ERROR); 240 | //die(); 241 | } 242 | if($sy>imagesy($tsimg)) { 243 | var_dump($j, $i, $cgid, $ti, $lid); 244 | trigger_error('height exceeded.', E_USER_ERROR); 245 | //die(); 246 | } 247 | if($dy2 < 0) { 248 | $sy+=abs($dy2); 249 | $sh-=abs($dy2); 250 | } 251 | } 252 | else { 253 | $sx=0; 254 | $sy=0; 255 | $sw=imagesx($tsimg); 256 | $sh=imagesy($tsimg); 257 | } 258 | if($this->zoom==1) { 259 | image_copy_and_resize($this->img, $tsimg, $this->ox+$dx, $this->oy+$dy, $sx, $sy, $sw, $sh); 260 | } 261 | else { 262 | image_copy_and_resize($this->img, $tsimg, $this->ox+$dx*$this->zoom, $this->oy+$dy*$this->zoom, $sx, $sy, $sw*$this->zoom, $sh*$this->zoom, $sw, $sh); 263 | } 264 | if(!is_object($o)) $this->draw_inside_tilelayer($ly, $j, $i); 265 | } 266 | elseif($this->map->orientation=='isometric') { 267 | if(is_object($o)) { 268 | trigger_error('not yet implemented', E_USER_ERROR); 269 | } 270 | else { 271 | $dx=(($this->map->width-1+$i-$j)*$this->map->tilewidth/2); 272 | $dy2=($i+$j+1)*$this->map->tileheight/2-$tsh/2; 273 | } 274 | $dy=max($dy2, 0); 275 | if(!$multiple) { 276 | $sx=$tx2+$tx*$tsw; 277 | $sy=$ty2+$ty*$tsh; 278 | $sw=$tsw; 279 | $sh=$tsh; 280 | if($sx+$sw>imagesx($this->ts_imgs[$ti])) { 281 | var_dump($cgid, $ti, $lid); 282 | trigger_error('width exceeded.', E_USER_ERROR); 283 | } 284 | if($sy+$sh>imagesy($this->ts_imgs[$ti])) { 285 | var_dump($cgid, $ti, $lid); 286 | trigger_error('height exceeded.', E_USER_ERROR); 287 | } 288 | } 289 | else { 290 | $sx=0; 291 | $sy=0; 292 | $sw=imagesx($tsimg); 293 | $sh=imagesy($tsimg); 294 | } 295 | if($dy2 < 0) { 296 | //var_dump($dx, $dy2, $sx, $sy, $sw, $sh);echo '
'."\r\n"; 297 | $sy+=abs($dy2); 298 | $sh-=abs($dy2); 299 | //var_dump($dx, $dy, $sx, $sy, $sw, $sh);echo '
'."\r\n"; 300 | //die(); 301 | } 302 | if($this->zoom==1) { 303 | image_copy_and_resize($this->img, $tsimg, $this->ox+$dx, $this->oy+$dy, $sx, $sy, $sw, $sh); 304 | } 305 | else { 306 | image_copy_and_resize($this->img, $tsimg, $this->ox+$dx*$this->zoom, $this->oy+$dy*$this->zoom, $sx, $sy, $sw*$this->zoom, $sh*$this->zoom, $sw, $sh); 307 | } 308 | if(!is_object($o)) $this->draw_inside_tilelayer($ly, $j, $i); 309 | //if($lid==1) break(3); 310 | } 311 | //trigger_error('not yet implemented', E_USER_ERROR); 312 | } 313 | 314 | public function draw_inside_tilelayer(Layer $ly, $j, $i) { 315 | /* 316 | ly layer 317 | j row 318 | i col 319 | */ 320 | if($this->map->orientation=='orthogonal') { 321 | // 322 | } 323 | elseif($this->map->orientation=='isometric') { 324 | // 325 | } 326 | return false; 327 | } 328 | 329 | public function draw_tilelayer($tl, $x=0, $y=0, $w=PHP_INT_MAX, $h=PHP_INT_MAX) { 330 | if(!$this->draw_tiles) return; 331 | if(strlen($tl->name)>0&&in_array($tl->name, $_SESSION['layers_nodraw'])) return; 332 | $jmax=min($tl->height,max($y+$h,PHP_INT_MAX)); 333 | $imax=min($tl->width ,max($x+$w,PHP_INT_MAX)); 334 | for($j=$y;$j<$jmax;++$j) { 335 | for($i=$x;$i<$imax;++$i) { 336 | $index=$j*$tl->width+$i; 337 | if($index>=$tl->get_tile_number()) { 338 | var_dump($j,$jmax,$i,$imax,$index); 339 | trigger_error('incorrect index or layer data.', E_USER_ERROR); 340 | } 341 | $cgid=$tl->get_tile($index); 342 | //var_dump($cgid);die(); 343 | if( ($cgid&0xE0000000) != 0 ) {//NOTE: for now, ignore horizontal/vertical/diagonal flipping 344 | //var_dump($cgid); 345 | $cgid&=0x1FFFFFFF; 346 | //var_dump($cgid);die(); 347 | } 348 | $this->draw_tile($tl, $cgid, $i, $j); 349 | } 350 | } 351 | } 352 | 353 | public function draw_objectlayer($ol, $x=0, $y=0, $w=PHP_INT_MAX, $h=PHP_INT_MAX) { 354 | if($this->draw_objects) { 355 | foreach($ol->getAllObjects() as $o) { 356 | if($o->polygon || $o->polyline) { 357 | if($o->x+$o->getWidthR() <=$x*$this->map->tilewidth ) continue; 358 | if($o->y+$o->getHeightB()<=$y*$this->map->tileheight) continue; 359 | if($o->x-$o->getWidthL() >=($x+$w)*$this->map->tilewidth ) continue; 360 | if($o->y-$o->getHeightT()>=($y+$h)*$this->map->tileheight) continue; 361 | imagerectangle($this->img, $this->ox+($o->x-$o->getWidthL())*$this->zoom, $this->oy+($o->y-$o->getHeightT())*$this->zoom, 362 | $this->ox+($o->x + $o->getWidthR())*$this->zoom, $this->oy+($o->y + $o->getHeightB())*$this->zoom, 363 | $this->colors['ligra']); 364 | if($o->polyline) { 365 | assert(count($o->points)/2>1); 366 | $_x=($o->x+$o->points[0])*$this->zoom; 367 | $_y=($o->y+$o->points[1])*$this->zoom; 368 | imagesetthickness($this->img, 2); 369 | for($i=2;$ipoints);$i+=2) { 370 | imageline($this->img, $this->ox+$_x, $this->oy+$_y, $this->ox+($o->x+$o->points[$i])*$this->zoom, $this->oy+($o->y+$o->points[$i+1])*$this->zoom, $this->colors['green']); 371 | $_x=($o->x+$o->points[$i])*$this->zoom; 372 | $_y=($o->y+$o->points[$i+1])*$this->zoom; 373 | } 374 | imagesetthickness($this->img, 1); 375 | } 376 | else if($o->polygon) { 377 | $ar=$o->points; 378 | for($i=0;$izoom; 380 | $ar[$i]+=$o->x*$this->zoom; 381 | $ar[$i+1]*=$this->zoom; 382 | $ar[$i+1]+=$o->y*$this->zoom; 383 | $ar[$i]+=$this->ox; 384 | $ar[$i+1]+=$this->oy; 385 | } 386 | imagesetthickness($this->img, 2); 387 | if(PHP_VERSION_ID<80000) imagepolygon($this->img, $ar, count($ar)/2, $this->colors['green']); 388 | else imagepolygon($this->img, $ar, $this->colors['green']); 389 | imagesetthickness($this->img, 1); 390 | } 391 | else if($o->name!='') { 392 | imagettftext($this->img, 10*$this->zoom, 0, $this->ox+($o->x-$o->getWidthL())*$this->zoom, $this->oy+($o->y-$o->getHeightT()-4)*$this->zoom, $this->colors['blue'], './courbd.ttf', $o->name); 393 | //imagestring($this->img, 3, $this->ox+($o->x-$o->getWidthL())*$this->zoom, $this->oy+($o->y-$o->getHeightT()-16)*$this->zoom, $o->name, $this->colors['blue']); 394 | } 395 | } 396 | elseif($o->ellipse) { 397 | if($o->x+$o->width <=$x*$this->map->tilewidth ) continue; 398 | if($o->y+$o->height<=$y*$this->map->tileheight) continue; 399 | if($o->x>=($x+$w)*$this->map->tilewidth ) continue; 400 | if($o->y>=($y+$h)*$this->map->tileheight) continue; 401 | imagesetthickness($this->img, 2); 402 | //imageellipse($this->img, $this->ox+$o->x+$o->width/2, $this->oy+$o->y+$o->height/2, $o->width, $o->height, $this->colors['purple']);//NOTE: doesn't work with setthickness, known bug ( 403 | imagearc($this->img, $this->ox+$o->x+$o->width/2, $this->oy+$o->y+$o->height/2, $o->width, $o->height, 0, 180, $this->colors['purple']); 404 | imagearc($this->img, $this->ox+$o->x+$o->width/2, $this->oy+$o->y+$o->height/2, $o->width, $o->height, 180, 360, $this->colors['purple']); 405 | imagesetthickness($this->img, 1); 406 | } 407 | elseif(is_int($o->gid)) { 408 | $cgid=$o->gid; 409 | $ti=$this->map->get_tileset_index($cgid); 410 | $lid=$cgid-$this->map->tilesets[$ti]->firstgid; 411 | //var_dump($o);die(); 412 | //var_dump($o->x);die(); 413 | if($o->x+$this->map->tilesets[$ti]->tilewidth <=$x*$this->map->tilewidth ) continue; 414 | if($o->y+$this->map->tilesets[$ti]->tileheight<=$y*$this->map->tileheight) continue; 415 | if($o->x>=($x+$w)*$this->map->tilewidth ) continue; 416 | if($o->y>=($y+$h)*$this->map->tileheight) continue; 417 | $this->draw_tile($ol, $cgid, NULL, NULL, $o); 418 | } 419 | else { 420 | if($o->x+$o->width <=$x*$this->map->tilewidth ) continue; 421 | if($o->y+$o->height<=$y*$this->map->tileheight) continue; 422 | if($o->x>=($x+$w)*$this->map->tilewidth ) continue; 423 | if($o->y>=($y+$h)*$this->map->tileheight) continue; 424 | imagesetthickness($this->img, 2); 425 | imagerectangle($this->img, $this->ox+$o->x*$this->zoom, $this->oy+$o->y*$this->zoom, $this->ox+($o->x + $o->width)*$this->zoom, $this->oy+($o->y + $o->height)*$this->zoom, $this->colors['green']); 426 | imagesetthickness($this->img, 1); 427 | if($o->name!='') { 428 | imagettftext($this->img, 10*$this->zoom, 0, $this->ox+$o->x*$this->zoom, $this->oy+($o->y-4)*$this->zoom, $this->colors['blue'], dirname(__FILE__).'/courbd.ttf', $o->name); 429 | //imagestring($this->img, 3, $this->ox+$o->x*$this->zoom, $this->oy+($o->y-16)*$this->zoom, $o->name, $this->colors['blue']); 430 | } 431 | } 432 | } 433 | } 434 | } 435 | 436 | public function draw_layers($x=0, $y=0, $w=PHP_INT_MAX, $h=PHP_INT_MAX) { 437 | //ob_start(); 438 | 439 | assert(count($this->ts_imgs)==count($this->map->tilesets)) or die('tilesets not loaded.'); 440 | 441 | foreach($this->map->layers as $index=>$ly) { 442 | //var_dump($index, $ly);die(); 443 | if($ly instanceof TileLayer) { 444 | if($this->draw_tiles) { 445 | //break; 446 | $this->draw_tilelayer($ly, $x, $y, $w, $h); 447 | } 448 | } 449 | elseif($ly instanceof ObjectLayer) { 450 | if($this->draw_objects) { 451 | //die(); 452 | $ol=$ly; 453 | $this->draw_objectlayer($ly, $x, $y, $w, $h); 454 | } 455 | } 456 | elseif($ly instanceof ImageLayer) { 457 | if($this->draw_images) { 458 | $il=$ly; 459 | $img_=create_image_from(dirname($this->map->filename).'/'.$il->source); 460 | if($il->x+imagesx($img_)<=$x*$this->map->tilewidth ) continue; 461 | if($il->y+imagesy($img_)<=$y*$this->map->tilewidth ) continue; 462 | if($il->x>=($x+$w)*$this->map->tilewidth ) continue; 463 | if($il->y>=($y+$h)*$this->map->tileheight) continue; 464 | if(function_exists('imageantialias')) { 465 | imageantialias($img_, false); 466 | } 467 | //imagealphablending($img_, true); 468 | imagealphablending($img_, false); 469 | $transc=$il->trans; 470 | $trans = imagecolorallocatealpha($img_, 255, 255, 255, 127);//transparent 471 | //$trans = imagecolorallocatealpha($img_, 255, 255, 255, 0);//opaque 472 | if((bool)$transc && $transc!='') { 473 | $r=hexdec(substr($transc,0,2)); 474 | $g=hexdec(substr($transc,2,2)); 475 | $b=hexdec(substr($transc,4,2)); 476 | //var_dump($transc, $r, $g, $b); 477 | $color = imagecolorallocatealpha($img_, $r, $g, $b, 0);//opaque 478 | //var_dump(imagesx($img_), imagesy($this->ts_imgs[$i]));die(); 479 | my_transparent($img_, $r, $g, $b, $trans); 480 | imagecolortransparent($img_, $color); 481 | } 482 | if($this->map->orientation=='orthogonal') { 483 | $sw=min($il->width *$this->map->tilewidth , $this->map->width *$this->map->tilewidth , imagesx($img_)); 484 | $sh=min($il->height*$this->map->tileheight, $this->map->height*$this->map->tileheight, imagesy($img_)); 485 | if($this->zoom==1) { 486 | image_copy_and_resize($this->img, $img_, $this->ox+$il->x, $this->oy+$il->y, 0, 0, $sw, $sh); 487 | } 488 | else { 489 | image_copy_and_resize($this->img, $img_, $this->ox+$il->x*$this->zoom, $this->oy+$il->y*$this->zoom, 0, 0, $sw*$this->zoom, $sh*$this->zoom, $sw, $sh); 490 | } 491 | } 492 | elseif($this->map->orientation=='isometric') { 493 | throw new Exception('image layer on isometric map not yet implemented.'); 494 | } 495 | imagedestroy($img_); 496 | unset($img_); 497 | $img_=NULL; 498 | } 499 | } 500 | unset($tl, $ol, $il); 501 | } 502 | } 503 | 504 | public function render($file=NULL) { 505 | imagesavealpha($this->img, true); 506 | 507 | //ini_set('output_buffering','off'); 508 | 509 | //imagejpeg($this->img, $file, 80); 510 | imagepng($this->img, $file, 7); 511 | } 512 | }; 513 | 514 | ?> -------------------------------------------------------------------------------- /viewer_part.php: -------------------------------------------------------------------------------- 1 | '."\r\n"; 71 | $res=$map->load($file, $ref); 72 | 73 | 74 | 75 | /*var_dump($map->getProperties());echo '
'."\r\n"; 76 | var_dump($map->tilesets[0]->getProperties());echo '
'."\r\n"; 77 | var_dump($map->tilesets[0]->getAllProperties());echo '
'."\r\n"; 78 | //var_dump($map->tilesets[0]->getIdProperties(0));echo '
'."\r\n"; 79 | var_dump($map->layers[0]->getProperties());echo '
'."\r\n"; 80 | var_dump($map->objectlayers[0]->getProperties());echo '
'."\r\n"; 81 | var_dump($map->objectlayers[0]->getObjectCount());echo '
'."\r\n"; 82 | echo '
'."\r\n"; 83 | var_dump($map->objectlayers[0]->getObject(0));echo '
'."\r\n"; 84 | echo ''."\r\n"; 85 | die();//*/ 86 | 87 | $viewer=new Viewer(); 88 | 89 | if($file=='../maps/isometric.tmx' && array_key_exists('rot', $_REQUEST)) { 90 | assert(in_array($_REQUEST['rot'],array('','0','ccw','90','180','cw','270','360'))) or trigger_error('bad rot value', E_USER_ERROR); 91 | $rot=$_REQUEST['rot']; 92 | require('rot.php'); 93 | foreach($map->layers as $a=>$layer) { 94 | for($i=0;$i<$map->height;++$i) { 95 | for($j=0;$j<$map->width;++$j) { 96 | $tile=$map->layers[$a]->get_tile($i*$map->width+$j); 97 | $lid=$tile-$map->tilesets[$map->get_tileset_index($tile)]->firstgid; 98 | if($rot=='cw' || $rot=='270') { 99 | $lid=rotate90cw_lid($lid); 100 | } 101 | elseif($rot=='ccw' || $rot=='90') { 102 | $lid=rotate90ccw_lid($lid); 103 | } 104 | elseif($rot=='180') { 105 | $lid=rotate180_lid($lid); 106 | } 107 | if($lid==-1) $tile=0; 108 | else $tile=$lid+$map->tilesets[$map->get_tileset_index($tile)]->firstgid; 109 | $map->layers[$a]->set_tile($i*$map->width+$j, $tile); 110 | } 111 | } 112 | if($rot=='cw' || $rot=='270') { 113 | $map->layers[$a]->rot90cw(); 114 | } 115 | elseif($rot=='ccw' || $rot=='90') { 116 | $map->layers[$a]->rot90ccw(); 117 | } 118 | elseif($rot=='180') { 119 | $map->layers[$a]->rot180(); 120 | } 121 | } 122 | } 123 | 124 | $viewer->setMap($map); 125 | 126 | ini_set('output_buffering','off'); 127 | 128 | $data=ob_get_clean(); 129 | if(!empty($data)) { 130 | header('Content-Type: text/plain'."\r\n"); 131 | echo $data; 132 | die(); 133 | } 134 | 135 | ob_start(); 136 | 137 | if(!array_key_exists('layers_nodraw', $_SESSION)) { 138 | $_SESSION['layers_nodraw']=array('collision'); 139 | } 140 | if(!array_key_exists('tilesets_nodraw', $_SESSION)) { 141 | $_SESSION['tilesets_nodraw']=array('collision'); 142 | } 143 | 144 | $viewer->load_ts(); 145 | 146 | $zoom=1; 147 | if(array_key_exists('zoom',$_REQUEST)) { 148 | assert(is_numeric($_REQUEST['zoom'])) or trigger_error('bad zoom value', E_USER_ERROR); 149 | $zoom=floatval($_REQUEST['zoom']); 150 | $viewer->zoom=$zoom; 151 | assert($viewer->zoom>=0.1 && $viewer->zoom<=10) or trigger_error('bad zoom range', E_USER_ERROR); 152 | } 153 | 154 | $x=0; 155 | if(array_key_exists('x',$_REQUEST)) { 156 | assert(is_numeric($_REQUEST['x'])) or trigger_error('bad x value', E_USER_ERROR); 157 | $x=intval($_REQUEST['x']); 158 | } 159 | $y=0; 160 | if(array_key_exists('y',$_REQUEST)) { 161 | assert(is_numeric($_REQUEST['y'])) or trigger_error('bad y value', E_USER_ERROR); 162 | $y=intval($_REQUEST['y']); 163 | } 164 | $w=PHP_INT_MAX; 165 | if(array_key_exists('w',$_REQUEST)) { 166 | assert(is_numeric($_REQUEST['w'])) or trigger_error('bad w value', E_USER_ERROR); 167 | $w=intval($_REQUEST['w']); 168 | } 169 | $h=PHP_INT_MAX; 170 | if(array_key_exists('h',$_REQUEST)) { 171 | assert(is_numeric($_REQUEST['h'])) or trigger_error('bad h value', E_USER_ERROR); 172 | $h=intval($_REQUEST['h']); 173 | } 174 | 175 | $ox=-$x*$map->tilewidth *$zoom; 176 | $oy=-$y*$map->tileheight*$zoom; 177 | 178 | if(array_key_exists('dt',$_REQUEST)) { 179 | $dt=$_REQUEST['dt']; 180 | if(is_null($dt)) $dt=false; 181 | else if( strcasecmp($dt,'true' )==0 || strcasecmp($dt,'yes')==0 || strcasecmp($dt,'on' )==0 || $dt==='1' || $dt===1 ) $dt=true; 182 | else if( strcasecmp($dt,'false')==0 || strcasecmp($dt,'no' )==0 || strcasecmp($dt,'off')==0 || $dt==='0' || $dt===0 ) $dt=false; 183 | else $dt=false; 184 | $viewer->draw_tiles=$dt; 185 | } 186 | if(array_key_exists('do',$_REQUEST)) { 187 | $do=$_REQUEST['do']; 188 | if(is_null($do)) $do=false; 189 | else if( strcasecmp($do,'true' )==0 || strcasecmp($do,'yes')==0 || strcasecmp($do,'on' )==0 || $do==='1' || $do===1 ) $do=true; 190 | else if( strcasecmp($do,'false')==0 || strcasecmp($do,'no' )==0 || strcasecmp($do,'off')==0 || $do==='0' || $do===0 ) $do=false; 191 | else $do=false; 192 | $viewer->draw_objects=$do; 193 | } 194 | if(array_key_exists('di',$_REQUEST)) { 195 | $di=$_REQUEST['di']; 196 | if(is_null($di)) $di=false; 197 | else if( strcasecmp($di,'true' )==0 || strcasecmp($di,'yes')==0 || strcasecmp($di,'on' )==0 || $di==='1' || $di===1 ) $di=true; 198 | else if( strcasecmp($di,'false')==0 || strcasecmp($di,'no' )==0 || strcasecmp($di,'off')==0 || $di==='0' || $di===0 ) $di=false; 199 | else $di=false; 200 | $viewer->draw_images=$di; 201 | } 202 | 203 | $viewer->ox=$ox; 204 | $viewer->oy=$oy; 205 | 206 | //var_dump($x, $y, $w, $h);die(); 207 | 208 | $viewer->init_draw($x, $y, $w, $h); 209 | $viewer->draw($x, $y, $w, $h); 210 | 211 | $data=ob_get_contents(); 212 | if(strlen($data)!=0) { 213 | header('Content-Type: text/plain'."\r\n"); 214 | echo $data; 215 | die(); 216 | } 217 | 218 | $viewer->render(); 219 | 220 | $data=ob_get_clean(); 221 | unset($viewer);$viewer=NULL; 222 | if(!defined('DEBUG')||DEBUG!==true) { 223 | //header('Content-Type: image/jpeg'."\r\n"); 224 | header('Content-Type: image/png'."\r\n"); 225 | } 226 | echo $data; 227 | 228 | ?> -------------------------------------------------------------------------------- /viewer_part_ui.php: -------------------------------------------------------------------------------- 1 | load($file, $ref, $recur); 67 | 68 | //$viewer=new Viewer(); 69 | //$viewer->setMap($map); 70 | 71 | //ini_set('output_buffering','off'); 72 | 73 | $data=ob_get_clean(); 74 | if(!empty($data)) { 75 | header('Content-Type: text/plain'."\r\n"); 76 | echo $data; 77 | //var_dump($data); 78 | die(); 79 | } 80 | 81 | //ob_start(); 82 | 83 | if(!array_key_exists('layers_nodraw', $_SESSION)) { 84 | $_SESSION['layers_nodraw']=array('collision'); 85 | } 86 | if(!array_key_exists('tilesets_nodraw', $_SESSION)) { 87 | $_SESSION['tilesets_nodraw']=array('collision'); 88 | } 89 | 90 | //$viewer->load_ts(); 91 | 92 | $zoom=1; 93 | if(array_key_exists('zoom',$_REQUEST)) { 94 | assert(is_numeric($_REQUEST['zoom'])) or trigger_error('bad zoom value', E_USER_ERROR); 95 | assert($zoom>=0.1 && $zoom<=10) or trigger_error('bad zoom range', E_USER_ERROR); 96 | $zoom=floatval($_REQUEST['zoom']); 97 | //$viewer->zoom=$zoom; 98 | } 99 | 100 | $x=0; 101 | if(array_key_exists('x',$_REQUEST)) { 102 | assert(is_numeric($_REQUEST['x'])) or trigger_error('bad x value', E_USER_ERROR); 103 | $x=intval($_REQUEST['x']); 104 | } 105 | $y=0; 106 | if(array_key_exists('y',$_REQUEST)) { 107 | assert(is_numeric($_REQUEST['y'])) or trigger_error('bad y value', E_USER_ERROR); 108 | $y=intval($_REQUEST['y']); 109 | } 110 | $w=PHP_INT_MAX; 111 | if(array_key_exists('w',$_REQUEST)) { 112 | assert(is_numeric($_REQUEST['w'])) or trigger_error('bad w value', E_USER_ERROR); 113 | $w=intval($_REQUEST['w']); 114 | } 115 | $h=PHP_INT_MAX; 116 | if(array_key_exists('h',$_REQUEST)) { 117 | assert(is_numeric($_REQUEST['h'])) or trigger_error('bad h value', E_USER_ERROR); 118 | $h=intval($_REQUEST['h']); 119 | } 120 | 121 | 122 | $dt=true; 123 | if(array_key_exists('dt',$_REQUEST)) { 124 | $dt=$_REQUEST['dt']; 125 | if(is_null($dt)) $dt=true; 126 | else if( strcasecmp($dt,'true' )==0 || strcasecmp($dt,'yes')==0 || $dt==='1' || $dt===1 ) $dt=true; 127 | else if( strcasecmp($dt,'false')==0 || strcasecmp($dt,'no' )==0 || $dt==='0' || $dt===0 ) $dt=false; 128 | else $dt=false; 129 | //$viewer->draw_tiles=$dt; 130 | } 131 | $do=true; 132 | if(array_key_exists('do',$_REQUEST)) { 133 | $do=$_REQUEST['do']; 134 | if(is_null($do)) $do=true; 135 | else if( strcasecmp($do,'true' )==0 || strcasecmp($do,'yes')==0 || $do==='1' || $do===1 ) $do=true; 136 | else if( strcasecmp($do,'false')==0 || strcasecmp($do,'no' )==0 || $do==='0' || $do===0 ) $do=false; 137 | else $do=false; 138 | //$viewer->draw_objects=$do; 139 | } 140 | $di=true; 141 | if(array_key_exists('di',$_REQUEST)) { 142 | $di=$_REQUEST['di']; 143 | if(is_null($di)) $di=true; 144 | else if( strcasecmp($di,'true' )==0 || strcasecmp($di,'yes')==0 || $di==='1' || $di===1 ) $di=true; 145 | else if( strcasecmp($di,'false')==0 || strcasecmp($di,'no' )==0 || $di==='0' || $di===0 ) $di=false; 146 | else $di=false; 147 | //$viewer->draw_images=$di; 148 | } 149 | if(array_key_exists('rot',$_REQUEST)) { 150 | assert(in_array($_REQUEST['rot'],array('', '0','ccw','90','180','cw','270','360'))) or trigger_error('bad rot value', E_USER_ERROR); 151 | $rot=$_REQUEST['rot']; 152 | } 153 | else $rot='0'; 154 | 155 | $act_count=0; 156 | if(array_key_exists('act_u',$_REQUEST)) { 157 | $vals=array( 158 | '-',//minus 159 | '+',//plus 160 | '↑',//haut 1 161 | '↓',//bas 1 162 | '⇑',//haut 2 163 | '⇓',//bas 2 164 | '↑',//haut 1 165 | '↓',//bas 1 166 | '⇑',//haut 2 167 | '⇓',//bas 2 168 | ); 169 | $act_u=htmlentities($_REQUEST['act_u'], ENT_COMPAT | ENT_HTML401, 'UTF-8'); 170 | if(!in_array($act_u, $vals)) die('incorrect up action'); 171 | switch($act_u) { 172 | case '-'://minus 173 | $h--; 174 | $y++; 175 | break; 176 | case '+'://plus 177 | $h++; 178 | $y--; 179 | break; 180 | case '↑'://haut 1 181 | case '↑'://haut 1 182 | $y--; 183 | break; 184 | case '↓'://bas 1 185 | case '↓'://bas 1 186 | $y++; 187 | break; 188 | case '⇑'://haut 2 189 | case '⇑'://haut 2 190 | $y-=$h; 191 | break; 192 | case '⇓'://bas 2 193 | case '⇓'://bas 2 194 | $y+=$h; 195 | break; 196 | default: 197 | die('incorrect up action'); 198 | break; 199 | } 200 | $act_count++; 201 | } 202 | if(array_key_exists('act_l',$_REQUEST)) { 203 | $vals=array( 204 | '-',//minus 205 | '+',//plus 206 | '←',//left 1 207 | '↔',//right 1 208 | '⇐',//left 2 209 | '⇒',//right 2 210 | '←',//left 1 211 | '→',//right 1 212 | '⇐',//left 2 213 | '⇒',//right 2 214 | ); 215 | $act_l=htmlentities($_REQUEST['act_l'], ENT_COMPAT | ENT_HTML401, 'UTF-8'); 216 | if(!in_array($act_l, $vals)) die('incorrect left action'); 217 | switch($act_l) { 218 | case '-'://minus 219 | $w--; 220 | $x++; 221 | break; 222 | case '+'://plus 223 | $w++; 224 | $x--; 225 | break; 226 | case '←'://left 1 227 | case '←'://left 1 228 | $x--; 229 | break; 230 | case '↔'://right 1 231 | case '→'://right 1 232 | $x++; 233 | break; 234 | case '⇐'://left 2 235 | case '⇐'://left 2 236 | $x-=$w; 237 | break; 238 | case '⇒'://right 2 239 | case '⇒'://right 2 240 | $x+=$w; 241 | break; 242 | default: 243 | die('incorrect left action'); 244 | break; 245 | } 246 | $act_count++; 247 | } 248 | if(array_key_exists('act_r',$_REQUEST)) { 249 | $vals=array( 250 | '-',//minus 251 | '+',//plus 252 | '←',//left 1 253 | '↔',//right 1 254 | '⇐',//left 2 255 | '⇒',//right 2 256 | '←',//left 1 257 | '→',//right 1 258 | '⇐',//left 2 259 | '⇒',//right 2 260 | ); 261 | $act_r=htmlentities($_REQUEST['act_r'], ENT_COMPAT | ENT_HTML401, 'UTF-8'); 262 | if(!in_array($act_r, $vals)) die('incorrect right action'); 263 | switch($act_r) { 264 | case '-'://minus 265 | $w--; 266 | break; 267 | case '+'://plus 268 | $w++; 269 | break; 270 | case '←'://left 1 271 | case '←'://left 1 272 | $x--; 273 | break; 274 | case '↔'://right 1 275 | case '→'://right 1 276 | $x++; 277 | break; 278 | case '⇐'://left 2 279 | case '⇐'://left 2 280 | $x-=$w; 281 | break; 282 | case '⇒'://right 2 283 | case '⇒'://right 2 284 | $x+=$w; 285 | break; 286 | default: 287 | die('incorrect right action'); 288 | break; 289 | } 290 | $act_count++; 291 | } 292 | if(array_key_exists('act_d',$_REQUEST)) { 293 | $vals=array( 294 | '-',//minus 295 | '+',//plus 296 | '↑',//haut 1 297 | '↓',//bas 1 298 | '⇑',//haut 2 299 | '⇓',//bas 2 300 | '↑',//haut 1 301 | '↓',//bas 1 302 | '⇑',//haut 2 303 | '⇓',//bas 2 304 | ); 305 | $act_d=htmlentities($_REQUEST['act_d'], ENT_COMPAT | ENT_HTML401, 'UTF-8'); 306 | if(!in_array($act_d, $vals)) die('incorrect down action'); 307 | switch($act_d) { 308 | case '-'://minus 309 | $h--; 310 | break; 311 | case '+'://plus 312 | $h++; 313 | break; 314 | case '↑'://haut 1 315 | case '↑'://haut 1 316 | $y--; 317 | break; 318 | case '↓'://bas 1 319 | case '↓'://bas 1 320 | $y++; 321 | break; 322 | case '⇑'://haut 2 323 | case '⇑'://haut 2 324 | $y-=$h; 325 | break; 326 | case '⇓'://bas 2 327 | case '⇓'://bas 2 328 | $y+=$h; 329 | break; 330 | default: 331 | die('incorrect down action'); 332 | break; 333 | } 334 | $act_count++; 335 | } 336 | if(array_key_exists('act_rot', $_REQUEST)) { 337 | $vals=array( 338 | '↺',//left rot 339 | '↻',//right rot 340 | '↺',//left rot 341 | '↻',//right rot 342 | "\xe2\x86\xba",//left rot 343 | "\xe2\x86\xbb",//right rot 344 | ); 345 | $act_rot=htmlentities($_REQUEST['act_rot'], ENT_COMPAT | ENT_HTML401, 'UTF-8'); 346 | if(!in_array($act_rot, $vals)) die('incorrect rot action'); 347 | if($rot=='ccw') $rot='90'; 348 | if($rot=='cw') $rot='270'; 349 | settype($rot, 'integer'); 350 | switch($act_rot) { 351 | case '↺': 352 | case '↺': 353 | case "\xe2\x86\xba": 354 | $rot=($rot+90)%360; 355 | break; 356 | case '↻': 357 | case '↻': 358 | case "\xe2\x86\xbb": 359 | $rot=($rot+270)%360; 360 | break; 361 | default: 362 | die('incorrect rot action'); 363 | break; 364 | } 365 | $act_count++; 366 | } 367 | 368 | if($act_count>1) die('incorrect action'); 369 | 370 | //TODO:width/height correction (fit to screen by default) 371 | if($w==PHP_INT_MAX) $w=12; 372 | if($h==PHP_INT_MAX) $h=12; 373 | 374 | if($x<0) $x=0; 375 | if($y<0) $y=0; 376 | if($h<1) $h=1; 377 | if($w<1) $w=1; 378 | 379 | if($w>$map->width ) $w=$map->width ; 380 | if($h>$map->height) $h=$map->height; 381 | 382 | if($x>=$map->width) { 383 | $x=$map->width-$w; 384 | } 385 | if($y>=$map->height) { 386 | $y=$map->height-$h; 387 | } 388 | 389 | if($x>$map->width -$w) $x=$map->width -$w; 390 | if($y>$map->height-$h) $y=$map->height-$h; 391 | 392 | if($w==$map->width &&$x>0) $x=0; 393 | if($h==$map->height&&$y>0) $y=0; 394 | 395 | function show_select($value) { 396 | $vals=array(0=>'Non',1=>'Oui'); 397 | foreach($vals as $k=>$v) { 398 | echo ''."\r\n"; 403 | } 404 | } 405 | 406 | ?> 407 | 408 | 409 | 410 | PHP TMX Map Viewer<?php if(array_key_exists('ref',$_REQUEST)&&$_REQUEST['ref']!='') print(' - '.$_REQUEST['ref']); ?><?php if(array_key_exists('url',$_REQUEST)&&$_REQUEST['url']!='') print(' - '.$_REQUEST['url']); else if(array_key_exists('list',$_REQUEST)&&$_REQUEST['list']!='') print(' - '.$_REQUEST['list']);?> 411 | 447 | 475 | 476 | 477 | 478 |
479 |
480 | 499 | '."\r\n"; 502 | echo ''."\r\n"; 521 | } 522 | else { 523 | if(file_exists($_REQUEST['ref'].'.htm') && (!array_key_exists('force',$_REQUEST) || $_REQUEST['force']!=='1') ) { 524 | echo ''."\r\n"; 525 | echo ''."\r\n"; 543 | } 544 | else { 545 | //echo ''."\r\n"; 546 | } 547 | } 548 | ?> 549 | 550 | 551 |
552 |
553 | '."\r\n"; 555 | if(array_key_exists('ref',$_REQUEST)) echo ''."\r\n"; 556 | if(array_key_exists('list',$_REQUEST)) echo ''."\r\n"; 557 | if(array_key_exists('url',$_REQUEST)) echo ''."\r\n"; 558 | if(!array_key_exists('dt',$_REQUEST)) 559 | $dt_=''; 560 | else 561 | $dt_=' checked="checked"'; 562 | if(!array_key_exists('do',$_REQUEST)) 563 | $do_=''; 564 | else 565 | $do_=' checked="checked"'; 566 | if(!array_key_exists('di',$_REQUEST)) 567 | $di_=''; 568 | else 569 | $di_=' checked="checked"'; 570 | ?>
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 | 580 |
581 |
582 |
583 | 584 | orientation=='isometric') { 586 | echo ' '."\r\n"; 587 | echo ' '."\r\n"; 593 | if($map->orientation=='isometric') { 594 | echo ' '."\r\n"; 595 | } 596 | ?> 597 | 598 | 599 | 639 | 640 | 641 | 642 | orientation=='isometric') { 644 | echo ' '."\r\n"; 645 | echo ' '."\r\n"; 651 | if($map->orientation=='isometric') { 652 | echo ' '."\r\n"; 653 | } 654 | ?> 655 |
'; 588 | } 589 | else { 590 | echo ' '; 591 | } 592 | echo '      




tilewidth,$map->tileheight,$zoom); 625 | if($w!=PHP_INT_MAX && $h!=PHP_INT_MAX) { 626 | $_w=$w*$map->tilewidth *$zoom; 627 | $_h=$h*$map->tileheight*$zoom; 628 | echo ' width="' .$_w.'"'; 629 | echo ' height="'.$_h.'"'; 630 | } 631 | else { 632 | echo ' width="' .($map->width *$map->tilewidth *$zoom).'"'; 633 | echo ' height="'.($map->height*$map->tileheight*$zoom).'"'; 634 | } 635 | } 636 | ?>/>



'; 646 | } 647 | else { 648 | echo ' '; 649 | } 650 | echo '      
656 | 657 | 658 | -------------------------------------------------------------------------------- /viewer_ui.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | (PHP) TMX Viewer [by sebbu] 8 | 9 | 35 | 36 | 95 | 96 |

MAP

97 | 98 |
99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |
140 |
141 | 142 | 143 | -------------------------------------------------------------------------------- /viewer_view.php: -------------------------------------------------------------------------------- 1 | '."\r\n"; 61 | $res=$map->load($file, $ref); 62 | 63 | //print_r($map->layers[0]);die(); 64 | 65 | /*var_dump($map->getProperties());echo '
'."\r\n"; 66 | var_dump($map->tilesets[0]->getProperties());echo '
'."\r\n"; 67 | var_dump($map->tilesets[0]->getAllProperties());echo '
'."\r\n"; 68 | //var_dump($map->tilesets[0]->getIdProperties(0));echo '
'."\r\n"; 69 | var_dump($map->layers[0]->getProperties());echo '
'."\r\n"; 70 | var_dump($map->objectlayers[0]->getProperties());echo '
'."\r\n"; 71 | var_dump($map->objectlayers[0]->getObjectCount());echo '
'."\r\n"; 72 | echo '
'."\r\n"; 73 | var_dump($map->objectlayers[0]->getObject(0));echo '
'."\r\n"; 74 | echo ''."\r\n"; 75 | die();//*/ 76 | 77 | $viewer=new Viewer(); 78 | 79 | if($file=='../maps/isometric.tmx' && array_key_exists('rot', $_REQUEST)) { 80 | if(!in_array($_REQUEST['rot'],array('','0','ccw','90','180','cw','270','360'))) { 81 | trigger_error('unknown rotation', E_USER_ERROR); 82 | } 83 | require('rot.php'); 84 | foreach($map->layers as $a=>$layer) { 85 | for($i=0;$i<$map->height;++$i) { 86 | for($j=0;$j<$map->width;++$j) { 87 | $tile=$map->layers[$a]->get_tile($i*$map->width+$j); 88 | $lid=$tile-$map->tilesets[$map->get_tileset_index($tile)]->firstgid; 89 | //var_dump($lid); 90 | if($_REQUEST['rot']=='cw' || $_REQUEST['rot']=='270') { 91 | $lid=rotate90cw_lid($lid); 92 | } 93 | elseif($_REQUEST['rot']=='ccw' || $_REQUEST['rot']=='90') { 94 | $lid=rotate90ccw_lid($lid); 95 | } 96 | elseif($_REQUEST['rot']=='180') { 97 | $lid=rotate180_lid($lid); 98 | } 99 | //var_dump($lid); 100 | //echo '
'; 101 | if($lid==-1) $tile=0; 102 | else $tile=$lid+$map->tilesets[$map->get_tileset_index($tile)]->firstgid; 103 | //var_dump($tile); 104 | $map->layers[$a]->set_tile($i*$map->width+$j, $tile); 105 | } 106 | } 107 | //var_dump($map->layers[$a]);die(); 108 | if($_REQUEST['rot']=='cw' || $_REQUEST['rot']=='270') { 109 | $map->layers[$a]->rot90cw(); 110 | } 111 | elseif($_REQUEST['rot']=='ccw' || $_REQUEST['rot']=='90') { 112 | $map->layers[$a]->rot90ccw(); 113 | } 114 | elseif($_REQUEST['rot']=='180') { 115 | $map->layers[$a]->rot180(); 116 | } 117 | } 118 | if(!in_array($_REQUEST['rot'],array('cw','ccw'))) { 119 | $tmp=$map->width; 120 | $map->width=$map->height; 121 | $map->height=$tmp; 122 | } 123 | //var_dump($map); 124 | } 125 | 126 | $viewer->setMap($map); 127 | 128 | ini_set('output_buffering','off'); 129 | 130 | $data=ob_get_clean(); 131 | if(!empty($data)) { 132 | header('Content-Type: text/plain'."\r\n"); 133 | echo $data; 134 | die(); 135 | } 136 | 137 | ob_start(); 138 | 139 | if(!array_key_exists('layers_nodraw', $_SESSION)) { 140 | $_SESSION['layers_nodraw']=array('collision'); 141 | } 142 | if(!array_key_exists('tilesets_nodraw', $_SESSION)) { 143 | $_SESSION['tilesets_nodraw']=array('collision'); 144 | } 145 | 146 | $viewer->load_ts(); 147 | 148 | if(array_key_exists('zoom',$_REQUEST)) { 149 | assert(is_numeric($_REQUEST['zoom'])) or die('bad zoom value'); 150 | $viewer->zoom=floatval($_REQUEST['zoom']); 151 | assert($viewer->zoom>=0.1 && $viewer->zoom<=10) or die('bad zoom range'); 152 | } 153 | 154 | $viewer->init_draw(); 155 | $viewer->draw(); 156 | 157 | $data=ob_get_contents(); 158 | if(strlen($data)!=0) { 159 | header('Content-Type: text/plain'."\r\n"); 160 | echo $data; 161 | die(); 162 | } 163 | 164 | $viewer->render(); 165 | 166 | $data=ob_get_clean(); 167 | if(!defined('DEBUG')||DEBUG!==true) { 168 | //header('Content-Type: image/jpeg'."\r\n"); 169 | header('Content-Type: image/png'."\r\n"); 170 | } 171 | echo $data; 172 | 173 | ?> --------------------------------------------------------------------------------