From c89ed446970e79523c562c72645642250eb1fc69 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Wed, 16 Mar 2016 18:35:08 -0400 Subject: [PATCH] working on chunk folders and unified webapp --- ...ng-files-in-www-minetest-chunkymapdata.bat | 0 ...wamp-www-minetest-chunkymapdata-worlds.bat | 5 + chunkymap-regen.py | 41 +- minetestinfo.py | 121 +- unused/chunkymap_deprecated.php | 766 ++++++++ web/chunkymap.php | 1566 +++++------------ .../{compass-rose.png => compass_rose.png} | Bin .../images/rename-deprecated.bat | 5 + .../images/{zoom-in.png => zoom_in.png} | Bin ...m-in_disabled.png => zoom_in_disabled.png} | Bin .../images/{zoom-out.png => zoom_out.png} | Bin ...out_disabled.png => zoom_out_disabled.png} | Bin web/viewchunkymap.php | 11 +- 13 files changed, 1341 insertions(+), 1174 deletions(-) rename chunkymap erase png files in www minetest chunkymapdata.bat => chunkymap-erase-png-files-in-www-minetest-chunkymapdata.bat (100%) create mode 100644 chunkymap-erase-wamp-www-minetest-chunkymapdata-worlds.bat create mode 100644 unused/chunkymap_deprecated.php rename web/chunkymapdata_default/images/{compass-rose.png => compass_rose.png} (100%) create mode 100644 web/chunkymapdata_default/images/rename-deprecated.bat rename web/chunkymapdata_default/images/{zoom-in.png => zoom_in.png} (100%) rename web/chunkymapdata_default/images/{zoom-in_disabled.png => zoom_in_disabled.png} (100%) rename web/chunkymapdata_default/images/{zoom-out.png => zoom_out.png} (100%) rename web/chunkymapdata_default/images/{zoom-out_disabled.png => zoom_out_disabled.png} (100%) diff --git a/chunkymap erase png files in www minetest chunkymapdata.bat b/chunkymap-erase-png-files-in-www-minetest-chunkymapdata.bat similarity index 100% rename from chunkymap erase png files in www minetest chunkymapdata.bat rename to chunkymap-erase-png-files-in-www-minetest-chunkymapdata.bat diff --git a/chunkymap-erase-wamp-www-minetest-chunkymapdata-worlds.bat b/chunkymap-erase-wamp-www-minetest-chunkymapdata-worlds.bat new file mode 100644 index 0000000..ecb6b7a --- /dev/null +++ b/chunkymap-erase-wamp-www-minetest-chunkymapdata-worlds.bat @@ -0,0 +1,5 @@ +SET CHUNKYMAPDATA_PATH=C:\wamp\www\chunkymapdata +SET CHUNKYMAPDATA_WORLDS_PATH=%CHUNKYMAPDATA_PATH%\worlds +rd /s /q "%CHUNKYMAPDATA_WORLDS_PATH%" +if NOT ["%errorlevel%"]==["0"] pause +REM explorer "%CHUNKYMAPDATA_PATH%" \ No newline at end of file diff --git a/chunkymap-regen.py b/chunkymap-regen.py index 16fc1d8..fc3ef23 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -625,14 +625,18 @@ class MTChunks: raw_input("ERROR: FLAG_COLOR (obtained from FLAG_EMPTY_HEXCOLOR) has "+len(FLAG_COLOR)+" element(s) (3 or 4 expected)") return result - def get_index_of_chunk_on_todo_list(self, chunky_pos): + def get_index_of_chunk_on_todo_list(self, chunky_pos, allow_current_chunk_enable=False): result = -1 if self.todo_index > -1: if self.todo_index -1 if is_any_part_queued: if queued_chunk_coords is None: @@ -705,8 +709,6 @@ class MTChunks: if not is_chunk_complete: break - - #if not is_any_part_queued: #if queued_chunk_coords is None: if is_chunk_complete and not is_any_part_queued: @@ -1413,21 +1415,23 @@ class MTChunks: #must check_decachunk_containing_chunk AFTER _check_map_pseudorecursion_branchfrom so check_decachunk_containing_chunk can see if there are more to do before rendering superchunk #always check since already checks queue and doesn't render decachunk on last rendered chunk, but instead on last queued chunk in decachunk #if self.rendered_this_session_count>prev_rendered_this_session_count or self.force_rerender_decachunks_enable: - #self.check_decachunk_containing_chunk(chunky_x, chunky_z) + + #Now is ok to check_decachunk_containing_chunk, since does not count current index as unfinished (allow_current_chunk_enable=False): + 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) + #Now is ok to check_decachunk_containing_chunk, since does not count current index as unfinished (allow_current_chunk_enable=False): + 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 - - #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() + #self.todo_positions = list() # there seems to be issues where not empty due to delayed garbage collection + while len(self.todo_positions) > 0 : self.todo_positions.pop() else: if self.verbose_enable: print(min_indent+"(no branches)") @@ -1595,7 +1599,8 @@ class MTChunks: print("PROCESSING MAP DATA (BRANCH PATTERN)") if os.path.isfile(self.minetestmapper_py_path) and os.path.isfile(self.colors_path): self.rendered_count = 0 - self.todo_positions = list() + #self.todo_positions = list() # there seems to be issues where not empty due to delayed garbage collection + while len(self.todo_positions) > 0 : self.todo_positions.pop() self.todo_positions.append((0,0)) #self.mapvars = get_dict_from_conf_file(self.world_yaml_path,":") self.verify_correct_map() @@ -1610,10 +1615,10 @@ class MTChunks: for decachunk_x_name in os.listdir(self.data_16px_path): decachunk_x_path = os.path.join(self.data_16px_path, decachunk_x_name) #for decachunk_z_basepath, decachunk_z_dirnames, decachunk_z_filenames in os.walk(decachunk_x_dirnames): - if decachunk_x_path[:1]!="." and os.path.isdir(decachunk_x_path): + if decachunk_x_name[:1]!="." and os.path.isdir(decachunk_x_path): for decachunk_z_name in os.listdir(decachunk_x_path): decachunk_z_path = os.path.join(decachunk_x_path, decachunk_z_name) - if decachunk_z_path[:1]!="." and os.path.isdir(decachunk_z_path): + if decachunk_z_name[:1]!="." and os.path.isdir(decachunk_z_path): #for chunk_filename in decachunk_z_filenames: for chunk_filename in os.listdir(decachunk_z_path): chunk_path = os.path.join(decachunk_z_path, chunk_filename) diff --git a/minetestinfo.py b/minetestinfo.py index 8b34189..0d81149 100644 --- a/minetestinfo.py +++ b/minetestinfo.py @@ -35,6 +35,42 @@ os_name="linux" if (os.path.sep!="/"): os_name="windows" print("Windows detected") +game_path_from_gameid_dict = {} + +def get_gameid_from_game_path(path): + result = None + if path is not None: + game_conf_path = os.path.join(path, "game.conf") + if os.path.isfile(game_conf_path): + game_conf_dict = get_dict_from_conf_file(game_conf_path) + if "name" in game_conf_dict: + result = game_conf_dict["name"] + if (result is None) or (len(result.strip())<1): + result = None + print("WARNING: missing 'name' in game.conf in '"+path+"'") + else: + print("WARNING: no game.conf in '"+path+"'") + return result + +def get_game_path_from_gameid(gameid): + result = None + games_path = os.path.join(minetestinfo.get_var("shared_minetest_path"), "games") + if gameid is not None: + if os.path.isdir(games_path): + for this_game_name in os.listdir(games_path): + this_game_path = os.path.join(games_path, this_game_name) + #for decachunk_z_basepath, decachunk_z_dirnames, decachunk_z_filenames in os.walk(this_game_dirnames): + if this_game_name[:1]!="." and os.path.isdir(this_game_path): + this_gameid = get_gameid_from_game_path(this_game_path) + if this_gameid == gameid: + result = this_game_path + break + else: + print("ERROR: cannot get game_path from gameid since games path is not ready yet (or '"+games_path+"' does not exist for some other reason such as shared_minetest_path is wrong and does not contain games folder)") + else: + print("ERROR: can't try get_game_path_from_gameid since gameid param is None.") + return result + def init_minetestinfo(): if not minetestinfo.contains("www_minetest_path"): @@ -127,13 +163,13 @@ def load_world_and_mod_data(): # dirnames.remove_at(i) world_count = 0 for subdirname in dirnames: - print (" EXAMINING "+subdirname) + #print (" EXAMINING "+subdirname) if subdirname[0]!=".": world_count += 1 index = 0 world_number = 0 for subdirname in dirnames: - print (" EXAMINING "+subdirname) + print (" "+subdirname) if subdirname[0]!=".": #if (index == len(dirnames)-1): # skip first one because the one on my computer is big if (subdirname!="world") or (world_number==(world_count-1)): @@ -167,23 +203,36 @@ def load_world_and_mod_data(): 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"): + print("Using world at '"+minetestinfo.get_var("primary_world_path")+"'") + #game_name = None + #if minetestinfo.contains("game_path"): + # game_name = os.path.basename(minetestinfo.get_var("game_path")) + tmp_gameid = get_world_var("gameid") + tmp_game_gameid = get_gameid_from_game_path(minetestinfo.get_var("game_path")) + if tmp_game_gameid is not None: + #print("World gameid is "+str(tmp_gameid)) + print(" (game_path gameid is "+str(tmp_game_gameid)+")") + if tmp_gameid != tmp_game_gameid: is_world_changed = True - - if minetestinfo.contains("game_path") or is_world_changed: + + default_gameid = None + if (not minetestinfo.contains("game_path")) or is_world_changed: if minetestinfo.contains("game_path"): - default_game_name = minetestinfo.get_var("game_path") - if default_game_name is None: - default_game_name = get_world_var("gameid") - if default_game_name is not None: - print("gameid "+default_game_name+" detected in world.") + default_gameid = get_gameid_from_game_path(minetestinfo.get_var("game_path")) + if default_gameid is None: + default_gameid = get_world_var("gameid") + if default_gameid is not None: + explained_string = "" + if minetestinfo.contains("game_path"): + explained_string = " is different than game_path in "+minetestinfo._config_path+" so game_path must be confirmed" + print("") + print("gameid '"+default_gameid+"' detected in world"+explained_string+".") games_path = os.path.join(minetestinfo.get_var("shared_minetest_path"), "games") game_blacklist = list() # is only used if there is no game defined in world game_blacklist.append("minetest_game") games_list = list() - if default_game_name is None: + if default_gameid is None: if os.path.isdir(games_path): folder_path = games_path sub_names = os.listdir(folder_path) @@ -197,22 +246,28 @@ def load_world_and_mod_data(): if os.path.isdir(sub_path): if (sub_name[:1]!="."): if (sub_name != "minetest_game") or (real_index>=real_count-1): - if default_game_name is None: - default_game_name = sub_name - games_list.append(sub_name) + this_gameid = get_gameid_from_game_path(sub_path) + if default_gameid is None: + default_gameid = this_gameid + games_list.append(this_gameid) real_index += 1 - if default_game_name is not None: + if default_gameid is not None: path_msg = "" if len(games_list)>0: - path_msg = " (or game name listed above)" - for try_game_name in games_list: - print(" "+try_game_name) - minetestinfo.prepare_var("game_path",os.path.join(games_path,default_game_name),"game (your subgame) path"+path_msg) + path_msg = " (or gameid if listed above)" + for try_gameid in games_list: + print(" "+try_gameid) + minetestinfo.prepare_var("game_path",os.path.join(games_path,default_gameid),"game (your subgame) path"+path_msg) if (not os.path.isdir(minetestinfo.get_var("game_path"))): - try_path = os.path.join(games_path,minetestinfo.get_var("game_path")) - if os.path.isdir(try_path): - minetestinfo.set_var("game_path",try_path) + try_path = get_game_path_from_gameid(minetestinfo.get_var("game_path")) + if try_path is not None: + if os.path.isdir(try_path): + minetestinfo.set_var("game_path",try_path) + else: + try_path = os.path.join(games_path,minetestinfo.get_var("game_path")) + if os.path.isdir(try_path): + minetestinfo.set_var("game_path",try_path) mods_path = None if minetestinfo.contains("game_path") and os.path.isdir(minetestinfo.get_var("game_path")): @@ -231,23 +286,31 @@ def load_world_and_mod_data(): #mod_path = os.path.join(mods_path, mod_name) #if os.path.isdir(mod_path): - #if default_game is None: - # game_names = os.listdir world_mt_mapvars = None world_mt_mapvars_world_path = None def get_world_var(name): result = None global world_mt_mapvars_world_path - world_path = minetestinfo.get_var("world_path") + world_path = minetestinfo.get_var("primary_world_path") #world_mt_mapvars = None global world_mt_mapvars if world_mt_mapvars is None or (world_path != world_mt_mapvars_world_path): + if world_mt_mapvars is not None: + print("WARNING: reloading world.mt since was using '"+world_mt_mapvars_world_path+"' but now using '"+world_path+"'") world_mt_mapvars_world_path = world_path if world_path is not None: - world_mt_mapvars = get_dict_from_conf_file(os.path.join(world_path, "world.mt"),"=") - if (world_mt_mapvars is not None) and name in world_mt_mapvars: - result = world_mt_mapvars[name] + this_world_mt_path = os.path.join(world_path, "world.mt") + world_mt_mapvars = get_dict_from_conf_file(this_world_mt_path,"=") + if world_mt_mapvars is None: + print("ERROR: Tried to get world.mt settings but couldn't read '"+this_world_mt_path+"'") + else: + print("ERROR: Tried to get '"+name+"' but primary_world_path is None") + if (world_mt_mapvars is not None): + if name in world_mt_mapvars: + result = world_mt_mapvars[name] + else: + print("WARNING: Tried to get '"+name+"' from world but this world.mt does not have the variable") return result init_minetestinfo() diff --git a/unused/chunkymap_deprecated.php b/unused/chunkymap_deprecated.php new file mode 100644 index 0000000..d346d02 --- /dev/null +++ b/unused/chunkymap_deprecated.php @@ -0,0 +1,766 @@ +"; +} + +function echo_chunkymap_controls() { + global $chunkymap_view_x; + global $chunkymap_view_z; + global $chunkymap_view_zoom; + global $chunkymap_view_max_zoom; + global $chunkymap_view_min_zoom; + global $chunkymap_anchor_name; + global $chunkymap_change_zoom_multiplier; + $is_in=false; + $is_out=false; + $in_img_name = "zoom_in.png"; + $out_img_name = "zoom_out.png"; + + $in_zoom = $chunkymap_view_zoom; + if ($in_zoom<$chunkymap_view_max_zoom) { + $is_in=true; + $in_zoom = $chunkymap_view_zoom*$chunkymap_change_zoom_multiplier; + //echo "in:$in_zoom "; + } + else $in_img_name = "zoom_in_disabled.png"; + + $out_zoom = $chunkymap_view_zoom; + if ($out_zoom>$chunkymap_view_min_zoom) { + $is_out=true; + $out_zoom = ($chunkymap_view_zoom/$chunkymap_change_zoom_multiplier); + } + else $out_img_name = "zoom_out_disabled.png"; + + $zoom_clip = $chunkymap_view_max_zoom; + $found=false; + while ($zoom_clip>=$chunkymap_view_min_zoom) { + if ($out_zoom>$zoom_clip) { + $out_zoom=$zoom_clip*2; + $found=true; + break; + } + $zoom_clip = $zoom_clip/2; + } + if (!$found) { + $out_zoom=$chunkymap_view_min_zoom; + } + //if ($in_zoom>$chunkymap_view_max_zoom) { + // $in_zoom=$chunkymap_view_max_zoom; + // echo ""; + //} + //elseif ($in_zoom>200) $in_zoom=400; + //elseif ($in_zoom>100) $in_zoom=200; + //elseif ($in_zoom>75) $in_zoom=100; + //if ($in_zoom>50) $in_zoom=75; + //elseif ($in_zoom>25) $in_zoom=50; + //elseif ($in_zoom>12) $in_zoom=25; + //elseif ($in_zoom>4) $in_zoom=12; + //elseif ($in_zoom>2) $in_zoom=4; + //elseif ($in_zoom>1) $in_zoom=2; + //else $in_zoom=$chunkymap_view_min_zoom; // if ($in_zoom>1) $in_zoom=5; + //echo "in:$in_zoom "; + // if ($out_zoom<$chunkymap_view_min_zoom) $out_zoom=$chunkymap_view_min_zoom; + // elseif ($out_zoom<2) $out_zoom=1; + // elseif ($out_zoom<4) $out_zoom=2; + // elseif ($out_zoom<12) $out_zoom=4; + // elseif ($out_zoom<25) $out_zoom=12; + // elseif ($out_zoom<50) $out_zoom=25; + // elseif ($out_zoom<75) $out_zoom=50; + // elseif ($out_zoom<100) $out_zoom=75; + //elseif ($out_zoom<200) $out_zoom=100; + //elseif ($out_zoom<$chunkymap_view_max_zoom) $out_zoom=(int)($chunkymap_view_max_zoom/2); + //else $out_zoom=$chunkymap_view_max_zoom; //if ($out_zoom>76) $out_zoom=100; + $zoom_clip=$chunkymap_view_min_zoom; + $found=false; + while ($zoom_clip<=$chunkymap_view_max_zoom) { + if ($in_zoom<($zoom_clip*2)) { + $in_zoom=$zoom_clip; + $found=true; + break; + } + $zoom_clip = $zoom_clip * 2; + } + if (!$found) $in_zoom=$chunkymap_view_max_zoom; + + $in_html=""; + $out_html=""; + global $world_name; + $append_vars=""; + if (isset($world_name)) { + $append_vars.="&"."world_name=$world_name"; + } + if ($is_in) $in_html="$in_html"; + if ($is_out) $out_html="$out_html"; + echo $in_html; + echo $out_html; +} + +function echo_decachunk_table() { + 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 $decachunk_dot_and_ext; + global $decachunk_prefix_then_x_string; + global $td_decachunk_placeholder_content; + global $td_1px_placeholder_content; + global $chunkymap_camera_pan_delta; + + check_world(); + global $chunkymapdata_thisworld_path; + global $world_name; + global $chunkymapdata_worlds_path; + global $z_opener; + + 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; + + $decachunks_per_page = intval(6.0/$chunkymap_view_zoom); + if ($decachunks_per_page<1) { + $decachunks_per_page = 1; + } + $viewer_ratio = 16.0/9.0; + $world_camera_w = 6.0 * (1.0/$chunkymap_view_zoom); + $world_camera_h = $world_camera_w; + //$world_camera_w = (($decachunks_per_page*160.0)); + //$world_camera_h = (($decachunks_per_page*160.0)); + + $view_left = (($chunkymap_view_x)) - (($world_camera_w/2.0)); + $view_right = $view_left + $world_camera_w; + //z is cartesian still: + $view_top = (($chunkymap_view_z)) + (($world_camera_h/2.0)); + $view_bottom = $view_top - $world_camera_h; + + echo_chunkymap_anchor(); + echo_chunkymap_controls(); + echo "\r\n"; + echo " ".($chunkymap_view_zoom*100.0)."%\r\n";//(string)((int)($chunkymap_view_zoom*100+.5)); + //"chunkymapdata/images/compass_rose.png" + //"chunkymapdata/images/start.png" + $decachunky_min_x = get_decachunky_coord_from_location($view_left); + $decachunky_min_z = get_decachunky_coord_from_location($view_bottom); + $decachunky_max_x = get_decachunky_coord_from_location($view_right); + $decachunky_max_z = get_decachunky_coord_from_location($view_top); + $decachunky_count_x = $decachunky_max_x-$decachunky_min_x+1; + $decachunky_count_z = $decachunky_max_z-$decachunky_min_z+1; + + //#region local vars + $generated_yml_path = $chunkymapdata_thisworld_path."/generated.yml"; + //#endregion local vars + + $decachunky_z=$decachunky_max_z; + //echo "
"; + //echo "$decachunky_min_x:$decachunky_max_x,$decachunky_min_z:$decachunky_max_z
"; + 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_decachunk_placeholder_content".'".''.''."$td_decachunk_placeholder_content".'
".''.''."\r\n"; + echo ' '."\r\n"; + while ($decachunky_z>=$decachunky_min_z) { + echo ' '."\r\n"; + $decachunky_x=$decachunky_min_x; + $cell_perc_remaining=100; + while ($decachunky_x<=$decachunky_max_x) { + $decachunk_file_name=get_decachunk_image_name_from_decachunk($decachunky_x, $decachunky_z); + $decachunk_file_path=get_decachunk_folder_path_from_decachunk($decachunky_x, $decachunky_z).'/'.$decachunk_file_name; + $td_content=""; + if (is_file($decachunk_file_path)) { + $td_content=""; + } + $this_cell_perc=$cell_perc; + if ($cell_perc_remaining>=$this_cell_perc) { + echo " '."\r\n"; + //echo ' '."\r\n"; + $cell_perc_remaining-=$this_cell_perc; + } + $decachunky_x+=1; + } + if ($cell_perc_remaining>0) { + $td_content=$td_1px_placeholder_content; + echo " "."\r\n"; + } + echo ' '."\r\n"; + $decachunky_z-=1; + } + echo '
"."$td_content".''."$decachunky_x,$decachunky_z".'$td_content
'."\r\n"; + echo '
".''.'
'."$td_decachunk_placeholder_content".'".''.''."$td_decachunk_placeholder_content".'
'."\r\n"; +} + +//formerly echo_chunkymap_table +function echo_chunkymap_as_chunk_table($show_all_enable) { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL); + //error_reporting(-1); + + + global $is_echo_never_held; + $is_echo_never_held=true; + global $chunkymap_view_x; + global $chunkymap_view_z; + global $chunkymap_view_zoom; + global $chunkymap_view_max_zoom; + global $chunkymap_view_min_zoom; + global $chunkymapdata_path; + global $chunkymapdata_worlds_path; + global $map_dict; + global $is_verbose; + global $chunkymap_tile_original_w; + global $chunkymap_tile_original_h; + global $chunkymap_view_max_zoom; + global $world_name; + global $chunk_dot_and_ext; + global $z_opener; + global $dot_yaml; + + echo_chunkymap_anchor(); + echo_chunkymap_controls(); + echo " ".($chunkymap_view_zoom*100.0)."%";//(string)((int)($chunkymap_view_zoom*100+.5)); + + 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; + //$zoom_divisor = (int)(100/$chunkymap_view_zoom); + $chunk_assoc = array(); // used for storing players; and used for determining which chunks are on the edge, since not all generated map tiles are the same size (edge tile images are smaller and corner ones are smaller yet) + $chunk_count = 0; + $chunk_prefix_then_x_string="chunk_x"; + + + $min_chunkx = 0; + $min_chunkz = 0; + $max_chunkx = 0; + $max_chunkz = 0; + $chunks_per_page = (1.0/$chunkymap_view_zoom)*10; + + $world_camera_w = (($chunks_per_page*16.0)); + $world_camera_h = (($chunks_per_page*16.0)); + $view_left = (($chunkymap_view_x)) - (($world_camera_w/2.0)); + $view_right = $view_left + $world_camera_w; + //z is cartesian still: + $view_top = (($chunkymap_view_z)) + (($world_camera_h/2.0)); + $view_bottom = $view_top - $world_camera_h; + + if (!$show_all_enable) { + $min_chunkx=intval($view_left/$chunkymap_tile_original_w); + $max_chunkx=intval($view_right/$chunkymap_tile_original_w); + $min_chunkz=intval($view_bottom/$chunkymap_tile_original_w); + $max_chunkz=intval($view_top/$chunkymap_tile_original_w); + } + global $showplayers; + $players = array(); + $player_count = 0; + $character_icon_w=8; + $character_icon_h=8; + global $chunkymapdata_thisworld_path; + check_world(); + if (isset($world_name)) { + $generated_yml_path = $chunkymapdata_thisworld_path."/generated.yml"; + if (is_file($generated_yml_path)) { + $map_dict = get_dict_from_conf($generated_yml_path,":"); + } + else { + echo_error("Missing '".$generated_yml_path."'"); + } + if ($showplayers==true) { + $chunkymap_players_path = $chunkymapdata_thisworld_path."/players"; + if ($handle = opendir($chunkymap_players_path)) { + while (false !== ($file_name = readdir($handle))) { + if (substr($file_name, 0, 1) != ".") { + $file_lower = strtolower($file_name); + if (endsWith($file_lower, ".yml")) { + $player_id=substr($file_name,0,strlen($file_name)-4); //-4 for .yml + $file_path = $chunkymap_players_path."/".$file_name; + if (is_file($file_path)) { + $player_dict = get_dict_from_conf($file_path,":"); + } + else { + echo_error("Missing '$player_dict'"); + } + $player_dict["id"]=$player_id; + //$players[$player_count]=get_dict_from_conf($file_path); + //$players[$player_count]["id"]=$player_id; + //if (isset($player_dict["position"])) { + if (isset($player_dict["x"]) and isset($player_dict["z"])) { + //$tuple_string=trim($player_dict["position"]); + //if ( startsWith($tuple_string, "(") and endsWith($tuple_string, ")") ) { + // $tuple_string=substr($tuple_string,1,strlen($tuple_string)-2); + //} + //$coordinates = explode(",", $tuple_string); + //if (count($coordinates)==3) { + //$nonchunky_x=(int)$coordinates[0]; + //$nonchunky_z=(int)$coordinates[2]; + $nonchunky_x=(int)$player_dict["x"]; + $nonchunky_z=(int)$player_dict["z"]; + $x = (int)( $nonchunky_x/$chunkymap_tile_original_w ); + $z = (int)( $nonchunky_z/$chunkymap_tile_original_h ); + $chunk_luid = "x".$x."z".$z; + $rel_x = $nonchunky_x - ($x*$chunkymap_tile_original_w); + $rel_z = $nonchunky_z - ($z*$chunkymap_tile_original_h); + if (!isset($chunk_assoc[$chunk_luid])) { + $chunk_assoc[$chunk_luid] = array(); + } + if (!isset($chunk_assoc[$chunk_luid]["players"])) { + $chunk_assoc[$chunk_luid]["players"] = array(); + } + if (!isset($chunk_assoc[$chunk_luid]["players_count"])) { + $chunk_assoc[$chunk_luid]["players_count"] = 0; + } + //already checked for position in outer case + //DEPRECATED: $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "position" ] = $player_dict["position"]; + $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "x" ] = $player_dict["x"]; + $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "z" ] = $player_dict["z"]; + $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "rel_x" ] = $rel_x; + $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "rel_z" ] = $rel_z; + $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "file_path" ] = $file_path; + + if (isset($player_dict["name"])) { + $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "text" ] = $player_dict["name"]; + } + else { + $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "text" ] = $player_dict["id"]; + } + $chunk_assoc[$chunk_luid]["players_count"] += 1; + //} + //else { + // echo_error("Bad coordinates $tuple_string for player."); + //} + } + else { + echo_error("Missing player location in data: ".implode(" ",$player_dict)); + } + + //$player_count++; + } + } + } + closedir($handle); + } + } + + $chunkymap_markers_path = $chunkymapdata_thisworld_path."/markers"; + if ($handle = opendir($chunkymap_markers_path)) { + while (false !== ($file_name = readdir($handle))) { + if (substr($file_name, 0, 1) != ".") { + $file_name_lower = strtolower($file_name); + if (endsWith($file_name_lower, ".yml")) { + $file_path = $chunkymap_markers_path."/".$file_name; + $marker_vars = get_dict_from_conf($file_path, ":"); + $abs_pos = explode(",",$marker_vars["location"]); + if (count($abs_pos)==3) { + //convert from 3d to 2d: + $abs_pos[1]=$abs_pos[3]; + } + //$text = ""; + //if (isset($marker_vars["text"])) { + // $text = $marker_vars["text"]; + //} + if (count($abs_pos)>=2) { + $chunky_x = intval($abs_pos[0]/$chunkymap_tile_original_w); + $chunky_z = intval($abs_pos[1]/$chunkymap_tile_original_h); + $rel_x = intval($abs_pos[0]) - ($chunky_x*$chunkymap_tile_original_w); + $rel_z = intval($abs_pos[1]) - ($chunky_z*$chunkymap_tile_original_h); + $chunk_luid = 'x'.$chunky_x.'z'.$chunky_z; + if (!isset($chunk_assoc[$chunk_luid])) { + $chunk_assoc[$chunk_luid] = array(); + } + if (!isset($chunk_assoc[$chunk_luid]["markers"])) { + $chunk_assoc[$chunk_luid]["markers"] = array(); + } + if (!isset($chunk_assoc[$chunk_luid]["markers_count"])) { + $chunk_assoc[$chunk_luid]["markers_count"] = 0; + } + + $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "x" ] = $abs_pos[0]; + $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "z" ] = $abs_pos[1]; + $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "rel_x" ] = $rel_x; + $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "rel_z" ] = $rel_z; + if (isset($marker_vars["image"])) { + $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "image" ] = $marker_vars["image"]; + } + if (isset($marker_vars["text"])) { + $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "text" ] = $marker_vars["text"]; + } + + $chunk_assoc[$chunk_luid]["markers_count"] += 1; + } + else { + echo_error("Bad location in marker file '$file_path'"); + } + } + } + } + } + + + //if ($map_dict != null) { + // $min_chunkx = $map_dict["min_chunkx"]; + // $min_chunkz = $map_dict["min_chunkz"]; + // $max_chunkx = $map_dict["max_chunkx"]; + // $max_chunkz = $map_dict["max_chunkz"]; + //} + //else { + //echo "calculating range..."; + //NOTE: even though *min and *max could be known from $map_dict, build a dict of chunks in order to align images properly since they are not all the same size: + $chunks_16px_path = $chunkymapdata_thisworld_path.'/'."16px"; + if ($chunks_16px_handle = opendir($chunks_16px_path)) { + while (false !== ($decachunk_x_name = readdir($chunks_16px_handle))) { + $decachunk_x_path = $chunks_16px_path."/".$decachunk_x_name; + if ((substr($decachunk_x_name, 0, 1) != ".") and is_dir($decachunk_x_path)) { + $decachunk_x_handle = opendir($decachunk_x_path); + while (false !== ($decachunk_z_name = readdir($decachunk_x_handle))) { + $decachunk_folder_path = $decachunk_x_path."/".$decachunk_z_name; + if ((substr($decachunk_z_name, 0, 1) != ".") and is_dir($decachunk_folder_path)) { + $decachunk_z_handle = opendir($decachunk_folder_path); + while (false !== ($chunk_name = readdir($decachunk_z_handle))) { + $file_lower = strtolower($chunk_name); + if (endsWith($file_lower, $chunk_dot_and_ext) and startsWith($file_lower, $chunk_prefix_then_x_string)) { + $z_opener_index = strpos($file_lower, $z_opener, strlen($chunk_prefix_then_x_string)); + if ($z_opener_index !== false) { + $x_len = $z_opener_index - strlen($chunk_prefix_then_x_string); + $remaining_len = strlen($file_lower) - strlen($chunk_prefix_then_x_string) - $x_len - strlen($z_opener) - strlen($chunk_dot_and_ext); + $x = substr($file_lower, strlen($chunk_prefix_then_x_string), $x_len); + $z = substr($file_lower, $z_opener_index + strlen($z_opener), $remaining_len); + if (is_int_string($x) and is_int_string($z)) { + $chunk_luid = "x".$x."z".$z; + if (!isset($chunk_assoc[$chunk_luid])) { + $chunk_assoc[$chunk_luid] = array(); + } + $chunk_assoc[$chunk_luid]["is_rendered"] = true; + if ($is_verbose) echo "$chunk_luid,"; + if ($show_all_enable) { + if ($x<$min_chunkx) { + $min_chunkx=(int)$x; + } + if ($x>$max_chunkx) { + $max_chunkx=(int)$x; + } + if ($z<$min_chunkz) { + $min_chunkz=(int)$z; + } + if ($z>$max_chunkz) { + $max_chunkz=(int)$z; + } + } + } + else { + echo "misnamed chunk tile image '$chunk_name' had coordinates ".$x.",".$z." for x,z."; + } + } + } + } + closedir($decachunk_z_handle); + } + } + closedir($decachunk_x_handle); + } + } + if ($is_verbose) echo "checked all chunks."; + echo ""; + closedir($chunks_16px_handle); + } + else { + echo_error("could not open $chunks_16px_path"); + } + //} + + $x_count = $max_chunkx - $min_chunkx; + $z_count = $max_chunkz - $min_chunkz; + echo "\r\n"; + echo "
\r\n"; + //cellpadding="0" cellspacing="0" still needed for IE + echo_hold( " \r\n"); + $z = (int)$max_chunkz; + $scale=(float)$chunkymap_view_zoom; // no longer /100 + $zoomed_w=(int)((float)$chunkymap_tile_original_w*$scale+.5); + $zoomed_h=(int)((float)$chunkymap_tile_original_h*$scale+.5); + $genresult_suffix_then_dot_then_ext="_mapper_result.txt"; + + $minute=60; + $player_file_age_expired_max_seconds=20*$minute-1; + $player_file_age_idle_max_seconds=5*$minute-1; + $chunks_16px_path = $chunkymapdata_thisworld_path.'/'."16px"; + while ($z >= $min_chunkz) { + echo_hold( " \r\n"); + $x = (int)$min_chunkx; + while ($x <= $max_chunkx) { + $this_zoomed_w = $zoomed_w; + $this_zoomed_h = $zoomed_h; + + //$chunk_yaml_path = $chunkymapdata_thisworld_path.'/'.$chunk_yaml_name; + //$chunk_yaml_path = $chunks_16px_path.'/'. + $chunk_yaml_path = get_chunk_yaml_path_from_chunky_coords($x,$z); + //$chunk_genresult_name = $chunk_prefix_then_x_string.$x.$z_opener.$z.$genresult_suffix_then_dot_then_ext; + //$chunk_genresult_path = $chunkymapdata_thisworld_path.'/'.$chunk_img_name; + $td_style_suffix=""; + $element_align_style_suffix=""; + $alignment_comment=""; + //if (is_file($chunk_genresult_path)) { + // contains lines such as: + // Result image (w=80 h=64) will be written to chunk_x0z1.png + // ('PNG Region: ', [0, 64, 80, 128]) + // ('Pixels PerNode: ', 1) + // where PNG Region's list value is an exclusive rect ordered as x1, y1, x2, y2 + //$found_original_w = null; + //$found_original_h = null; + //$this_zoomed_w=(int)((float)$found_original_w*$scale+.5); + //this_zoomed_h=(int)((float)$found_original_h*$scale+.5); + //} + if (is_file($chunk_yaml_path)) { + // contains lines such as: + //is_marked_empty:False + //is_marked:True + //image_w:80 + //image_h:80 + //image_left:0 + //image_top:64 + //image_right:-80 + //image_bottom:-16 + // where if is_marked_empty, the remaining values don't exist + $expected_left = (int)$x * (int)$chunkymap_tile_original_w; + $expected_top = (int)$z * (int)$chunkymap_tile_original_h; + $expected_right = (int)$x + (int)$chunkymap_tile_original_w; + $expected_bottom = (int)$z + (int)$chunkymap_tile_original_h; + $chunk_dict = get_dict_from_conf($chunk_yaml_path,":"); + if (isset($chunk_dict["image_w"])) { + $this_zoomed_w=(int)((float)$chunk_dict["image_w"]*$scale+.5); + } + if (isset($chunk_dict["image_h"])) { + $this_zoomed_h=(int)((float)$chunk_dict["image_h"]*$scale+.5); + } + //TODO: use image_* to determine (if the doesn't touch certain sides of image_w x image_h rect, change the following accordingly) + if (isset($chunk_dict["image_left"])) { + if (isset($chunk_dict["image_right"])) { + if ( (int)$chunk_dict["image_left"] > $expected_left ) { + $td_style_suffix.="text-align:right;"; + //$alignment_comment.=""; + } + //elseif ( (int)$chunk_dict["image_right"] < $expected_right ) { + // $td_style_suffix.="text-align:left;"; + //} + else { + $td_style_suffix.="text-align:left;"; + //$alignment_comment.=""; + } + } + } + + //if (isset($chunk_dict["image_right"])) { + // if ( (int)$chunk_dict["image_right"] != $expected_right ) { + // $td_style_suffix.="text-align:left;"; + // } + // //else { + // // $td_style_suffix.="text-align:left;"; + // //} + //} + + if (isset($chunk_dict["image_top"])) { + if (isset($chunk_dict["image_bottom"])) { + if ( (int)$chunk_dict["image_top"] > $expected_top) { + $element_align_style_suffix.="vertical-align:bottom;"; + //$alignment_comment.=""; + } + //elseif ( (int)$chunk_dict["image_bottom"] < $expected_bottom) { + // $element_align_style_suffix.="vertical-align:top;"; + //} + else { + $element_align_style_suffix.="vertical-align:top;"; + //$alignment_comment.=""; + } + } + } + //if (isset($chunk_dict["image_bottom"])) { + // if ( (int)$chunk_dict["image_bottom"] != $expected_bottom) { + // $element_align_style_suffix.="vertical-align:top;"; + // } + // //else { + // // $element_align_style_suffix.="vertical-align:bottom;"; + // //} + //} + + //$element_align_style_suffix.="vertical-align:left;"; + } + + echo_hold( " \r\n"); + $x++; + } + echo_hold( " \r\n"); + echo_release(); + $z--; + } + echo "
"); + echo_hold("
"); //causes child's absolute position to be relative to this div's location, as per http://www.w3schools.com/css/tryit.asp?filename=trycss_position_absolute + $chunk_luid = "x".$x."z".$z; + $chunk_img_path = get_chunk_image_path_from_chunky_coords($x, $z); + if (is_file($chunk_img_path)) { + echo_hold( ""); + } + else { + //echo_hold( " "); + } + if (isset($chunk_assoc[$chunk_luid]["players_count"])) { + echo ""; + $nonprivate_name_beginning_char_count = 20; + + for ($player_count=0; $player_count<$chunk_assoc[$chunk_luid]["players_count"]; $player_count++) { + $rel_x = $chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["rel_x"]; + $rel_z = $chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["rel_z"]; + $is_expired=false; + $is_idle=false; + if (isset($chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["file_path"])) { + $last_player_update_time=filemtime($chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["file_path"]); + if (time()-$last_player_update_time > $player_file_age_expired_max_seconds) { + $is_expired=true; + } + elseif (time()-$last_player_update_time > $player_file_age_idle_max_seconds) { + $is_idle=true; + } + } + $text = $chunk_assoc[$chunk_luid]["players"][$player_count]["text"]; + if (strlen($chunk_assoc[$chunk_luid]["players"][$player_count]["text"])>$nonprivate_name_beginning_char_count) { + $text = substr($text, 0, $nonprivate_name_beginning_char_count)."*"; + } + //show head full size (not zoomed): + $zoomed_head_w=$character_icon_w;//(int)((float)$character_icon_w*$scale+.5); + $zoomed_head_h=$character_icon_h;//(int)((float)$character_icon_h*$scale+.5); + $rel_x -= (int)($zoomed_head_w/2); + $rel_z -= (int)($zoomed_head_h/2); + //$img_style="position:absolute; "; + $img_style=""; + $img_border_style="border: 1px solid white;"; + $text_style="color:white;"; + if ($is_expired==false) { + if ($is_idle==true) { + $img_border_style="border: 1px solid rgba(128,128,128,.5);"; + $img_style.="opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below + $text_style="color:white; opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below + } + echo_hold( "
$text
" ); + } + //$position_offset_x+=$character_icon_w; + } + } + else echo ""; + + if (isset($chunk_assoc[$chunk_luid]["markers_count"])) { + echo ""; + $nonprivate_name_beginning_char_count = 20; + + for ($marker_count=0; $marker_count<$chunk_assoc[$chunk_luid]["markers_count"]; $marker_count++) { + $rel_x = $chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["rel_x"]; + $rel_z = $chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["rel_z"]; + $is_expired=false; + $is_idle=false; + // if (isset($chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["file_path"])) { + // $last_marker_update_time=filemtime($chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["file_path"]); + // if (time()-$last_marker_update_time > $marker_file_age_expired_max_seconds) { + // $is_expired=true; + // } + // elseif (time()-$last_marker_update_time > $marker_file_age_idle_max_seconds) { + // $is_idle=true; + // } + // } + + $text = $chunk_assoc[$chunk_luid]["markers"][$marker_count]["text"]; + $image_path = ""; + if (isset($chunk_assoc[$chunk_luid]["markers"][$marker_count]["image"])) { + $image_path = $chunk_assoc[$chunk_luid]["markers"][$marker_count]["image"]; + } + if (strlen($chunk_assoc[$chunk_luid]["markers"][$marker_count]["text"])>$nonprivate_name_beginning_char_count) { + $text = substr($text, 0, $nonprivate_name_beginning_char_count)."*"; + } + //show head full size (not zoomed): + //$zoomed_head_w=$character_icon_w;//(int)((float)$character_icon_w*$scale+.5); + //$zoomed_head_h=$character_icon_h;//(int)((float)$character_icon_h*$scale+.5); + $zoomed_image_w=16; + $zoomed_image_h=16; + $rel_x -= (int)($zoomed_image_w/2); + $rel_z -= (int)($zoomed_image_h/2); + //$img_style="position:absolute; "; + $img_style=""; + $img_border_style=""; + //$img_border_style="border: 1px solid white;"; + $text_style="color:white;"; + if ($is_expired==false) { + if ($is_idle==true) { + $img_border_style=""; + //$img_border_style="border: 1px solid rgba(128,128,128,.5);"; + $img_style.="opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below + $text_style="color:white; opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below + } + echo_hold( "
$text
" ); + } + //$position_offset_x+=$character_icon_w; + } + } + else echo ""; + + //echo "
".$x.",0,".$z; + echo_hold($alignment_comment); + echo_hold("
"); + echo_hold( "
\r\n"; + echo "
\r\n"; + } + else { //not isset($world_name) + echo "

Choose world:

"; + echo ""; + } +} +?> \ No newline at end of file diff --git a/web/chunkymap.php b/web/chunkymap.php index 6990423..7354e38 100644 --- a/web/chunkymap.php +++ b/web/chunkymap.php @@ -50,7 +50,8 @@ $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_zoom_delta=1.5; +$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; @@ -64,6 +65,13 @@ $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"; @@ -100,6 +108,9 @@ function get_dict_from_conf($path, $assignment_operator) { } return $result; }//end get_dict_from_conf + + + $map_dict = null; //startsWith and endsWith are from: @@ -136,116 +147,7 @@ function set_chunkymap_view($set_chunkymap_view_x, $set_chunkymap_view_z, $set_c $chunkymap_view_z = $set_chunkymap_view_z; $chunkymap_view_zoom = $set_chunkymap_view_zoom; } -function echo_chunkymap_anchor() { - global $chunkymap_anchor_name; - echo ""; -} -function echo_chunkymap_controls() { - global $chunkymap_view_x; - global $chunkymap_view_z; - global $chunkymap_view_zoom; - global $chunkymap_view_max_zoom; - global $chunkymap_view_min_zoom; - global $chunkymap_anchor_name; - $is_in=false; - $is_out=false; - $in_img_name = "zoom-in.png"; - $out_img_name = "zoom-out.png"; - $in_zoom = $chunkymap_view_zoom; - if ($in_zoom<$chunkymap_view_max_zoom) { - $is_in=true; - $in_zoom = $chunkymap_view_zoom*2.0; - //echo "in:$in_zoom "; - } - else $in_img_name = "zoom-in_disabled.png"; - - $out_zoom = $chunkymap_view_zoom; - if ($out_zoom>$chunkymap_view_min_zoom) { - $is_out=true; - $out_zoom = ($chunkymap_view_zoom/2.0); - } - else $out_img_name = "zoom-out_disabled.png"; - - $zoom_clip = $chunkymap_view_max_zoom; - $found=false; - while ($zoom_clip>=$chunkymap_view_min_zoom) { - if ($out_zoom>$zoom_clip) { - $out_zoom=$zoom_clip*2; - $found=true; - break; - } - $zoom_clip = $zoom_clip/2; - } - if (!$found) { - $out_zoom=$chunkymap_view_min_zoom; - } - //if ($in_zoom>$chunkymap_view_max_zoom) { - // $in_zoom=$chunkymap_view_max_zoom; - // echo ""; - //} - //elseif ($in_zoom>200) $in_zoom=400; - //elseif ($in_zoom>100) $in_zoom=200; - //elseif ($in_zoom>75) $in_zoom=100; - //if ($in_zoom>50) $in_zoom=75; - //elseif ($in_zoom>25) $in_zoom=50; - //elseif ($in_zoom>12) $in_zoom=25; - //elseif ($in_zoom>4) $in_zoom=12; - //elseif ($in_zoom>2) $in_zoom=4; - //elseif ($in_zoom>1) $in_zoom=2; - //else $in_zoom=$chunkymap_view_min_zoom; // if ($in_zoom>1) $in_zoom=5; - //echo "in:$in_zoom "; - // if ($out_zoom<$chunkymap_view_min_zoom) $out_zoom=$chunkymap_view_min_zoom; - // elseif ($out_zoom<2) $out_zoom=1; - // elseif ($out_zoom<4) $out_zoom=2; - // elseif ($out_zoom<12) $out_zoom=4; - // elseif ($out_zoom<25) $out_zoom=12; - // elseif ($out_zoom<50) $out_zoom=25; - // elseif ($out_zoom<75) $out_zoom=50; - // elseif ($out_zoom<100) $out_zoom=75; - //elseif ($out_zoom<200) $out_zoom=100; - //elseif ($out_zoom<$chunkymap_view_max_zoom) $out_zoom=(int)($chunkymap_view_max_zoom/2); - //else $out_zoom=$chunkymap_view_max_zoom; //if ($out_zoom>76) $out_zoom=100; - $zoom_clip=$chunkymap_view_min_zoom; - $found=false; - while ($zoom_clip<=$chunkymap_view_max_zoom) { - if ($in_zoom<($zoom_clip*2)) { - $in_zoom=$zoom_clip; - $found=true; - break; - } - $zoom_clip = $zoom_clip * 2; - } - if (!$found) $in_zoom=$chunkymap_view_max_zoom; - - $in_html=""; - $out_html=""; - global $world_name; - $append_vars=""; - if (isset($world_name)) { - $append_vars.="&"."world_name=$world_name"; - } - if ($is_in) $in_html="$in_html"; - if ($is_out) $out_html="$out_html"; - echo $in_html; - echo $out_html; -} - -$is_echo_never_held=false; -$held_echos=""; -function echo_hold($val) { - global $is_echo_never_held; - global $held_echos; - if (!$is_echo_never_held) $held_echos.="$val"; - else echo "$val"; -} - -function echo_release() { - global $held_echos; - global $is_echo_never_held; - if (!$is_echo_never_held) echo "$held_echos"; - $held_echos=""; -} function echo_map_heading_text() { echo "Chunkymap"; //echo "Map of "; @@ -321,6 +223,25 @@ function get_decachunk_image_name_from_decachunk($x, $z) { 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"; @@ -332,1066 +253,439 @@ function get_javascript_bool_value($this_bool) { //chunk_mode_enable: shows chunk png images instead of decachunk jpg images (slower) //debug_mode_enable: draws colored rectangles based on yml files instead of drawing images -function echo_chunkymap_canvas($chunk_mode_enable, $debug_mode_enable) { +function echo_chunkymap_canvas($chunk_mode_enable, $debug_mode_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_zoom_delta; + global $chunkymap_change_zoom_multiplier; + global $chunkymap_camera_pan_delta; + global $world_name; check_world(); - $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 (isset($world_name)) { + $chunks_per_tile_x_count = 10; + $chunks_per_tile_z_count = 10; - 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; - - $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; - - echo ' '; - echo ' - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - $this_tiley_z=$max_tiley_z; //start at max since screen is inverted cartesian - if ($debug_mode_enable!==true) { - //this table is hidden when javascript runs successfully, but it is also a map though not very functional - 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; - 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"; + function process_view_change() { + //NOTE: this should be exactly the same math as php uses to make sure there are the same #of tiles displayed as were loaded by php + if (current_w>current_h) { + world_camera_w = (800/tile_w) * (1.0/chunkymap_view_zoom); + world_camera_h = world_camera_w/current_ratio; } - } - 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"; + else { + world_camera_h = (800/tile_h) * (1.0/chunkymap_view_zoom); + world_camera_w = world_camera_h*current_ratio; } } - echo " \r\n"; - $this_tiley_x++; - } - echo " \r\n"; - $this_tiley_z-=1; - } - 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) -} - -function echo_decachunk_table() { - 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 $decachunk_dot_and_ext; - global $decachunk_prefix_then_x_string; - - check_world(); - global $chunkymapdata_thisworld_path; - global $world_name; - global $chunkymapdata_worlds_path; - global $z_opener; - - 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; - - $decachunks_per_page = intval(6.0/$chunkymap_view_zoom); - if ($decachunks_per_page<1) { - $decachunks_per_page = 1; - } - $viewer_ratio = 16.0/9.0; - $world_camera_w = 6.0 * (1.0/$chunkymap_view_zoom); - $world_camera_h = $world_camera_w; - //$world_camera_w = (($decachunks_per_page*160.0)); - //$world_camera_h = (($decachunks_per_page*160.0)); - - $view_left = (($chunkymap_view_x)) - (($world_camera_w/2.0)); - $view_right = $view_left + $world_camera_w; - //z is cartesian still: - $view_top = (($chunkymap_view_z)) + (($world_camera_h/2.0)); - $view_bottom = $view_top - $world_camera_h; - - echo_chunkymap_anchor(); - echo_chunkymap_controls(); - echo "\r\n"; - echo " ".($chunkymap_view_zoom*100.0)."%\r\n";//(string)((int)($chunkymap_view_zoom*100+.5)); - //"chunkymapdata/images/compass-rose.png" - //"chunkymapdata/images/start.png" - $decachunky_min_x = get_decachunky_coord_from_location($view_left); - $decachunky_min_z = get_decachunky_coord_from_location($view_bottom); - $decachunky_max_x = get_decachunky_coord_from_location($view_right); - $decachunky_max_z = get_decachunky_coord_from_location($view_top); - $decachunky_count_x = $decachunky_max_x-$decachunky_min_x+1; - $decachunky_count_z = $decachunky_max_z-$decachunky_min_z+1; - - //#region local vars - $generated_yml_path = $chunkymapdata_thisworld_path."/generated.yml"; - //#endregion local vars - - $decachunky_z=$decachunky_max_z; - //echo "
"; - //echo "$decachunky_min_x:$decachunky_max_x,$decachunky_min_z:$decachunky_max_z
"; - $td_placeholder_content=""; - $td_1px_placeholder_content=""; - 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_placeholder_content".'".''.''."$td_placeholder_content".'
".''.''."\r\n"; - echo ' '."\r\n"; - while ($decachunky_z>=$decachunky_min_z) { - echo ' '."\r\n"; - $decachunky_x=$decachunky_min_x; - $cell_perc_remaining=100; - while ($decachunky_x<=$decachunky_max_x) { - $decachunk_file_name=get_decachunk_image_name_from_decachunk($decachunky_x, $decachunky_z); - $decachunk_file_path=get_decachunk_folder_path_from_decachunk($decachunky_x, $decachunky_z).'/'.$decachunk_file_name; - $td_content=""; - if (is_file($decachunk_file_path)) { - $td_content=""; - } - $this_cell_perc=$cell_perc; - if ($cell_perc_remaining>=$this_cell_perc) { - echo " '."\r\n"; - //echo ' '."\r\n"; - $cell_perc_remaining-=$this_cell_perc; - } - $decachunky_x+=1; - } - if ($cell_perc_remaining>0) { - $td_content=$td_1px_placeholder_content; - echo " "."\r\n"; - } - echo ' '."\r\n"; - $decachunky_z-=1; - } - echo '
"."$td_content".''."$decachunky_x,$decachunky_z".'$td_content
'."\r\n"; - echo '
".''.'
'."$td_placeholder_content".'".''.''."$td_placeholder_content".'
'."\r\n"; -} - -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; - } + + function process_resize(ctx) { + //var ctx = my_canvas.getContext("2d"); + ctx.canvas.width = window.innerWidth; + ctx.canvas.height = window.innerHeight; + //current_w = ctx.canvas.width; + //current_h = ctx.canvas.width; + current_w = window.innerWidth; + current_h = window.innerHeight; + current_ratio = current_w/current_h; + + //if (ctx.canvas.height$chunkymap_view_max_zoom) $chunkymap_view_zoom = $chunkymap_view_max_zoom; - //$zoom_divisor = (int)(100/$chunkymap_view_zoom); - $chunk_assoc = array(); // used for storing players; and used for determining which chunks are on the edge, since not all generated map tiles are the same size (edge tile images are smaller and corner ones are smaller yet) - $chunk_count = 0; - $chunk_prefix_then_x_string="chunk_x"; - - - $min_chunkx = 0; - $min_chunkz = 0; - $max_chunkx = 0; - $max_chunkz = 0; - $chunks_per_page = (1.0/$chunkymap_view_zoom)*10; - - $world_camera_w = (($chunks_per_page*16.0)); - $world_camera_h = (($chunks_per_page*16.0)); - $view_left = (($chunkymap_view_x)) - (($world_camera_w/2.0)); - $view_right = $view_left + $world_camera_w; - //z is cartesian still: - $view_top = (($chunkymap_view_z)) + (($world_camera_h/2.0)); - $view_bottom = $view_top - $world_camera_h; - - if (!$show_all_enable) { - $min_chunkx=intval($view_left/$chunkymap_tile_original_w); - $max_chunkx=intval($view_right/$chunkymap_tile_original_w); - $min_chunkz=intval($view_bottom/$chunkymap_tile_original_w); - $max_chunkz=intval($view_top/$chunkymap_tile_original_w); - } - global $showplayers; - $players = array(); - $player_count = 0; - $character_icon_w=8; - $character_icon_h=8; - global $chunkymapdata_thisworld_path; - check_world(); - if (isset($world_name)) { - $generated_yml_path = $chunkymapdata_thisworld_path."/generated.yml"; - if (is_file($generated_yml_path)) { - $map_dict = get_dict_from_conf($generated_yml_path,":"); - } - else { - echo_error("Missing '".$generated_yml_path."'"); - } - if ($showplayers==true) { - $chunkymap_players_path = $chunkymapdata_thisworld_path."/players"; - if ($handle = opendir($chunkymap_players_path)) { - while (false !== ($file_name = readdir($handle))) { - if (substr($file_name, 0, 1) != ".") { - $file_lower = strtolower($file_name); - if (endsWith($file_lower, ".yml")) { - $player_id=substr($file_name,0,strlen($file_name)-4); //-4 for .yml - $file_path = $chunkymap_players_path."/".$file_name; - if (is_file($file_path)) { - $player_dict = get_dict_from_conf($file_path,":"); - } - else { - echo_error("Missing '$player_dict'"); - } - $player_dict["id"]=$player_id; - //$players[$player_count]=get_dict_from_conf($file_path); - //$players[$player_count]["id"]=$player_id; - //if (isset($player_dict["position"])) { - if (isset($player_dict["x"]) and isset($player_dict["z"])) { - //$tuple_string=trim($player_dict["position"]); - //if ( startsWith($tuple_string, "(") and endsWith($tuple_string, ")") ) { - // $tuple_string=substr($tuple_string,1,strlen($tuple_string)-2); - //} - //$coordinates = explode(",", $tuple_string); - //if (count($coordinates)==3) { - //$nonchunky_x=(int)$coordinates[0]; - //$nonchunky_z=(int)$coordinates[2]; - $nonchunky_x=(int)$player_dict["x"]; - $nonchunky_z=(int)$player_dict["z"]; - $x = (int)( $nonchunky_x/$chunkymap_tile_original_w ); - $z = (int)( $nonchunky_z/$chunkymap_tile_original_h ); - $chunk_luid = "x".$x."z".$z; - $rel_x = $nonchunky_x - ($x*$chunkymap_tile_original_w); - $rel_z = $nonchunky_z - ($z*$chunkymap_tile_original_h); - if (!isset($chunk_assoc[$chunk_luid])) { - $chunk_assoc[$chunk_luid] = array(); - } - if (!isset($chunk_assoc[$chunk_luid]["players"])) { - $chunk_assoc[$chunk_luid]["players"] = array(); - } - if (!isset($chunk_assoc[$chunk_luid]["players_count"])) { - $chunk_assoc[$chunk_luid]["players_count"] = 0; - } - //already checked for position in outer case - //DEPRECATED: $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "position" ] = $player_dict["position"]; - $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "x" ] = $player_dict["x"]; - $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "z" ] = $player_dict["z"]; - $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "rel_x" ] = $rel_x; - $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "rel_z" ] = $rel_z; - $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "file_path" ] = $file_path; - - if (isset($player_dict["name"])) { - $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "text" ] = $player_dict["name"]; - } - else { - $chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "text" ] = $player_dict["id"]; - } - $chunk_assoc[$chunk_luid]["players_count"] += 1; - //} - //else { - // echo_error("Bad coordinates $tuple_string for player."); - //} - } - else { - echo_error("Missing player location in data: ".implode(" ",$player_dict)); - } - - //$player_count++; - } - } + + var bw_count = 0; + var bawidgets = new Array(); + var last_bawidget = null; + function add_bawidget(x, y, width, height, this_onclick, name) { + this_widget = Array(); + this_widget["x"] = x; + this_widget["y"] = y; + this_widget["width"] = width; + this_widget["height"] = height; + this_widget["click_event"] = this_onclick; + this_widget["name"] = name; + + this_widget["image"] = null; + this_widget["text"] = null; + bawidgets[bw_count] = this_widget; + last_bawidget = this_widget; + bw_count++; } - closedir($handle); - } - } - - $chunkymap_markers_path = $chunkymapdata_thisworld_path."/markers"; - if ($handle = opendir($chunkymap_markers_path)) { - while (false !== ($file_name = readdir($handle))) { - if (substr($file_name, 0, 1) != ".") { - $file_name_lower = strtolower($file_name); - if (endsWith($file_name_lower, ".yml")) { - $file_path = $chunkymap_markers_path."/".$file_name; - $marker_vars = get_dict_from_conf($file_path, ":"); - $abs_pos = explode(",",$marker_vars["location"]); - if (count($abs_pos)==3) { - //convert from 3d to 2d: - $abs_pos[1]=$abs_pos[3]; - } - //$text = ""; - //if (isset($marker_vars["text"])) { - // $text = $marker_vars["text"]; - //} - if (count($abs_pos)>=2) { - $chunky_x = intval($abs_pos[0]/$chunkymap_tile_original_w); - $chunky_z = intval($abs_pos[1]/$chunkymap_tile_original_h); - $rel_x = intval($abs_pos[0]) - ($chunky_x*$chunkymap_tile_original_w); - $rel_z = intval($abs_pos[1]) - ($chunky_z*$chunkymap_tile_original_h); - $chunk_luid = 'x'.$chunky_x.'z'.$chunky_z; - if (!isset($chunk_assoc[$chunk_luid])) { - $chunk_assoc[$chunk_luid] = array(); - } - if (!isset($chunk_assoc[$chunk_luid]["markers"])) { - $chunk_assoc[$chunk_luid]["markers"] = array(); - } - if (!isset($chunk_assoc[$chunk_luid]["markers_count"])) { - $chunk_assoc[$chunk_luid]["markers_count"] = 0; - } - - $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "x" ] = $abs_pos[0]; - $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "z" ] = $abs_pos[1]; - $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "rel_x" ] = $rel_x; - $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "rel_z" ] = $rel_z; - if (isset($marker_vars["image"])) { - $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "image" ] = $marker_vars["image"]; - } - if (isset($marker_vars["text"])) { - $chunk_assoc[$chunk_luid][ "markers" ][ $chunk_assoc[$chunk_luid]["markers_count"] ][ "text" ] = $marker_vars["text"]; - } - - $chunk_assoc[$chunk_luid]["markers_count"] += 1; - } - else { - echo_error("Bad location in marker file '$file_path'"); - } - } + function contains_coords(bawidget, cursor_x, cursor_y) { + right = bawidget.x+bawidget.width; + bottom = bawidget.y+bawidget.height; + return cursor_x>=bawidget.x && cursor_y>=bawidget.y && cursor_x$max_chunkx) { - $max_chunkx=(int)$x; - } - if ($z<$min_chunkz) { - $min_chunkz=(int)$z; - } - if ($z>$max_chunkz) { - $max_chunkz=(int)$z; - } - } - } - else { - echo "misnamed chunk tile image '$chunk_name' had coordinates ".$x.",".$z." for x,z."; - } - } - } - } - closedir($decachunk_z_handle); - } + function click_if_contains(bawidget, cursor_x, cursor_y) { + if (contains_coords(bawidget, cursor_x, cursor_y)) { + if (bawidget["click_event"] != null) { + bawidget["click_event"](); } - closedir($decachunk_x_handle); } } - if ($is_verbose) echo "checked all chunks."; - echo ""; - closedir($chunks_16px_handle); - } - else { - echo_error("could not open $chunks_16px_path"); - } - //} - - $x_count = $max_chunkx - $min_chunkx; - $z_count = $max_chunkz - $min_chunkz; - echo "\r\n"; - echo "
\r\n"; - //cellpadding="0" cellspacing="0" still needed for IE - echo_hold( " \r\n"); - $z = (int)$max_chunkz; - $scale=(float)$chunkymap_view_zoom; // no longer /100 - $zoomed_w=(int)((float)$chunkymap_tile_original_w*$scale+.5); - $zoomed_h=(int)((float)$chunkymap_tile_original_h*$scale+.5); - $genresult_suffix_then_dot_then_ext="_mapper_result.txt"; - - $minute=60; - $player_file_age_expired_max_seconds=20*$minute-1; - $player_file_age_idle_max_seconds=5*$minute-1; - $chunks_16px_path = $chunkymapdata_thisworld_path.'/'."16px"; - while ($z >= $min_chunkz) { - echo_hold( " \r\n"); - $x = (int)$min_chunkx; - while ($x <= $max_chunkx) { - $this_zoomed_w = $zoomed_w; - $this_zoomed_h = $zoomed_h; - - //$chunk_yaml_path = $chunkymapdata_thisworld_path.'/'.$chunk_yaml_name; - //$chunk_yaml_path = $chunks_16px_path.'/'. - $chunk_yaml_path = get_chunk_yaml_path_from_chunky_coords($x,$z); - //$chunk_genresult_name = $chunk_prefix_then_x_string.$x.$z_opener.$z.$genresult_suffix_then_dot_then_ext; - //$chunk_genresult_path = $chunkymapdata_thisworld_path.'/'.$chunk_img_name; - $td_style_suffix=""; - $element_align_style_suffix=""; - $alignment_comment=""; - //if (is_file($chunk_genresult_path)) { - // contains lines such as: - // Result image (w=80 h=64) will be written to chunk_x0z1.png - // ('PNG Region: ', [0, 64, 80, 128]) - // ('Pixels PerNode: ', 1) - // where PNG Region's list value is an exclusive rect ordered as x1, y1, x2, y2 - //$found_original_w = null; - //$found_original_h = null; - //$this_zoomed_w=(int)((float)$found_original_w*$scale+.5); - //this_zoomed_h=(int)((float)$found_original_h*$scale+.5); - //} - if (is_file($chunk_yaml_path)) { - // contains lines such as: - //is_marked_empty:False - //is_marked:True - //image_w:80 - //image_h:80 - //image_left:0 - //image_top:64 - //image_right:-80 - //image_bottom:-16 - // where if is_marked_empty, the remaining values don't exist - $expected_left = (int)$x * (int)$chunkymap_tile_original_w; - $expected_top = (int)$z * (int)$chunkymap_tile_original_h; - $expected_right = (int)$x + (int)$chunkymap_tile_original_w; - $expected_bottom = (int)$z + (int)$chunkymap_tile_original_h; - $chunk_dict = get_dict_from_conf($chunk_yaml_path,":"); - if (isset($chunk_dict["image_w"])) { - $this_zoomed_w=(int)((float)$chunk_dict["image_w"]*$scale+.5); + + function process_zoom_change() { + var zoom_in_img = null; + var zoom_out_img = null; + var zoom_in_img_disabled = null; + var zoom_out_img_disabled = null; + var tmp_zoom_out_ptr = zoom_out; + var tmp_zoom_in_ptr = zoom_in; + + if (chunkymap_view_zoomchunkymap_view_max_zoom) {chunkymap_view_zoom = chunkymap_view_max_zoom;} + + if (chunkymap_view_zoom==chunkymap_view_min_zoom) { + zoom_out_img = document.getElementById("zoom_out_disabled"); + tmp_zoom_out_ptr = null; } - if (isset($chunk_dict["image_h"])) { - $this_zoomed_h=(int)((float)$chunk_dict["image_h"]*$scale+.5); + else { + zoom_out_img = document.getElementById("zoom_out"); } - //TODO: use image_* to determine (if the doesn't touch certain sides of image_w x image_h rect, change the following accordingly) - if (isset($chunk_dict["image_left"])) { - if (isset($chunk_dict["image_right"])) { - if ( (int)$chunk_dict["image_left"] > $expected_left ) { - $td_style_suffix.="text-align:right;"; - //$alignment_comment.=""; - } - //elseif ( (int)$chunk_dict["image_right"] < $expected_right ) { - // $td_style_suffix.="text-align:left;"; - //} - else { - $td_style_suffix.="text-align:left;"; - //$alignment_comment.=""; - } - } + if (chunkymap_view_zoom==chunkymap_view_max_zoom) { + zoom_in_img = document.getElementById("zoom_in_disabled"); + tmp_zoom_in_ptr = null; } - - //if (isset($chunk_dict["image_right"])) { - // if ( (int)$chunk_dict["image_right"] != $expected_right ) { - // $td_style_suffix.="text-align:left;"; - // } - // //else { - // // $td_style_suffix.="text-align:left;"; - // //} - //} - - if (isset($chunk_dict["image_top"])) { - if (isset($chunk_dict["image_bottom"])) { - if ( (int)$chunk_dict["image_top"] > $expected_top) { - $element_align_style_suffix.="vertical-align:bottom;"; - //$alignment_comment.=""; - } - //elseif ( (int)$chunk_dict["image_bottom"] < $expected_bottom) { - // $element_align_style_suffix.="vertical-align:top;"; - //} - else { - $element_align_style_suffix.="vertical-align:top;"; - //$alignment_comment.=""; - } - } + else { + zoom_in_img = document.getElementById("zoom_in"); } - //if (isset($chunk_dict["image_bottom"])) { - // if ( (int)$chunk_dict["image_bottom"] != $expected_bottom) { - // $element_align_style_suffix.="vertical-align:top;"; - // } - // //else { - // // $element_align_style_suffix.="vertical-align:bottom;"; - // //} - //} - - //$element_align_style_suffix.="vertical-align:left;"; - } - - echo_hold( "
"); - echo_hold("
"); //causes child's absolute position to be relative to this div's location, as per http://www.w3schools.com/css/tryit.asp?filename=trycss_position_absolute - $chunk_luid = "x".$x."z".$z; - $chunk_img_path = get_chunk_image_path_from_chunky_coords($x, $z); - if (is_file($chunk_img_path)) { - echo_hold( ""); - } - else { - //echo_hold( " "); + location_label["text"] = chunkymap_view_x+","+chunkymap_view_z; + + zoom_label_value=chunkymap_view_zoom*100; + if (zoom_label_value>1) { + zoom_label_value = Math.round(zoom_label_value, 1); + } + else { + zoom_label_value = Math.round(zoom_label_value, 7); + } + zoom_label["text"]=zoom_label_value+"%"; + + zoom_in_button["click_event"]=tmp_zoom_in_ptr; + zoom_in_button["image"]=zoom_in_img; + zoom_out_button["click_event"]=tmp_zoom_out_ptr; + zoom_out_button["image"]=zoom_out_img; } - if (isset($chunk_assoc[$chunk_luid]["players_count"])) { - echo ""; - $nonprivate_name_beginning_char_count = 20; - - for ($player_count=0; $player_count<$chunk_assoc[$chunk_luid]["players_count"]; $player_count++) { - $rel_x = $chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["rel_x"]; - $rel_z = $chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["rel_z"]; - $is_expired=false; - $is_idle=false; - if (isset($chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["file_path"])) { - $last_player_update_time=filemtime($chunk_assoc[$chunk_luid][ "players" ][ $player_count ]["file_path"]); - if (time()-$last_player_update_time > $player_file_age_expired_max_seconds) { - $is_expired=true; - } - elseif (time()-$last_player_update_time > $player_file_age_idle_max_seconds) { - $is_idle=true; - } - } - $text = $chunk_assoc[$chunk_luid]["players"][$player_count]["text"]; - if (strlen($chunk_assoc[$chunk_luid]["players"][$player_count]["text"])>$nonprivate_name_beginning_char_count) { - $text = substr($text, 0, $nonprivate_name_beginning_char_count)."*"; + + + function draw_map() { + process_zoom_change(); + var r = 0; //border + var g = 0; //exists + var b = 0; // + + var alert_string=""; + if (current_ratio==null) { + alert_string+="current_ratio is null; "; + } + if (font_string==null) { + alert_string+="font_string is null; "; + } + if (current_w==null) { + alert_w+="current_ratio is null; "; + } + if (current_w==null) { + alert_w+="current_ratio is null; "; + } + if (current_ratio==null) { + alert_string+="current_ratio is null; "; + } + if (alert_string.length>0) { + alert(alert_string); + } + + var ctx = my_canvas.getContext("2d"); + process_resize(ctx); + + ctx.fillStyle = "black"; + ctx.fillRect(0,0,ctx.canvas.width,ctx.canvas.height); + + ctx.fillStyle = "white"; + ctx.rect(20,20,150,100); + ctx.stroke(); + + //size_1pt_pixel_count = ctx.canvas.height/600.0; + var bw_index = 0; + + + + for (i=0; i$text
" ); + else if (this_img != null) { + ctx.drawImage(this_img, this_widget.x, this_widget.y, this_widget.width, this_widget.height); } - //$position_offset_x+=$character_icon_w; } } - else echo ""; - - if (isset($chunk_assoc[$chunk_luid]["markers_count"])) { - echo ""; - $nonprivate_name_beginning_char_count = 20; - - for ($marker_count=0; $marker_count<$chunk_assoc[$chunk_luid]["markers_count"]; $marker_count++) { - $rel_x = $chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["rel_x"]; - $rel_z = $chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["rel_z"]; - $is_expired=false; - $is_idle=false; - // if (isset($chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["file_path"])) { - // $last_marker_update_time=filemtime($chunk_assoc[$chunk_luid][ "markers" ][ $marker_count ]["file_path"]); - // if (time()-$last_marker_update_time > $marker_file_age_expired_max_seconds) { - // $is_expired=true; - // } - // elseif (time()-$last_marker_update_time > $marker_file_age_idle_max_seconds) { - // $is_idle=true; - // } - // } - - $text = $chunk_assoc[$chunk_luid]["markers"][$marker_count]["text"]; - $image_path = ""; - if (isset($chunk_assoc[$chunk_luid]["markers"][$marker_count]["image"])) { - $image_path = $chunk_assoc[$chunk_luid]["markers"][$marker_count]["image"]; + + window.onload = function() { + my_canvas.onclick = function(event) { + for (i=0; i$nonprivate_name_beginning_char_count) { - $text = substr($text, 0, $nonprivate_name_beginning_char_count)."*"; + }; + + var ctx = my_canvas.getContext("2d"); + process_resize(ctx); + + var pen_x = size_1em_pixel_count; + var pen_y = size_1em_pixel_count; + var tmp_w = null; + var tmp_h = null; + var compass_rose_w = size_1em_pixel_count*5; + + + + + //LOCATION LABEL (no click): + bw_index = add_bawidget(pen_x+compass_rose_w/4, pen_y, tmp_w, tmp_h, null, "location_label"); + location_label = last_bawidget; + //done on each draw: last_bawidget["text"] = + + pen_y += size_1em_pixel_count + padding_h; + + //COMPASS ROSE (no click): + var compass_rose_img = document.getElementById("compass-rose"); + var this_h_ratio = compass_rose_img.height/compass_rose_img.width; + tmp_w = compass_rose_w; + tmp_h = tmp_w*this_h_ratio; + bw_index = add_bawidget(pen_x-padding_w, pen_y, tmp_w, tmp_h, null, "compass-rose"); + last_bawidget["image"] = compass_rose_img; + compass_rose_img.style.visibility="hidden"; + pen_y += last_bawidget.height+padding_h; + + //ZOOM LABEL (no click): + bw_index = add_bawidget(pen_x+compass_rose_w/5, pen_y, tmp_w, tmp_h, null, "zoom_label"); + zoom_label = last_bawidget; + //done on each draw: last_bawidget["text"] = (chunkymap_view_zoom*100)+"%" + pen_y += size_1em_pixel_count + padding_h; + + //ZOOM IN: + var zoom_in_img = document.getElementById("zoom_in"); + this_h_ratio = zoom_in_img.height/zoom_in_img.width; + tmp_w = size_1em_pixel_count*2; + tmp_h = tmp_w*this_h_ratio; + bw_index = add_bawidget(pen_x, pen_y, tmp_w, tmp_h, null, "zoom_in", null); + //zoom_in_button_index = bw_index; + zoom_in_button = last_bawidget; + last_bawidget["image"]=zoom_in_img; + zoom_in_img.style.visibility="hidden"; + document.getElementById("zoom_in_disabled").style.visibility="hidden"; + //pen_y += tmp_h+padding_h; + pen_x += tmp_w; + + //ZOOM OUT + var zoom_out_img = document.getElementById("zoom_out"); + this_h_ratio = zoom_out_img.height/zoom_out_img.width; + tmp_w = size_1em_pixel_count*2; + tmp_h = tmp_w*this_h_ratio; + bw_index = add_bawidget(pen_x, pen_y, tmp_w, tmp_h, null, "zoom_out", null); + zoom_out_button = last_bawidget; + //zoom_out_button_index = bw_index; + last_bawidget["image"]=zoom_out_img; + zoom_out_img.style.visibility="hidden"; + document.getElementById("zoom_out_disabled").style.visibility="hidden"; + pen_y += tmp_h+padding_h; + pen_x -= tmp_w; + + + draw_map(); + } + + '; + }//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 ($debug_mode_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++; } - else echo ""; - - //echo "
".$x.",0,".$z; - echo_hold($alignment_comment); - echo_hold(""); - echo_hold( "\r\n"); - $x++; + echo " \r\n"; + $this_tiley_z-=1; } - echo_hold( " \r\n"); - echo_release(); - $z--; + 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"; } - //show head full size (not zoomed): - //$zoomed_head_w=$character_icon_w;//(int)((float)$character_icon_w*$scale+.5); - //$zoomed_head_h=$character_icon_h;//(int)((float)$character_icon_h*$scale+.5); - $zoomed_image_w=16; - $zoomed_image_h=16; - $rel_x -= (int)($zoomed_image_w/2); - $rel_z -= (int)($zoomed_image_h/2); - //$img_style="position:absolute; "; - $img_style=""; - $img_border_style=""; - //$img_border_style="border: 1px solid white;"; - $text_style="color:white;"; - if ($is_expired==false) { - if ($is_idle==true) { - $img_border_style=""; - //$img_border_style="border: 1px solid rgba(128,128,128,.5);"; - $img_style.="opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below - $text_style="color:white; opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below - } - echo_hold( "
$text
" ); + } + 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"; } - //$position_offset_x+=$character_icon_w; } + echo ""."
'; + echo '
".''.'
'."$td_decachunk_placeholder_content".'".''.''."$td_decachunk_placeholder_content".'
'."\r\n"; } - echo "
\r\n"; - echo "
\r\n"; } else { //not isset($world_name) echo "

Choose world:

"; @@ -1423,6 +717,34 @@ function echo_chunkymap_as_chunk_table($show_all_enable) { } 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; + } } + ?> diff --git a/web/chunkymapdata_default/images/compass-rose.png b/web/chunkymapdata_default/images/compass_rose.png similarity index 100% rename from web/chunkymapdata_default/images/compass-rose.png rename to web/chunkymapdata_default/images/compass_rose.png diff --git a/web/chunkymapdata_default/images/rename-deprecated.bat b/web/chunkymapdata_default/images/rename-deprecated.bat new file mode 100644 index 0000000..795343d --- /dev/null +++ b/web/chunkymapdata_default/images/rename-deprecated.bat @@ -0,0 +1,5 @@ +rename zoom-in.png zoom_in.png +rename zoom-out.png zoom_out.png +rename zoom-in_disabled.png zoom_in_disabled.png +rename zoom-out_disabled.png zoom_out_disabled.png +rename compass-rose.png compass_rose.png \ No newline at end of file diff --git a/web/chunkymapdata_default/images/zoom-in.png b/web/chunkymapdata_default/images/zoom_in.png similarity index 100% rename from web/chunkymapdata_default/images/zoom-in.png rename to web/chunkymapdata_default/images/zoom_in.png diff --git a/web/chunkymapdata_default/images/zoom-in_disabled.png b/web/chunkymapdata_default/images/zoom_in_disabled.png similarity index 100% rename from web/chunkymapdata_default/images/zoom-in_disabled.png rename to web/chunkymapdata_default/images/zoom_in_disabled.png diff --git a/web/chunkymapdata_default/images/zoom-out.png b/web/chunkymapdata_default/images/zoom_out.png similarity index 100% rename from web/chunkymapdata_default/images/zoom-out.png rename to web/chunkymapdata_default/images/zoom_out.png diff --git a/web/chunkymapdata_default/images/zoom-out_disabled.png b/web/chunkymapdata_default/images/zoom_out_disabled.png similarity index 100% rename from web/chunkymapdata_default/images/zoom-out_disabled.png rename to web/chunkymapdata_default/images/zoom_out_disabled.png diff --git a/web/viewchunkymap.php b/web/viewchunkymap.php index 40c8d02..b36c465 100644 --- a/web/viewchunkymap.php +++ b/web/viewchunkymap.php @@ -1,6 +1,6 @@ - -Chunkymap Example Page +Chunkymap @@ -26,9 +26,10 @@ if (is_file('chunkymap.php')) { //echo ""; set_chunkymap_view($chunkymap_view_x,$chunkymap_view_z,$chunkymap_view_zoom); //echo "
"; - $chunk_mode_enable=true; //this should usually be false; - $debug_mode_enable=false; //this renders colors based on yml files instead of drawing images - echo_chunkymap_canvas($chunk_mode_enable,$debug_mode_enable); + $chunk_mode_enable=true; //(this should normally be false) if true, uses 16x16 png files instead of the 160x160 decachunks; it is slower but may have more of the map during times when new chunks are explored but before the render queue is done and the decachunk images are created from the chunk images.); + $debug_mode_enable=false; //if true, this renders colors based on yml files instead of drawing images (and does not echo images at all) + $html4_mode_enable=false; //if true, does not echo canvas nor client-side scripting + echo_chunkymap_canvas($chunk_mode_enable,$debug_mode_enable,$html4_mode_enable); //echo_chunkymap_as_chunk_table(false); //echo_decachunk_table(); //echo "
";