This is the backend--don't call it directly. instead do include_once('chunkymap.php'); To use the map, go to viewchunkymap.php instead."; } //NOTE: for parse errors, MUST add the following line to php.ini (such as /etc/php5/apache2/php.ini): display_errors = on if (is_file('browser.php')) { include_once('browser.php'); } else { echo ""; } $chunkymap_anchor_name="chunkymap_top"; $is_verbose = false; if ($is_verbose) echo "REQUEST..."; foreach($_REQUEST as $key => $value) { //in case auto_globals is not enabled $GLOBALS[$key]=$value; if ($is_verbose) echo "$key:$value..."; } if ($is_verbose) echo "timezone..."; date_default_timezone_set('EST'); //required by PHP >=5.1.0 if ($is_verbose) echo "globals..."; //$chunkymap_view_x=0; //$chunkymap_view_z=0; //$chunkymap_view_zoom=25; if (!isset($chunkymap_view_x)) { $chunkymap_view_x=0; } if (!isset($chunkymap_view_z)) { $chunkymap_view_z=0; } if (!isset($chunkymap_view_zoom)) { $chunkymap_view_zoom=.25; } $chunkymapdata_path = "chunkymapdata"; $chunkymapdata_worlds_path = $chunkymapdata_path."/worlds"; $chunkymapdata_thisworld_path = null; $showplayers=true; // NOT OPTIONAL for table version: $chunkymap_tile_original_w=16; $chunkymap_tile_original_h=16; $chunk_dimension_min=$chunkymap_tile_original_w; if ($chunkymap_tile_original_h<$chunk_dimension_min) $chunk_dimension_min=$chunkymap_tile_original_h; $chunkymap_change_zoom_multiplier=1.5; $chunkymap_camera_pan_delta=.5; $chunkymap_view_min_zoom=0.0173415299; //1.0/$chunk_dimension_min; //should be a number that would get to exactly 100 eventually if multiplied by chunkymap_zoom_delta repeatedly (such as 0.09765625 if chunkymap_zoom_delta were 2); 0.005 was avoided since tiles used to be 80x80 pixels $chunkymap_view_max_zoom=16585998.48141; //13107200.0; $decachunk_prefix_string="decachunk_"; $decachunk_prefix_then_x_string=$decachunk_prefix_string."x"; $chunk_prefix_string="chunk_"; $chunk_prefix_then_x_string=$chunk_prefix_string."x"; $z_opener="z"; $dot_yaml=".yml"; $decachunk_dot_and_ext=".jpg"; $chunk_dot_and_ext = ".png"; //$more_attribs_string="; -webkit-filter: opacity(0%); filter: opacity(0%)"; $more_attribs_string=""; $td_decachunk_placeholder_content=""; $td_chunk_placeholder_content=""; $td_1px_placeholder_content=""; function echo_error($val) { if (!isset($val)) { $val="Unknown Error"; } echo ''.$val.'
'."\n"; } function get_dict_from_conf($path, $assignment_operator) { global $is_verbose; if ($is_verbose) echo "get_dict..."; $handle = fopen($path, "r"); $result = null; if ($handle) { while (($line = fgets($handle)) !== false) { $line_strip = trim($line); if (strlen($line_strip)>0) { if (substr($line_strip,0,1)!="#") { $ao_index = strpos($line_strip, $assignment_operator); if ($ao_index>0 and $ao_index<(strlen($line_strip)-1)) { //skip blank variable OR value $found_name = substr($line_strip, 0, $ao_index); $found_value_index = $ao_index + 1; $found_value = substr($line_strip, $found_value_index, strlen($line_strip)-$found_value_index); if ($result===null) { $result = array(); } $result[$found_name]=$found_value; } } } } fclose($handle); } else { echo "Failed to read $path (run chunkymap-cronjob script as root first, otherwise see README.md in minetest-chunkymap to ensure installation is correct).
"; } return $result; }//end get_dict_from_conf $map_dict = null; //startsWith and endsWith are from: //Salmon A. stackoverflow. . 5 Feb 2016. 19 Feb, 2016. function startsWith($haystack, $needle) { // search backwards starting from haystack length characters from the end return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; } function endsWith($haystack, $needle) { // search forward starting from end minus needle length characters return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false); } //NOTE: This function is here since the builtin is_int checks type (which is not needed in this webapp) and the builtin is_numeric includes decimal and exponent (see http://php.net/manual/en/function.is-numeric.php) function is_int_string($val) { global $is_verbose; if ($is_verbose) echo "is_int_string..."; $result = true; $int_chars="0123456789-"; for ($i=0; $i(missing world name)"; // } function get_chunk_folder_path_from_chunky_coords($chunky_x, $chunky_z) { global $chunkymapdata_thisworld_path; //NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0 $decachunk_x = get_decachunky_coord_from_chunky_coord($chunky_x); $decachunk_z = get_decachunky_coord_from_chunky_coord($chunky_z); //if ($x<0) { $decachunk_x = $x + $x%10; } //else { $decachunk_x = $x - $x%10; } //if ($z<0) { $decachunk_z = $z + $z%10; } //else { $decachunk_z = $z - $z%10; } $result = $chunkymapdata_thisworld_path.'/16px/'.$decachunk_x.'/'.$decachunk_z; return $result; } function get_decachunk_folder_path_from_location($x, $z) { global $chunkymapdata_thisworld_path; //NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0 $chunky_x = get_chunky_coord_from_location($x); $chunky_z = get_chunky_coord_from_location($z); $decachunky_x = get_decachunky_coord_from_chunky_coord($chunky_x); $decachunky_z = get_decachunky_coord_from_chunky_coord($chunky_z); $hectochunk_x = get_hectochunky_coord_from_decachunky_coord($decachunky_x); $hectochunk_z = get_hectochunky_coord_from_decachunky_coord($decachunky_z); $result = $chunkymapdata_thisworld_path.'/160px/'.$hectochunk_x.'/'.$hectochunk_z; return $result; } function get_decachunk_folder_path_from_decachunk($chunky_x, $chunky_z) { global $chunkymapdata_thisworld_path; //NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0 $hectochunk_x = get_hectochunky_coord_from_decachunky_coord($chunky_x); $hectochunk_z = get_hectochunky_coord_from_decachunky_coord($chunky_z); $result = $chunkymapdata_thisworld_path.'/160px/'.$hectochunk_x.'/'.$hectochunk_z; return $result; } function get_chunky_coord_from_location($location_coord) { $chunk_coord = intval(floor((float)$location_coord/16)); return $chunk_coord; } function get_decachunky_coord_from_chunky_coord($chunky_x) { return intval(floor((float)$chunky_x/10.0)); } function get_hectochunky_coord_from_decachunky_coord($chunky_x) { return intval(floor((float)$chunky_x/10.0)); } function get_decachunky_coord_from_location($location_x) { $chunk_x = get_chunky_coord_from_location($location_x); $decachunk_x = get_decachunky_coord_from_chunky_coord($chunk_x); return $decachunk_x; } function get_decachunk_image_path_from_decachunk($decachunky_x, $decachunky_z) { return get_decachunk_folder_path_from_decachunk($decachunky_x, $decachunky_z)."/".get_decachunk_image_name_from_decachunk($decachunky_x, $decachunky_z); } function get_decachunk_image_name_from_decachunk($x, $z) { global $decachunk_prefix_string; global $decachunk_dot_and_ext; return "$decachunk_prefix_string"."$x"."z"."$z"."$decachunk_dot_and_ext"; } function get_chunk_yaml_path_from_chunky_coords($chunky_x, $chunky_z) { return get_chunk_folder_path_from_chunky_coords($chunky_x, $chunky_z).'/'.get_chunk_yaml_file_name($chunky_x, $chunky_z); } function get_chunk_image_path_from_chunky_coords($chunky_x, $chunky_z) { return get_chunk_folder_path_from_chunky_coords($chunky_x, $chunky_z).'/'.get_chunk_file_name($chunky_x, $chunky_z); } function get_chunk_yaml_file_name($chunky_x, $chunky_z) { global $chunk_prefix_then_x_string; global $dot_yaml; global $z_opener; return $chunk_prefix_then_x_string.$chunky_x.$z_opener.$chunky_z.$dot_yaml; } function get_chunk_file_name($chunky_x, $chunky_z) { global $chunk_prefix_then_x_string; global $dot_yaml; global $z_opener; global $chunk_dot_and_ext; return $chunk_prefix_then_x_string.$chunky_x.$z_opener.$chunky_z."$chunk_dot_and_ext"; } function get_javascript_bool_value($this_bool) { $result = "false"; if ($this_bool == true) { $result = "true"; } return $result; } //chunk_mode_enable: shows chunk png images instead of decachunk jpg images (slower) //visual_debug_enable: draws colored rectangles based on yml files instead of drawing images function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_mode_enable) { global $chunkymap_view_x; global $chunkymap_view_z; global $chunkymap_view_zoom; global $chunkymap_view_max_zoom; global $chunkymap_view_min_zoom; global $showplayers; global $chunkymap_change_zoom_multiplier; global $chunkymap_camera_pan_delta; global $world_name; check_world(); if (isset($world_name)) { $chunks_per_tile_x_count = 10; $chunks_per_tile_z_count = 10; //use decachunk jpgs by default for speed: $tile_w = 160; $tile_h = 160; if (isset($chunk_mode_enable) and ($chunk_mode_enable===true)) { $tile_w = 16; $tile_h = 16; $chunks_per_tile_x_count = 1; $chunks_per_tile_z_count = 1; } else { $chunk_mode_enable=false; } $locations_per_tile_x_count = $chunks_per_tile_x_count*16; $locations_per_tile_z_count = $chunks_per_tile_z_count*16; if ($chunkymap_view_zoom<$chunkymap_view_min_zoom) $chunkymap_view_zoom = $chunkymap_view_min_zoom; if ($chunkymap_view_zoom>$chunkymap_view_max_zoom) $chunkymap_view_zoom = $chunkymap_view_max_zoom; $EM_PER_WIDTH_COUNT = 800.0/12.0; $world_camera_w = (800/$tile_w) * (1.0/$chunkymap_view_zoom); //screen should be 800pt wide always (so 12pt is similar on all screens and only varies with physical size of screen in inches, and since pt was invented to replace px) $world_camera_left = $chunkymap_view_x-$world_camera_w/2.0; $world_camera_h = $world_camera_w; //start with square camera to make sure enough chunks are loaded and since neither screen height nor ratio can be known from php since it is only run on server-side $world_camera_top = $chunkymap_view_z+$world_camera_h/2.0; //plus since cartesian until drawn [then flipped] $chunky_view_x = get_chunky_coord_from_location($chunkymap_view_x); $chunky_view_z = get_chunky_coord_from_location($chunkymap_view_z); #tile is either chunk or decachunk $min_tiley_x = -1; $max_tiley_x = 0; $min_tiley_z = -1; $max_tiley_z = 0; $world_camera_right = $world_camera_left+$world_camera_w; $world_camera_bottom = $world_camera_top-$world_camera_h; //minus since cartesian until drawn [then flipped] //Only whether the near edges are in the canvas matters (get bottom of max since always cartesian until drawn [then inverted]): $min_tiley_x__chunk_location_right = $min_tiley_x*$locations_per_tile_x_count+$locations_per_tile_x_count; $max_tiley_x__chunk_location_left = $max_tiley_x*$locations_per_tile_x_count; $min_tiley_z__chunk_location_top = $min_tiley_z*$locations_per_tile_z_count; $max_tiley_z__chunk_location_bottom = $max_tiley_z*$locations_per_tile_z_count+$locations_per_tile_z_count; while ($min_tiley_x__chunk_location_right>$world_camera_left) { $min_tiley_x -= 1; $min_tiley_x__chunk_location_right = $min_tiley_x*$locations_per_tile_x_count+$locations_per_tile_x_count; } while ($max_tiley_x__chunk_location_left<$world_camera_right) { $max_tiley_x += 1; $max_tiley_x__chunk_location_left = $max_tiley_x*$locations_per_tile_x_count; } while ($min_tiley_z__chunk_location_top>$world_camera_bottom) { $min_tiley_z -= 1; $min_tiley_z__chunk_location_top = $min_tiley_z*$locations_per_tile_z_count; } while ($max_tiley_z__chunk_location_bottom<$world_camera_top) { $max_tiley_z += 1; $max_tiley_z__chunk_location_bottom = $max_tiley_z*$locations_per_tile_z_count+$locations_per_tile_z_count; } $tile_x_count = $max_tiley_x-$min_tiley_x+1; $tile_z_count = $max_tiley_z-$min_tiley_z+1; if ($html4_mode_enable!==true) { echo ' '; echo ' '; }//end if not $html4_mode_enable global $td_decachunk_placeholder_content; global $td_chunk_placeholder_content; $td_tile_placeholder_content = null; if ($chunk_mode_enable) { $td_tile_placeholder_content = $td_chunk_placeholder_content; } else { $td_tile_placeholder_content = $td_decachunk_placeholder_content } echo ''; echo ''; echo ''; echo ''; echo ''; $this_tiley_z=$max_tiley_z; //start at max since screen is inverted cartesian if ($visual_debug_enable!==true) { //this table loads the images then is hidden when javascript runs successfully, but it is also a map though not very functional echo ''."\r\n"; echo ' '."\r\n"; echo ' '."\r\n"; echo " '."\r\n"; echo ' '."\r\n"; echo ' '."\r\n"; $cell_perc=intval(round(100.0/$decachunky_count_x)); echo ' '."\r\n"; echo " '."\r\n"; echo ' '."\r\n"; echo " '."\r\n"; echo ' '."\r\n"; echo ' '."\r\n"; echo ' '."\r\n"; echo " '."\r\n"; echo ' '."\r\n"; echo ' '."\r\n"; echo '
'."$td_tile_placeholder_content".'".''.''."$td_tile_placeholder_content".'
".''.''."\r\n"; echo ' '."\r\n"; while ($this_tiley_z>=$min_tiley_z) { $this_tiley_x=$min_tiley_x; echo " \r\n"; while ($this_tiley_x<=$max_tiley_x) { $img_path=null; echo " \r\n"; $this_tiley_x++; } echo " \r\n"; $this_tiley_z-=1; } echo '
"; if ($chunk_mode_enable) { $img_path=get_chunk_image_path_from_chunky_coords($this_tiley_x, $this_tiley_z); if (!is_file($img_path)) { echo ""; $img_path="chunkymapdata/images/chunk-blank.jpg"; } } else { $img_path=get_decachunk_image_path_from_decachunk($this_tiley_x, $this_tiley_z); if (!is_file($img_path)) { echo ""; $img_path="chunkymapdata/images/decachunk-blank.jpg"; } } echo ""."
'; echo '
".''.'
'."$td_decachunk_placeholder_content".'".''.''."$td_decachunk_placeholder_content".'
'."\r\n"; } } else { //not isset($world_name) echo "

Choose world:

"; echo ""; } //TODO: $chunkymap_view_zoom SHOULD BE interpreted so each block (pixel) is 1pt: 1066x600 pt canvas would have 66+2/3 blocks horizontally, is 37.5 blocks vertically //so, at zoom 1.0 canvas should show 60 chunks across (6 decachunks across) }//end echo_chunkymap_canvas function check_world() { global $chunkymapdata_thisworld_path; global $world_name; global $chunkymapdata_worlds_path; if (!isset($world_name)) { if ($handle = opendir($chunkymapdata_worlds_path)) { while (false !== ($file_name = readdir($handle))) { if (substr($file_name, 0, 1) != ".") { $file_path = $chunkymapdata_worlds_path."/".$file_name; if (is_dir($file_path)) { $world_name=$file_name; break; } } } closedir($handle); } } if (isset($world_name)) { $chunkymapdata_thisworld_path = $chunkymapdata_worlds_path."/".$world_name; } } ?>