diff --git a/README.md b/README.md index 5436b69..4c5782c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ This program comes without any warranty, to the extent permitted by applicable l #where 1 is number of seconds: refresh_players_seconds:1 -* Has static html version of map (echo_chunkymap_table() php function) -- see example.php +* Can show a static html version of map (echo_chunkymap_table() php function) -- see viewchunkymap.php * Zoom in and out * optionally echo name of world that was detected by the scheduled py file * shows player location (can optionally show only first characters of name, for privacy; there is no saved setting yet, so to adjust, you must change the value of $nonprivate_name_beginning_char_count in chunkymap.php) @@ -78,11 +78,11 @@ world_path (if you are not using /var/www/html/minetest/chunkymapdata, edit chunkymap-cronjob script to use the correct directory, then) `chmod +x set-minutely-crontab-job.sh && ./set-minutely-crontab-job.sh` * IF you are using Linux - * Either copy your code to example.php and use it, or just rename it to map.php (or anything you want) then link to it. + * Rename viewchunkymap.php so it won't be overwritten on update if you want to modify it (or anything you want) then make a link to it on your website or share the link some other way. # The commands below will work if you are using the web installer, or have done mv minetest-chunkymap-master "$HOME/Downloads/minetest-chunkymap" (and if you are using /var/www/html/minetest -- otherwise change that below) MT_MY_WEBSITE_PATH=/var/www/html/minetest sudo cp -f "$HOME/Downloads/minetest-chunkymap/web/chunkymap.php" "$MT_MY_WEBSITE_PATH/chunkymap.php" - sudo cp --no-clobber "$HOME/Downloads/minetest-chunkymap/web/example.php" "$MT_MY_WEBSITE_PATH/viewchunkymap.php" + sudo cp -f "$HOME/Downloads/minetest-chunkymap/web/viewchunkymap.php" "$MT_MY_WEBSITE_PATH/viewchunkymap.php" sudo cp -R --no-clobber "$HOME/Downloads/minetest-chunkymap/web/images/*" "$MT_MY_WEBSITE_PATH/images/" #--no-clobber: do not overwrite existing # after you do this, the update script will do it for you if you are using /var/www/html/minetest, otherwise edit the update script before using it to get these things updated diff --git a/chunkymap-regen.py b/chunkymap-regen.py index f97a654..bfe36e0 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -478,7 +478,7 @@ class MTChunks: install_list = list() install_list.append(InstalledFile("browser.php",source_web_path,dest_web_path)) install_list.append(InstalledFile("chunkymap.php",source_web_path,dest_web_path)) - install_list.append(InstalledFile("example.php",source_web_path,dest_web_path)) + install_list.append(InstalledFile("viewchunkymap.php",source_web_path,dest_web_path)) install_list.append(InstalledFile("zoom-in.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) install_list.append(InstalledFile("zoom-out.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) install_list.append(InstalledFile("zoom-in_disabled.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) @@ -584,6 +584,47 @@ class MTChunks: # 0 becomes 0 #-1 becomes -10 return int(decachunky_x*10) + + def is_worldborder_chunk(self, chunky_x, chunky_z): + result = False + image_path = get_chunk_image_path(chunky_x, chunky_z) + if os.path.isfile(image_path): + original_im = Image.open(image_path) + im = original_im + if im.bits<24: + im = original_im.convert('RGB') + width, height = im.size + pixel_count = width*height + pixel_count_f = float(pixel_count) + border_count = 0 + FLAG_COLORS_LIST = list() + FLAG_COLOR_CHANNELS = get_list_from_hex(self.FLAG_EMPTY_HEXCOLOR) + FLAG_COLORS_LIST.append(FLAG_COLOR_CHANNELS) + FLAG_COLORS_LIST.append((255,255,255)) #for compatibility with maps generated by earlier versions ONLY + FLAG_COLORS_LIST.append((0,0,0)) #for compatibility with maps generated by earlier versions ONLY + for FLAG_COLOR in FLAG_COLORS_LIST: + if len(FLAG_COLOR)==3 or len(FLAG_COLOR)==4: + for y in range(0,height): + for x in range(0,width): + r, g, b = im.getpixel((x, y)) + if r==FLAG_COLOR[0] and g==FLAG_COLOR[1] and b==FLAG_COLOR[2]: + border_pixel_count += 1 + if float(border_pixel_count)/pixel_count_f >=.51: + result = True + break + else: + raw_input("ERROR: FLAG_COLOR (obtained from FLAG_EMPTY_HEXCOLOR) has "+len(FLAG_COLOR)+" element(s) (3 or 4 expected)") + return result + + def is_chunk_on_todo_list(self, chunky_pos): + result = -1 + if self.todo_indexprev_rendered_this_session_count or self.force_rerender_decachunks_enable: - self.check_decachunk_containing_chunk(chunky_x, chunky_z) + #self.check_decachunk_containing_chunk(chunky_x, chunky_z) if self.verbose_enable: print(min_indent+"["+str(self.todo_index)+"] branching from "+str((chunky_x, chunky_z))+" (added "+str(len(self.todo_positions)-prev_len)+")") else: + #self.check_decachunk_containing_chunk(chunky_x, chunky_z) if self.verbose_enable: print(min_indent+"["+str(self.todo_index)+"] not branching from "+str((chunky_x, chunky_z))) self.todo_index += 1 - if self.todo_index>=len(self.todo_positions): # check again since may have branched above, making this untrue + + #check_decachunk_containing_chunk AFTER incrementing todo_index so that self being queued doesn't prevent decachunk render: + self.check_decachunk_containing_chunk(chunky_x, chunky_z) + if self.todo_index>=len(self.todo_positions): # check again since may have branched above, making this untrue self.save_mapvars_if_changed() self.todo_index = -1 + self.todo_positions = list() else: if self.verbose_enable: print(min_indent+"(no branches)") @@ -1417,6 +1499,74 @@ class MTChunks: print("") print("") + def get_cross_coords_list(x_int, y_int, restrict_to_decachunk_enable=False): + results = None + if x_int is not None and y_int is not None: + tmp = list() + # North, East, South, West (cartesian): + tmp.append((x_int,y_int+1)) + tmp.append((x_int+1,y_int)) + tmp.append((x_int,y_int-1)) + tmp.append((x_int-1,y_int)) + if restrict_to_decachunk_enable: + results = list() + starting_decachunk_luid = self.get_decachunk_luid_from_chunk(x_int, y_int) + for result in tmp: + this_x, this_y = result + if self.get_decachunk_luid_from_chunk(this_x, this_y) == starting_decachunk_luid: + results.append(result) + else: + results = tmp + return results + + def get_outline_coords_list(x_int, y_int, restrict_to_decachunk_enable=False): + results = None + if x_int is not None and y_int is not None: + tmp = list() + # North, NE, East, SE, South, SW, West, NW (cartesian): + tmp.append((x_int,y_int+1)) # N + tmp.append((x_int+1,y_int+1)) # NE + tmp.append((x_int+1,y_int)) # E + tmp.append((x_int+1,y_int-1)) # SE + tmp.append((x_int,y_int-1)) # S + tmp.append((x_int-1,y_int-1)) # SW + tmp.append((x_int-1,y_int)) # W + tmp.append((x_int-1,y_int+1)) # NW + if restrict_to_decachunk_enable: + results = list() + starting_decachunk_luid = self.get_decachunk_luid_from_chunk(x_int, y_int) + for result in tmp: + this_x, this_y = result + if self.get_decachunk_luid_from_chunk(this_x, this_y) == starting_decachunk_luid: + results.append(result) + else: + results = tmp + return results + + def is_worldborder_count_gt_or_eq(chunky_coords_list, min_count): + result = False + count = 0 + for chunky_pos in chunky_coords_list: + if is_worldborder_chunk(chunky_pos[0], chunky_pos[1]): + count += 1 + if count >= min_count: + result = True + break + return result + + + def is_nonworldborder_isrendered_count_gt_or_eq(chunky_coords_list, min_count): + result = False + count = 0 + if chunky_coords_list is not None: + for chunky_pos in chunky_coords_list: + chunky_x, chunky_z = chunky_pos + if is_chunk_rendered_on_dest(chunky_x, chunky_z) and not is_worldborder_chunk(chunky_x, chunky_z): + count += 1 + if count >= min_count: + result = True + break + return result def check_map_pseudorecursion_start(self): if self.todo_index<0: diff --git a/chunkymap-signals example - turn on verbose.txt b/chunkymap-signals example - verbose_enable True.txt similarity index 100% rename from chunkymap-signals example - turn on verbose.txt rename to chunkymap-signals example - verbose_enable True.txt diff --git a/expertmm.py b/expertmm.py index df67c67..f84806b 100644 --- a/expertmm.py +++ b/expertmm.py @@ -31,6 +31,8 @@ class InstalledFile: self.file_name=file_name self.source_dir_path=source_dir_path self.dest_dir_path=dest_dir_path + + class ConfigManager: #config_name = None @@ -138,7 +140,7 @@ def is_dict_subset(new_dict, old_dict, verbose_messages_enable, verbose_dest_des view_traceback() return is_changed -def vec2_not_in(this_list, this_vec): +def vec2_not_in(this_vec, this_list): result = False if this_list is not None and this_vec is not None: for try_vec in this_list: @@ -261,6 +263,26 @@ def save_conf_from_dict(path, this_dict, assignment_operator="=", save_nulls_ena outs.close() except: pass + +def get_list_from_hex(hex_string): + results = None + if hex_string is not None: + if len(hex_string)>=2: + if hex_string[:2]=="0x": + hex_string = hex_string[2:] + elif hex_string[:1]=="#": + hex_string = hex_string[1:] + if len(hex_string)>0 and hex_string[len(hex_string)-1:]=="h": + hex_string = hex_string[:len(hex_string)-1] + index = 0 + while index= 2: + results.append(int(hex_string[index:index+2], 16)) + index += 2 + + return results def get_tuple_from_notation(line, debug_src_name=""): result = None diff --git a/minetestinfo.py b/minetestinfo.py index ebc3389..8b34189 100644 --- a/minetestinfo.py +++ b/minetestinfo.py @@ -163,6 +163,9 @@ def load_world_and_mod_data(): this_primary_world_path = try_path minetestinfo._data["primary_world_path"] = this_primary_world_path auto_chosen_world = False + else: + if default_world_path is not None: + minetestinfo._data["primary_world_path"] = default_world_path minetestinfo.save_yaml() if get_world_var("gameid") != minetestinfo.get_var("game_path"): diff --git a/update-chunkymap-on-ubuntu-from-web.sh b/update-chunkymap-on-ubuntu-from-web.sh index a0a21f4..ec94682 100644 --- a/update-chunkymap-on-ubuntu-from-web.sh +++ b/update-chunkymap-on-ubuntu-from-web.sh @@ -24,8 +24,8 @@ MT_MY_WEBSITE_PATH=/var/www/html/minetest if [ -f "$HOME/Downloads/minetest-chunkymap/web/chunkymap.php" ]; then if [ -f "$MT_MY_WEBSITE_PATH/chunkymap.php" ]; then sudo cp -f "$HOME/Downloads/minetest-chunkymap/web/chunkymap.php" "$MT_MY_WEBSITE_PATH/" - #sudo cp --no-clobber "$HOME/Downloads/minetest-chunkymap/web/example.php" "$MT_MY_WEBSITE_PATH/viewchunkymap.php" - sudo cp -f "$HOME/Downloads/minetest-chunkymap/web/example.php" "$MT_MY_WEBSITE_PATH/example.php" + #sudo cp --no-clobber "$HOME/Downloads/minetest-chunkymap/web/viewchunkymap.php" "$MT_MY_WEBSITE_PATH/viewchunkymap.php" + sudo cp -f "$HOME/Downloads/minetest-chunkymap/web/viewchunkymap.php" "$MT_MY_WEBSITE_PATH/viewchunkymap.php" # cannot put wildcard in quotes on unix #sudo cp -R --no-clobber $HOME/Downloads/minetest-chunkymap/web/images/* "$MT_MY_WEBSITE_PATH/images/" #--no-clobber: do not overwrite existing diff --git a/web/chunkymap.php b/web/chunkymap.php index 285aa99..819369b 100644 --- a/web/chunkymap.php +++ b/web/chunkymap.php @@ -1,8 +1,10 @@ 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 diff --git a/web/update wamp www.bat b/web/update wamp www.bat index 368f121..58160b3 100644 --- a/web/update wamp www.bat +++ b/web/update wamp www.bat @@ -3,10 +3,10 @@ SET SRC_MT_WEB_PATH=%USERPROFILE%\Documents\GitHub\minetest-chunkymap\web SET DEST_MT_WEBSITE_PATH=C:\wamp\www copy /y "%SRC_MT_WEB_PATH%\browser.php" "%DEST_MT_WEBSITE_PATH%\" copy /y "%SRC_MT_WEB_PATH%\chunkymap.php" "%DEST_MT_WEBSITE_PATH%\" -copy /y "%SRC_MT_WEB_PATH%\example.php" "%DEST_MT_WEBSITE_PATH%\" +copy /y "%SRC_MT_WEB_PATH%\viewchunkymap.php" "%DEST_MT_WEBSITE_PATH%\" SET DEST_MT_WEBSITE_CHUNKYMAP_IMAGES_PATH=%DEST_MT_WEBSITE_PATH%\chunkymapdata\images copy /y "%SRC_MT_WEB_PATH%\chunkymapdata_default\images\*" "%DEST_MT_WEBSITE_CHUNKYMAP_IMAGES_PATH%" -if NOT ["%errorlevel%"]==["0"] pause \ No newline at end of file +if NOT ["%errorlevel%"]==["0"] pause diff --git a/web/example.php b/web/viewchunkymap.php similarity index 100% rename from web/example.php rename to web/viewchunkymap.php