diff --git a/README.md b/README.md index 2a9bdaa..5f5cef8 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This program comes without any warranty, to the extent permitted by applicable l * Install the git version of minetest (or otherwise install 0.4.13 or other version compatible with the map generators used by chunkymap) OPTION 2: IF you are using Ubuntu go to a terminal, cd to this folder, then switch user to the one that will run minetestserver - (since install-chunkymap-on-ubuntu.sh DOES replace "/home/owner" with current user's home in all chunkymap scripts in destination folder) + (since install-chunkymap-on-ubuntu.sh DOES replace "/home/owner" with current user's home [replace-with-current-user.py, which is automatically called by install, will change /home/owner to current user's folder in each script that install copies to $HOME/minetest/util]) then go to Terminal and run: `minetestserver` then when it is finished loading, press Ctrl C then run: diff --git a/chunkymap-regen.py b/chunkymap-regen.py index d11b12a..27ec4cc 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -93,11 +93,11 @@ is_save_output_ok = True def get_dict_from_conf_file(path,assignment_operator="="): results = None + print "Checking "+str(path)+" for settings..." if os.path.isfile(path): results = {} - ins = open(yaml_path, 'r') + ins = open(path, 'r') line = True - operator = ":" while line: line = ins.readline() if line and len(line)>0: @@ -109,7 +109,7 @@ def get_dict_from_conf_file(path,assignment_operator="="): if ao_index 0: - ini_name = line[:ao_index].strip() - ini_value = line[ao_index+1:].strip() - if ini_name=="name": - player_name = ini_value - elif ini_name=="position": - player_position = ini_value + found_name = line[:ao_index].strip() + found_value = line[ao_index+1:].strip() + if found_name=="name": + player_name = found_value + elif found_name=="position": + player_position = found_value if (player_name is not None) and (player_position is not None): has_enough_data = True break @@ -155,10 +155,12 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): player_dest_path = os.path.join(chunkymap_players_path,filename+".yml") if has_enough_data: #if player_name!="singleplayer": - outs = open(player_dest_path, 'w') - outs.write("name:"+player_name+"\n") # python automatically uses correct newline for your os when you put "\n" - outs.write("position:"+player_position+"\n") - outs.close() + map_player_dict = get_dict_from_conf_file(player_dest_path,":") + if (map_player_dict is None) or (map_player_dict["position"]!=player_position): + outs = open(player_dest_path, 'w') + outs.write("name:"+player_name+"\n") # python automatically uses correct newline for your os when you put "\n" + outs.write("position:"+player_position+"\n") + outs.close() mapvars = get_dict_from_conf_file(yaml_path,":") #is_testonly == (os_name=="windows") @@ -196,8 +198,8 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): total_generated_count = 0 #values for command arguments: - maxheight = 100 - minheight = -50 + maxheight = 50 + minheight = -25 pixelspernode = 1 #ALSO save to YAML: #world_name @@ -233,6 +235,9 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): dest_png_path = os.path.join(chunkymap_data_path, png_name) dest_mapper_out_path = os.path.join(chunkymap_data_path, mapper_out_name) is_empty_chunk = False + if os.path.isfile(dest_mapper_out_path): + if os.path.isfile(dest_png_path): + os.remove(dest_mapper_out_path) if os.path.isfile(dest_mapper_out_path): ins = open(dest_mapper_out_path) line = True @@ -274,7 +279,7 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): if os.path.isfile(dest_png_path): total_generated_count += 1 square_generates_count += 1 - print("Skipping existing map tile " + png_name + " since not full_render") + print("Skipping existing map tile file " + png_name + " (delete it to re-render)") elif is_empty_chunk: print("Skipping empty chunk " + chunk_luid + " since not full_render") print "" # blank line before next z so output is human readable diff --git a/chunkymap.php b/chunkymap.php new file mode 100644 index 0000000..7d2c7cf --- /dev/null +++ b/chunkymap.php @@ -0,0 +1,111 @@ + $value) { +//in case auto_globals is not enabled +$GLOBALS[$key]=$value; +} +date_default_timezone_set('EST'); //required by PHP >=5.1.0 + +$chunkymapdata_path = "chunkymapdata"; +$showplayers=true; + +function get_dict_from_conf($path, $assignment_operator) { + $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)!="#") { + $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 = get_dict_from_conf($chunkymapdata_path."/generated.yml"; + +//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); +} + +function echo_chunkymap_table($center_x, $center_z, $zoom_min_1_max_100) { + global $chunkymapdata_path; + global $map_dict; + if ($zoom_min_1_max_100<1) $zoom_min_1_max_100 = 1; + if ($zoom_min_1_max_100>100) $zoom_min_1_max_100 = 100; + $zoom_divisor = int(100/$zoom_min_1_max_100); + $chunk_assoc = array(); + $chunk_count = 0; + $x_opener="chunk_x"; + $z_opener="z"; + $dot_and_ext = ".png"; + $x = $map_dict["chunkx_min"]; + $z = $map_dict["chunkz_min"]; + $x_count = $map_dict["chunkx_max"] - $map_dict["chunkx_min"] + $z_count = $map_dict["chunkz_max"] - $map_dict["chunkz_min"] + echo ""; + while ($z <= $map_dict["chunkz_max"]) { + echo " "; + while ($x <= $map_dict["chunkx_max"]) { + echo " "; + $x++; + } + echo " "; + $z++; + } + echo "
"; + $chunk_luid = "x".$x."z".$z; + $chunk_img_name = $x_opener.$x.$z_opener.$z."$dot_and_ext"; + $chunk_img_path = $chunkymapdata_path.'/'.$chunk_img_name; + if (is_file($chunk_img_path)) { + echo ""; + } + echo "
".$x.",0,".$z + echo "
"; + //NOTE: no need to detect range since using $map_dict + /* + $x_max = 0; + $x_min = 0; + $z_min = 0; + $z_max = 0; + if ($handle = opendir($chunkymapdata_path)) { + while (false !== ($file = readdir($handle))) { + if (substr($file, 0, 1) != ".") { + $file_lower = strtolower($file); + if (endsWith($file_lower, $dot_and_ext) and startsWith($file_lower, $x_opener)) { + $z_opener_index = strpos($file_lower, $z_opener, strlen($x_opener)); + if ($z_opener_index !== false) { + $x_len = $z_opener_index - strlen($x_opener); + $z_len = strlen($file_lower) - strlen($x_opener) - $x_len - strlen($z_opener) - $dot_and_ext; + $x = substr($file_lower, strlen($x_opener), $x_len); + $z = substr($file_lower, $z_opener_index + strlen($z_opener), $z_len); + } + } + } + } + } + */ +} +?> \ No newline at end of file diff --git a/index-example.php b/index-example.php new file mode 100644 index 0000000..4059326 --- /dev/null +++ b/index-example.php @@ -0,0 +1,11 @@ + +Chunkymap Example Page + +Live Map: + +
Powered by Chunkymap
+ + \ No newline at end of file diff --git a/install-chunkymap-on-ubuntu-from-web.sh b/install-chunkymap-on-ubuntu-from-web.sh index 97b5cb0..c015bc7 100644 --- a/install-chunkymap-on-ubuntu-from-web.sh +++ b/install-chunkymap-on-ubuntu-from-web.sh @@ -1,10 +1,4 @@ #!/bin/sh -cd ~/minetest-stuff -rm master.zip -wget https://github.com/expertmm/minetest-chunkymap/archive/master.zip -mv master.zip minetest-chunkymap.zip -unzip minetest-chunkymap.zip -mv minetest-chunkymap-master minetest-chunkymap -cd minetest-chunkymap -chmod +x install-chunkymap-on-ubuntu.sh -./install-chunkymap-on-ubuntu.sh \ No newline at end of file +CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap +./update-chunkymap-installer-only.sh +sh $CHUNKYMAP_INSTALLER_DIR/install-chunkymap-on-ubuntu.sh \ No newline at end of file diff --git a/install-chunkymap-on-ubuntu.sh b/install-chunkymap-on-ubuntu.sh index 8d65296..8fbdef3 100644 --- a/install-chunkymap-on-ubuntu.sh +++ b/install-chunkymap-on-ubuntu.sh @@ -1,4 +1,5 @@ #!/bin/sh +CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap MINETEST_UTIL=$HOME/minetest/util CHUNKYMAP_DEST=$MINETEST_UTIL @@ -8,15 +9,15 @@ sudo apt-get install python-numpy python-pil #rm -f ~/minetestmapper-numpy.py #wget https://github.com/spillz/minetest/raw/master/util/minetestmapper-numpy.py #since colors.txt is in ~/minetest/util: -cp -f minetestmapper-numpy.py $HOME/minetest/util/minetestmapper-numpy.py +cp -f "$CHUNKYMAP_INSTALLER_DIR/minetestmapper-numpy.py" "$HOME/minetest/util/minetestmapper-numpy.py" mkdir "$CHUNKYMAP_DEST" -cp -f chunkymap-regen.py "$CHUNKYMAP_DEST/" +cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.py" "$CHUNKYMAP_DEST/" #chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.py" -cp -f chunkymap-regen.sh "$CHUNKYMAP_DEST/" +cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.sh" "$CHUNKYMAP_DEST/" chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.sh" -cp -f chunkymap-cronjob "$CHUNKYMAP_DEST/" +cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-cronjob" "$CHUNKYMAP_DEST/" chmod +x "$CHUNKYMAP_DEST/chunkymap-cronjob" -cp -f set-minutely-crontab-job.sh "$CHUNKYMAP_DEST/" +cp -f "$CHUNKYMAP_INSTALLER_DIR/set-minutely-crontab-job.sh" "$CHUNKYMAP_DEST/" chmod +x "$CHUNKYMAP_DEST/set-minutely-crontab-job.sh" python replace-with-current-user.py diff --git a/update-chunkymap-installer-only.sh b/update-chunkymap-installer-only.sh new file mode 100644 index 0000000..7860e51 --- /dev/null +++ b/update-chunkymap-installer-only.sh @@ -0,0 +1,13 @@ +#!/bin/sh +CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap + +cd ~/minetest-stuff +rm master.zip +wget https://github.com/expertmm/minetest-chunkymap/archive/master.zip +mv master.zip minetest-chunkymap.zip +unzip minetest-chunkymap.zip +#mv minetest-chunkymap-master minetest-chunkymap +mv minetest-chunkymap-master "$CHUNKYMAP_INSTALLER_DIR" +#cd minetest-chunkymap +chmod +x "$CHUNKYMAP_INSTALLER_DIR/install-chunkymap-on-ubuntu.sh" +chmod +x "$CHUNKYMAP_INSTALLER_DIR/update-chunkymap-on-ubuntu-from-web.sh" \ No newline at end of file diff --git a/update-chunkymap-on-ubuntu-from-web.sh b/update-chunkymap-on-ubuntu-from-web.sh new file mode 100644 index 0000000..2032571 --- /dev/null +++ b/update-chunkymap-on-ubuntu-from-web.sh @@ -0,0 +1,18 @@ +#!/bin/sh +CHUNKYMAP_INSTALLER_DIR=~/minetest-stuff/minetest-chunkymap +./update-chunkymap-installer-only.sh +#./install-chunkymap-on-ubuntu.sh + + +cp -f "$CHUNKYMAP_INSTALLER_DIR/minetestmapper-numpy.py" "$HOME/minetest/util/minetestmapper-numpy.py" +mkdir "$CHUNKYMAP_DEST" +cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.py" "$CHUNKYMAP_DEST/" +#chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.py" +cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-regen.sh" "$CHUNKYMAP_DEST/" +chmod +x "$CHUNKYMAP_DEST/chunkymap-regen.sh" +cp -f "$CHUNKYMAP_INSTALLER_DIR/chunkymap-cronjob" "$CHUNKYMAP_DEST/" +chmod +x "$CHUNKYMAP_DEST/chunkymap-cronjob" +cp -f "$CHUNKYMAP_INSTALLER_DIR/set-minutely-crontab-job.sh" "$CHUNKYMAP_DEST/" +chmod +x "$CHUNKYMAP_DEST/set-minutely-crontab-job.sh" + +python replace-with-current-user.py \ No newline at end of file