From 07bc40429e645a01472bf271884b9f58ffe79b4e Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Sun, 20 Mar 2016 04:33:58 -0400 Subject: [PATCH] draw singleimage, players, markers on canvas --- README.md | 2 + chunkymap-regen.py | 45 +- expertmmregressionsuite.py | 2 + singleimage.py | 25 +- unused/chunkymap_deprecated.php | 5 +- web/chunkymap.php | 696 +++++++++++++++--- web/chunkymapdata_default/world/markers/0.yml | 8 +- web/viewchunkymap.php | 11 +- 8 files changed, 657 insertions(+), 137 deletions(-) diff --git a/README.md b/README.md index dfa7dbe..7312d8d 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ This program comes without any warranty, to the extent permitted by applicable l refresh_map_seconds:1 #where 1 is number of seconds: refresh_players_seconds:1 +* Save jpg or png named as player's index to the players folder of the world to change player's icon on map (index is a number assigned for use with ajax when $show_player_names_enable is false). The index can be found in the player's yml file generated by chunkymap-regen.py. * Can show a static html version of map (echo_chunkymap_table() php function) -- see viewchunkymap.php * Zoom in and out @@ -132,6 +133,7 @@ world_path (chunkymap-regen.py will ask for configuration options on first run and ask for your www root) ## Known Issues +* Fix chunk generation and draw decachunks to canvas (so singleimage.py is not required to be run before chunkymap-regen.py) * Detect exceptions in mintestmapper (such as database locked) and do not mark the chunk as is_empty * Move the following to config dict: python_exe_path diff --git a/chunkymap-regen.py b/chunkymap-regen.py index 6d9d00e..a97c8b5 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -9,6 +9,7 @@ import timeit from timeit import default_timer as best_timer #file modified time etc: import time +#from datetime import datetime #copyfile etc: import shutil import math @@ -21,7 +22,7 @@ from pythoninfo import * from PIL import Image, ImageDraw, ImageFont, ImageColor #mode_to_bpp dict is from Antti Haapala. . 7 Mar 2015. 28 Feb 2016. mode_to_bpp = {'1':1, 'L':8, 'P':8, 'RGB':24, 'RGBA':32, 'CMYK':32, 'YCbCr':24, 'I':32, 'F':32} - +INTERNAL_TIME_FORMAT_STRING="%Y-%m-%d %H:%M:%S" #best_timer = timeit.default_timer #if sys.platform == "win32": # on Windows, the best timer is time.clock() @@ -337,20 +338,20 @@ class MTChunks: 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("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)) - install_list.append(InstalledFile("zoom-out_disabled.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_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)) + install_list.append(InstalledFile("zoom_out_disabled.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) install_list.append(InstalledFile("start.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) install_list.append(InstalledFile("target_start.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) - install_list.append(InstalledFile("compass-rose.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) + install_list.append(InstalledFile("compass_rose.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) install_list.append(InstalledFile("loading.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) - install_list.append(InstalledFile("arrow-wide-up.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) - install_list.append(InstalledFile("arrow-wide-down.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) - install_list.append(InstalledFile("arrow-wide-left.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) - install_list.append(InstalledFile("arrow-wide-right.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) - install_list.append(InstalledFile("chunk-blank.jpg", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) - install_list.append(InstalledFile("decachunk-blank.jpg", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) + install_list.append(InstalledFile("arrow_wide_up.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) + install_list.append(InstalledFile("arrow_wide_down.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) + install_list.append(InstalledFile("arrow_wide_left.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) + install_list.append(InstalledFile("arrow_wide_right.png", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) + install_list.append(InstalledFile("chunk_blank.jpg", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) + install_list.append(InstalledFile("decachunk_blank.jpg", source_web_chunkymapdata_images_path, dest_web_chunkymapdata_images_path)) source_chunkymapdata_players = os.path.join(source_web_chunkymapdata_world_path, "players") dest_chunkymapdata_players = os.path.join(self.chunkymap_thisworld_data_path, "players") install_list.append(InstalledFile("singleplayer.png", source_chunkymapdata_players, dest_chunkymapdata_players)) @@ -371,7 +372,8 @@ class MTChunks: if source_mtime_seconds>installed_mtime_seconds: shutil.copyfile(source_path, installed_path) # DOES replace destination file else: - raw_input("WARNING: cannot update file since can't find '"+source_path+"'") + print("WARNING: cannot update file since can't find '"+source_path+"'") + raw_input("Press enter to continue...") def deny_http_access(self, dir_path): @@ -1083,8 +1085,17 @@ class MTChunks: player_index = None this_player = None is_changed = False + #(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file_path) + mtime = time.gmtime(os.path.getmtime(file_path)) + #NOTE: time.gmtime converts long timestamp to 9-long tuple + this_mtime_string = time.strftime(INTERNAL_TIME_FORMAT_STRING, mtime) + #mtime = os.path.getmtime(file_path) + #this_mtime_string = datetime.strftime(mtime, INTERNAL_TIME_FORMAT_STRING) if file_name in self.players: this_player = self.players[file_name] + if ("utc_mtime" not in this_player) or (this_player["utc_mtime"]!=this_mtime_string): + this_player["utc_mtime"]=this_mtime_string + is_changed = True if "index" in this_player: player_index = self.players[file_name]["index"] else: @@ -1095,11 +1106,15 @@ class MTChunks: this_player = {} player_index = self.get_new_player_index() this_player["index"] = player_index + this_player["playerid"] = file_name + this_player["utc_mtime"] = this_mtime_string + if player_name is not None: + this_player["name"] = player_name self.players[file_name] = this_player is_changed = True player_dest_path = None if player_index is not None: - player_dest_path = os.path.join(self.chunkymap_players_path, player_index+".yml") + player_dest_path = os.path.join(self.chunkymap_players_path, str(player_index)+".yml") else: print("ERROR: player_index is None for '"+file_name+"' (this should never happen)") player_x = None @@ -1198,7 +1213,7 @@ class MTChunks: #if not self.verbose_enable: print("PLAYERS:") print(" saved: "+str(player_written_count)+" (moved:"+str(players_moved_count)+"; new:"+str(players_saved_count)+")") - print(" didn't change: "+str(players_didntmove_count)) + print(" didn't move: "+str(players_didntmove_count)) def is_chunk_traversed_by_player(self, chunk_luid): result = False diff --git a/expertmmregressionsuite.py b/expertmmregressionsuite.py index d40efb7..e0a0fbd 100644 --- a/expertmmregressionsuite.py +++ b/expertmmregressionsuite.py @@ -19,6 +19,8 @@ from expertmm import * # * check for signs in len params (such as where str(len(part1+part2)) should be str(len(part1))+part2 # * check for only variable name in quotes (maybe the programmer meant to use the value) # * check for use of os.dirname (should be os.path.dirname) +# * mixing width with y (or height or z) and mixing height with x (or width) +# * using '+' next to '"' in php seperated only by whitespace (probably meant concatenate operator '.') def view_traceback(): ex_type, ex, tb = sys.exc_info() diff --git a/singleimage.py b/singleimage.py index 3ac3d74..cfce664 100644 --- a/singleimage.py +++ b/singleimage.py @@ -3,7 +3,8 @@ import os from minetestinfo import * #python_exe_path is from: from pythoninfo import * - +#from PIL import Image, ImageDraw, ImageFont, ImageColor +from PIL import Image class ChunkymapOfflineRenderer: @@ -56,6 +57,7 @@ class ChunkymapOfflineRenderer: #cmd_no_out_string = python_exe_path+" "+self.minetestmapper_py_path+" --bgcolor '"+self.FLAG_EMPTY_HEXCOLOR+"' --input \""+minetestinfo.get_var("primary_world_path")+"\" --geometry "+geometry_string+" --output \""+tmp_png_path+"\"" png_name = "singleimage.png" + tmp_png_path = os.path.join(genresults_folder_path, png_name) squote = "" if os_name!="windows": @@ -87,8 +89,27 @@ class ChunkymapOfflineRenderer: os.remove(dest_png_path) os.rename(tmp_png_path, dest_png_path) final_png_path = dest_png_path - print("Map image saved to:") + print("Png image saved to:") print(" "+final_png_path) + print("Converting to jpg...") + pngim = Image.open(final_png_path) + #jpgim = Image.new('RGB', pngim.size, (0, 0, 0)) + #jpgim.paste(pngim.convert("RGB"), (0,0,pngim.size[0],pngim.size[0])) + jpg_name = "singleimage.jpg" + dest_jpg_path = os.path.join(www_chunkymapdata_world_path, jpg_name) + if os.path.isfile(dest_jpg_path): + os.remove(dest_jpg_path) + if not os.path.isfile(dest_jpg_path): + print(" removed old '"+dest_jpg_path+"'") + else: + print(" failed to remove'"+dest_jpg_path+"'") + #jpgim.save(dest_jpg_path) + pngim.save(dest_jpg_path, 'JPEG') + if os.path.isfile(dest_jpg_path): + print("jpg image saved to:") + print(" "+dest_jpg_path) + else: + print("Could not write '"+dest_jpg_path+"'") if os.path.isfile(genresult_path): print("Results:") print(" "+genresult_path) diff --git a/unused/chunkymap_deprecated.php b/unused/chunkymap_deprecated.php index deef314..63abb43 100644 --- a/unused/chunkymap_deprecated.php +++ b/unused/chunkymap_deprecated.php @@ -507,9 +507,8 @@ function echo_chunkymap_as_chunk_table($show_all_enable) { $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; + global $player_file_age_expired_max_seconds; + global $player_file_age_idle_max_seconds; $chunks_16px_path = $chunkymapdata_thisworld_path.'/'."16px"; while ($z >= $min_chunkz) { echo_hold( " \r\n"); diff --git a/web/chunkymap.php b/web/chunkymap.php index 28c6312..37a07bd 100644 --- a/web/chunkymap.php +++ b/web/chunkymap.php @@ -7,6 +7,11 @@ if (($_SERVER['PHP_SELF'] == "chunkymap.php") or endsWith($_SERVER['PHP_SELF']," } + +$minute=60; +$player_file_age_expired_max_seconds=20*$minute-1; +$player_file_age_idle_max_seconds=5*$minute-1; + //NOTE: for parse errors, MUST add the following line to php.ini (such as /etc/php5/apache2/php.ini): display_errors = on if (is_file('browser.php')) { include_once('browser.php'); @@ -262,9 +267,98 @@ function get_javascript_int_value($this_val) { return $result; } +function get_markers_from_dir($chunkymap_markers_path) { + global $chunkymapdata_thisworld_path; + global $player_file_age_expired_max_seconds; + global $player_file_age_idle_max_seconds; + global $show_expired_players_enable; + $markers=array(); + $markers_count=0; + 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, ":"); + if (isset($marker_vars["x"]) and isset($marker_vars["z"])) { + $is_expired=false; + $is_idle=false; + if (isset($marker_vars["utc_mtime"])) { + $last_player_update_time = strtotime($marker_vars["utc_mtime"]); + 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; + } + if ($is_expired===false) { + $markers[$markers_count]["utc_mtime"] = $marker_vars["utc_mtime"]; + } + } + if (($show_expired_players_enable===true) or ($is_expired===false)) { + $markers[$markers_count]["x"] = $marker_vars["x"]; + $markers[$markers_count]["z"] = $marker_vars["z"]; + $markers[$markers_count]["is_idle"] = $is_idle; + $markers[$markers_count]["is_expired"] = $is_expired; + if (isset($marker_vars["y"])) { + $markers[$markers_count]["y"] = $marker_vars["y"]; + } + if (isset($marker_vars["image"])) { + $try_path = "$chunkymapdata_thisworld_path/".$marker_vars["image"]; + if (is_file($try_path)) { + $markers[$markers_count]["image"] = $try_path; //this is the normal place to store them actually + } + else { + $markers[$markers_count]["image"] = $marker_vars["image"]; + } + } + else { + if (isset($marker_vars["index"])) { + $try_path = "$chunkymapdata_thisworld_path/players/".$marker_vars["index"].".jpg"; + if (is_file($try_path)) { + $markers[$markers_count]["image"] = $try_path; + echo_error("detected image $try_path\r\n"); + } + else { + + $try_path = "$chunkymapdata_thisworld_path/players/".$marker_vars["index"].".png"; + if (is_file($try_path)) { + $markers[$markers_count]["image"] = $try_path; + } + } + } + else { + echo_error("missing index in marker file $file_name\r\n"); + } + } + if (isset($marker_vars["name"])) { + $markers[$markers_count]["name"] = $marker_vars["name"]; + } + if (isset($marker_vars["index"])) { + $markers[$markers_count]["index"] = $marker_vars["index"]; //for ajax to get player location with neither playerid nor name known + } + if (isset($marker_vars["playerid"])) { + $markers[$markers_count]["playerid"] = $marker_vars["playerid"]; + } + $markers_count+=1; + } + + } + else { + echo_error("Bad location in marker file '$file_path'"); + } + } + } + } + } + return $markers; +} + + //chunk_mode_enable: shows chunk png images instead of decachunk jpg images (slower) //visual_debug_enable: draws colored rectangles based on yml files instead of drawing images -function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_mode_enable) { +function echo_chunkymap_canvas($show_player_names_enable, $chunk_mode_enable, $visual_debug_enable, $html4_mode_enable) { global $x; global $z; global $zoom; @@ -302,7 +396,7 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ if ($zoom<$chunkymap_view_min_zoom) $zoom = $chunkymap_view_min_zoom; if ($zoom>$chunkymap_view_max_zoom) $zoom = $chunkymap_view_max_zoom; - $EM_PER_WIDTH_COUNT = 800.0/12.0; + $EM_PER_WIDTH_COUNT = 800.0/12.0; //ultimately derived from 12pt font on 800x600 display--no really, this is right $camera_w = (800) * (1.0/$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) $camera_left = $x-$camera_w/2.0; @@ -384,6 +478,51 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ } } } + + $markers = get_markers_from_dir($chunkymapdata_thisworld_path."/markers"); + $players = get_markers_from_dir($chunkymapdata_thisworld_path."/players"); + $index = 0; + $players_count = count($players); + while ($index<$players_count) { + $this_player = $players[$index]; + $img_src = "$chunkymapdata_thisworld_path/players/singleplayer.png"; + if (!isset($players[$index]["image"])) { + $players[$index]["image"] = $img_src; + } + if (isset($players[$index]["image"])) { + if (isset($players[$index]["index"])) { + $public_index=$players[$index]["index"]; + $players[$index]["img_id"] = "player"."$public_index"."_img"; + //echo ("players[index][img_id]:".$players[$index]["img_id"]); + } + else { + echo_error("Missing index for player\r\n"); + } + } + else { + echo echo_error("Missing image for player\r\n"); + } + $index++; + } + //echo ("finished adding id to $players_count player(s)\r\n"); + //img_id is actually only needed for canvas drawing + $index = 0; + $markers_count = count($markers); + while ($index<$markers_count) { + if (isset($markers[$index]["image"])) { + if (isset($markers[$index]["index"])) { + $public_index=$markers[$index]["index"]; + $markers[$index]["img_id"] = "marker"."$public_index"."_img"; + } + else { + echo_error("Missing index for marker "+$markers[$index]["name"]); + } + } + $index++; + } + //images are echoed further down + + if ($html4_mode_enable!==true) { //image-rendering: -moz-crisp-edges; image-rendering:-o-crisp-edges; image-rendering: -webkit-optimize-contrast; image-rendering: crisp-edges; -ms-interpolation-mode: nearest-neighbor; echo ' '; @@ -392,6 +531,84 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ var x='.$x.'; var z='.$z.'; var zoom='.$zoom.'; + //var default_player_img = document.getElementById("singleplayer_img");'; + + $player_count = count($players); + echo ' + //var player_count='.$player_count.'; + var players=['; + $index=0; + while ($index<$player_count) { + echo "{"; + $this_player = $players[$index]; + //if (isset($this_player["index"])) { + $public_index = $this_player["index"]; + //} + echo "x:".$this_player["x"].",\r\n"; + echo "z:".$this_player["z"].",\r\n"; + if (($show_player_names_enable===true) and isset($this_player["name"])) { + echo "name:\"".$this_player["name"]."\",\r\n"; + } + else { + echo "name:null,\r\n"; + } + if (isset($this_player["img_id"])) { + echo "img_id:\"".$this_player["img_id"]."\",\r\n"; + echo "img_enable:true,\r\n"; + } + else { + echo "img_enable:false,\r\n"; + } + echo "is_expired:".get_javascript_bool_value($this_player["is_expired"]).",\r\n"; + echo "is_idle:".get_javascript_bool_value($this_player["is_idle"]).",\r\n"; + echo "index:$public_index\r\n"; + echo "}"; + $index++; + if ($index!=$player_count) { + echo ","; + } + echo "\r\n"; + } + echo '];'."\r\n"; + + $marker_count = count($markers); + echo ' + //var marker_count='.$marker_count.'; + var markers=['; + $index=0; + while ($index<$marker_count) { + echo "{"; + $this_marker = $markers[$index]; + //if (isset($this_marker["index"])) { + $public_index = $this_marker["index"]; + //} + echo "x:".$this_marker["x"].",\r\n"; + echo "z:".$this_marker["z"].",\r\n"; + if (isset($this_marker["name"])) { + echo "name:\"".$this_marker["name"]."\",\r\n"; + } + else { + echo "name:null,\r\n"; + } + if (isset($this_marker["img_id"])) { + echo "img_id:\"".$this_marker["img_id"]."\",\r\n"; + echo "img_enable:true,\r\n"; + } + else { + echo "img_enable:false,\r\n"; + } + echo "is_expired:".get_javascript_bool_value($this_marker["is_expired"]).",\r\n"; + echo "is_idle:".get_javascript_bool_value($this_marker["is_idle"]).",\r\n"; + echo "index:$public_index\r\n"; + echo "}"; + $index++; + if ($index!=$marker_count) { + echo ","; + } + echo "\r\n\r\n"; + } + echo ']; + var chunkymap_view_max_zoom='.$chunkymap_view_max_zoom.'; var chunkymap_view_min_zoom='.$chunkymap_view_min_zoom.'; var chunkymap_zoom_delta='.$chunkymap_change_zoom_multiplier.'; @@ -430,7 +647,11 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ var zoom_in_button_index = null; var zoom_out_button_index = null; var zoom_out_label_index = null; - var location_label_index = null; + var xy_label_index = null; + var xy_label = null; + var zoom_label = null; + var zoom_in_button = null; + var zoom_out_button = null; var label0 = null; var label1 = null; var label2 = null; @@ -447,14 +668,57 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ var zoomed_size_1pt_pixel_count = null; var ctx = null; + ctx = my_canvas.getContext("2d"); + process_resize(); + ctx.fillStyle = "black"; + ctx.fillRect(0,0,ctx.canvas.width,ctx.canvas.height); + var tmp_widget = {x:100,y:100,text:"Loading..."}; + draw_widget_recolored(tmp_widget, "rgb(128,128,128)"); + + var powered_by_label = create_bawidget(ctx.canvas.width/2, size_1em_pixel_count/4, 0, 0, null, "powered_by_label"); + powered_by_label.text = "Chunkymap"; + powered_by_label.size_em = .75; + //powered_by_label.color_string = "rgb(12,132,245)" + powered_by_label.color_string = "rgb(192,192,192)" + function zoom_in() { zoom*=chunkymap_zoom_delta; + process_zoom_change(); //DOES call process_view_change draw_map(); } function zoom_out() { zoom/=chunkymap_zoom_delta; + process_zoom_change(); //DOES call process_view_change draw_map(); } + function process_resize() { + //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.height; + //current_w = window.innerWidth; + //current_h = window.innerHeight; + current_ratio = current_w/current_h; + + //if (ctx.canvas.heightcurrent_h) { @@ -469,6 +733,64 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ camera_top = z + (camera_h/2.0); //plus since cartesian camera_right = camera_left+camera_w; camera_bottom = camera_top - camera_h; //minus since cartesion + if (label4!=null) { + //change_widget(label4, "[4] camera_w: "+Math.round(camera_w)+"; camera_h:"+Math.round(camera_h)) + } + } + 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 (zoomchunkymap_view_max_zoom) {zoom = chunkymap_view_max_zoom;} + + if (zoom==chunkymap_view_min_zoom) { + zoom_out_img = document.getElementById("zoom_out_disabled"); + tmp_zoom_out_ptr = null; + } + else { + zoom_out_img = document.getElementById("zoom_out"); + } + if (zoom==chunkymap_view_max_zoom) { + zoom_in_img = document.getElementById("zoom_in_disabled"); + tmp_zoom_in_ptr = null; + } + else { + zoom_in_img = document.getElementById("zoom_in"); + } + if (xy_label!=null) { + xy_label.text = Math.round(x)+","+Math.round(z); + } + + zoom_label_value=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); + } + zoomed_size_1pt_pixel_count = size_1pt_pixel_count*zoom; + if (zoom_label!=null) { + change_widget(zoom_label, zoom_label_value+"%"); + //zoom_label.text=zoom_label_value+"%"; + } + if (label3!=null) { + //change_widget(label3, "size_1pt_pixel_count:"+size_1pt_pixel_count+" zoomed_size_1pt_pixel_count:"+zoomed_size_1pt_pixel_count); + } + + if (zoom_in_button!=null) { + zoom_in_button.click_event=tmp_zoom_in_ptr; + zoom_in_button.image=zoom_in_img; + } + if (zoom_out_button!=null) { + zoom_out_button.click_event=tmp_zoom_out_ptr; + zoom_out_button.image=zoom_out_img; + } + process_view_change(); } function get_world_point_from_screen_point(screen_point) { @@ -481,48 +803,88 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ }; } - function get_screen_point_from_world_coords(location_x, location_z) { + function get_screen_point_from_world_coords(location_x, location_z) { //var half_camera_w = camera_w/2.0; //var half_camera_h = camera_h/2.0; - horz_ratio = location_x/(camera_right-camera_left); - vert_ratio = location_z/(camera_bottom-camera_top); + //subtract camera coords first (subtract both coords since location and camera are both cartesian) + horz_ratio = (location_x-camera_left)/(camera_right-camera_left); + vert_ratio = (location_z-camera_top)/(camera_bottom-camera_top); return { x:horz_ratio*current_w, y:vert_ratio*current_h }; } - 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.heightchunkymap_view_max_zoom) {zoom = chunkymap_view_max_zoom;} - - if (zoom==chunkymap_view_min_zoom) { - zoom_out_img = document.getElementById("zoom_out_disabled"); - tmp_zoom_out_ptr = null; - } - else { - zoom_out_img = document.getElementById("zoom_out"); - } - if (zoom==chunkymap_view_max_zoom) { - zoom_in_img = document.getElementById("zoom_in_disabled"); - tmp_zoom_in_ptr = null; - } - else { - zoom_in_img = document.getElementById("zoom_in"); - } - location_label.text = Math.round(x)+","+Math.round(z); - - zoom_label_value=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; - } function draw_map() { - process_zoom_change(); + var r = 0; //border var g = 0; //exists var b = 0; // @@ -618,8 +944,8 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ alert(alert_string); } - ctx = my_canvas.getContext("2d"); - process_resize(ctx); + + process_resize(); ctx.fillStyle = "black"; ctx.fillRect(0,0,ctx.canvas.width,ctx.canvas.height); @@ -641,36 +967,47 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ ctx.drawImage(si, si_canvas_topleft.x, si_canvas_topleft.y, si_canvas_w, si_canvas_h); //label5.text = "--map "+si_canvas_topleft.x+":"+si_canvas_bottomright.x+","+si_canvas_topleft.y+":"+si_canvas_bottomright.y+" "+si_canvas_w+"x"+si_canvas_h+" --camera "+camera_left+":"+camera_right+","+camera_bottom+":"+camera_top; - label5.text = "map world bounds: "+si_left+":"+si_right+","+si_bottom+":"+si_top; - label1.text = "map on canvas "+Math.round(si_canvas_topleft.x)+":"+Math.round(si_canvas_bottomright.x)+","+Math.round(si_canvas_topleft.y)+":"+Math.round(si_canvas_bottomright.y)+" "+Math.round(si_canvas_w)+"x"+Math.round(si_canvas_h); - label2.text="camera "+Math.round(camera_left)+":"+Math.round(camera_right)+","+Math.round(camera_bottom)+":"+Math.round(camera_top); - label3.text="size_1pt_pixel_count:"+size_1pt_pixel_count+" zoomed_size_1pt_pixel_count:"+zoomed_size_1pt_pixel_count; - label4.text="canvas "+current_w+"x"+current_h; + //label5.text = "map world bounds: "+si_left+":"+si_right+","+si_bottom+":"+si_top; + //label1.text = "map on canvas "+Math.round(si_canvas_topleft.x)+":"+Math.round(si_canvas_bottomright.x)+","+Math.round(si_canvas_topleft.y)+":"+Math.round(si_canvas_bottomright.y)+" "+Math.round(si_canvas_w)+"x"+Math.round(si_canvas_h); + //label2.text="[2] camera: "+Math.round(camera_left)+":"+Math.round(camera_right)+","+Math.round(camera_bottom)+":"+Math.round(camera_top); + //UNUSED (or mouse screen position): label4.text="canvas "+current_w+"x"+current_h; } - + draw_markers(markers, 1, "rgb(71,219,37)"); + draw_markers(players, .7, "white"); for (i=0; i-1 && dragging_prev_point.y>-1) { - //flip both axes to give the effect of moving the map instead of the camera (z was already flipped [cartesian] so flip again): - x -= (mouse_point.x - dragging_prev_point.x)/zoomed_size_1pt_pixel_count; - z += (mouse_point.y - dragging_prev_point.y)/zoomed_size_1pt_pixel_count; + //flip both axes to give the effect of moving the map instead of the camera: + prev_cursor_world_point = get_world_point_from_screen_point(dragging_prev_point); + cursor_world_point = get_world_point_from_screen_point(mouse_point); + x -= cursor_world_point.x - prev_cursor_world_point.x; + z -= cursor_world_point.z - prev_cursor_world_point.z; + //(z was already flipped [cartesian] so flip again): + //x -= (mouse_point.x - dragging_prev_point.x)/zoomed_size_1pt_pixel_count; + //z += (mouse_point.y - dragging_prev_point.y)/zoomed_size_1pt_pixel_count; process_view_change(); } dragging_prev_point.x=mouse_point.x; @@ -764,8 +1105,9 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ draw_map(); } else { - change_widget(label0, mouse_point.x+","+mouse_point.y+" world_point: "+Math.round(world_point.x)+","+Math.round(world_point.z)); + //change_widget(label0, mouse_point.x+","+mouse_point.y+" world_point: "+Math.round(world_point.x)+","+Math.round(world_point.z)); } + change_widget(label0, "location: "+Math.round(world_point.x)+","+Math.round(world_point.z)); }, false); //my_canvas.addEventListener("mousemove", function(evt) { // var mousePos = getMousePos(my_canvas, evt); @@ -793,8 +1135,8 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ // handle_mouseout(event); //}; - var ctx = my_canvas.getContext("2d"); - process_resize(ctx); + //ctx = my_canvas.getContext("2d"); + process_resize(); var pen_x = size_1em_pixel_count; var pen_y = size_1em_pixel_count; @@ -803,8 +1145,9 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ 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; + bw_index = add_bawidget(pen_x+compass_rose_w/4, pen_y, tmp_w, tmp_h, null, "xy_label"); + xy_label = last_bawidget; + xy_label.visible = false; //done on each draw: last_bawidget.text = pen_y += size_1em_pixel_count + padding_h; @@ -889,6 +1232,10 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ //done on each draw: last_bawidget.text = pen_y += size_1em_pixel_count + padding_h; + document.getElementById("chunkymap_table").style.visibility="hidden"; + document.getElementById("singleimage_table").style.visibility="hidden"; + + process_zoom_change(); draw_map(); } @@ -903,18 +1250,137 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ else { $td_tile_placeholder_content = $td_decachunk_placeholder_content; } - $si_path = "$chunkymapdata_thisworld_path/singleimage.png"; + + + $si_path = "$chunkymapdata_thisworld_path/singleimage.jpg"; $si_yml_path = "$chunkymapdata_thisworld_path/singleimage.yml"; if (is_file($si_path) and is_file($si_yml_path)) { - //$style_append="; visibility:hidden"; $style_append=""; - echo ''."\r\n"; + if ($html4_mode_enable===true) { + echo '
'."\r\n"; + } + else { + $style_append="; visibility:hidden"; + echo '
'."\r\n"; + } echo ' '."\r\n"; echo '
'."\r\n"; $style_append=""; + $players_count = count($players); + $index=0; + while ($index<$players_count) { + $this_player = $players[$index]; + $public_index = $this_player["index"]; + // z-index:999; + $zoomed_head_w="1%"; + $img_style=""; + $img_border_style="border: 1px solid white;"; + $text_style="color:white;"; + $img_id = null; + $img_enable = true; + $img_src = "$chunkymapdata_thisworld_path/players/singleplayer.png"; + if (!isset($this_player["image"])) { + $this_player["image"] = $img_src; + } + if (isset($this_player["image"])) { + $img_src = $this_player["image"]; + if (isset($this_player["img_id"])) { //this is only needed for changing canvas drawing location via ajax + $img_id = $this_player["img_id"]; + $img_enable = true; + } + else { + echo "missing player img_id\r\n"; + } + } + else { + echo "missing player image\r\n"; + } + //$text = "$public_index"; + $text = ""; + if ($show_player_names_enable) { + if (isset($this_player["name"])) { + $text = $this_player["name"]; + } + } + if ($this_player["is_expired"]===true) { //should only be used for debug + $img_border_style="border: 1px solid rgba(128,128,128,.5);"; + $img_style.="opacity: 0.1; filter: alpha(opacity=10);"; //filter is for IE8 and below + $text_style="color:white; opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below + $text.=" (expired)"; + } + elseif ($this_player["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 + } + + $rel_x = "50%"; //TODO: NOT YET IMPLEMENTED (determine from actual location) + $rel_z = "50%"; //TODO: NOT YET IMPLEMENTED (determine from actual location) + + echo "
\r\n"; + if ($img_enable===true) { + $id_string = ""; + if ($img_id!==null) { + $id_string=" id=\"$img_id\""; + } + echo " \r\n"; + } + echo " $text
\r\n"; + $index++; + }//end for player + + $markers_count = count($markers); + $index=0; + echo "\r\n"; + while ($index<$markers_count) { + $this_marker = $markers[$index]; + $public_index = $this_marker["index"]; + // z-index:999; + $zoomed_head_w="2%"; + $img_style=""; + $img_border_style="border: 1px solid white;"; + $text_style="color:white;"; + $img_id = "marker"."$public_index"."_img"; + $img_enable = false; + $img_src = null; + $text = ""; + if (isset($this_marker["image"])) { + $img_enable = true; + $img_src = $this_marker["image"]; + } + else { + $text = "$public_index"; + } + if (isset($this_marker["name"])) { + $text = $this_marker["name"]; + } + if ($this_marker["is_expired"]===true) { //should only be used for debug + $img_border_style="border: 1px solid rgba(128,128,128,.5);"; + $img_style.="opacity: 0.1; filter: alpha(opacity=10);"; //filter is for IE8 and below + $text_style="color:white; opacity: 0.4; filter: alpha(opacity=40);"; //filter is for IE8 and below + $text.=" (expired)"; + } + elseif ($this_marker["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 + } + + $rel_x = "50%"; //TODO: NOT YET IMPLEMENTED (determine from actual location) + $rel_z = "50%"; //TODO: NOT YET IMPLEMENTED (determine from actual location) + + echo "
\r\n"; + if ($img_enable===true) { + echo " \r\n"; + } + echo " $text
\r\n"; + $index++; + }//end for marker echo ' '."\r\n"; echo '
'."\r\n"; } + + //echo ""; echo ''; echo ''; echo ''; @@ -923,7 +1389,12 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ $this_tiley_z=$max_tiley_z; //start at max since screen is inverted cartesian if ($visual_debug_enable!==true) { //this table loads the images then is hidden when javascript runs successfully, but it is also a map though not very functional - echo ''."\r\n"; + if ($html4_mode_enable===true) { + echo '
'."\r\n"; + } + else { + echo '
'."\r\n"; + } echo ' '."\r\n"; echo ' '."\r\n"; echo " '."\r\n"; @@ -971,6 +1442,9 @@ function echo_chunkymap_canvas($chunk_mode_enable, $visual_debug_enable, $html4_ echo ' '."\r\n"; echo ''."\r\n"; } + if ($html4_mode_enable===true) { + echo '
Powered by Chunkymap
'; + } } else { //not isset($world_name) echo "

Choose world:

"; diff --git a/web/chunkymapdata_default/world/markers/0.yml b/web/chunkymapdata_default/world/markers/0.yml index df5b418..1497cfd 100644 --- a/web/chunkymapdata_default/world/markers/0.yml +++ b/web/chunkymapdata_default/world/markers/0.yml @@ -1,4 +1,6 @@ -text:Starting Location -location:0.0,0.0 +index:0 +name:Starting Location +x:0 +y:0 +z:0 image:chunkymapdata/images/start.png -comment:formerly chunk_markers_x0z0.yml \ No newline at end of file diff --git a/web/viewchunkymap.php b/web/viewchunkymap.php index 3651692..acfdafe 100644 --- a/web/viewchunkymap.php +++ b/web/viewchunkymap.php @@ -15,6 +15,12 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); //echo "php started..."; + +///// SHOW EXPIRED PLAYERS: /////////// +$show_expired_players_enable = true; // +/////////////////////////////////////// +//make sure you set this here, otherwise players can override it + if (is_file('chunkymap.php')) { //echo "including..."; include_once('chunkymap.php'); @@ -34,8 +40,8 @@ if (is_file('chunkymap.php')) { //echo "
"; $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.); $visual_debug_enable=false; //if true, this renders colors based on yml files instead of drawing images (and does not echo images at all) - - echo_chunkymap_canvas($chunk_mode_enable,$visual_debug_enable,$html4_mode_enable); + $show_player_names_enable=true; + echo_chunkymap_canvas($show_player_names_enable,$chunk_mode_enable,$visual_debug_enable,$html4_mode_enable); //echo_chunkymap_as_chunk_table(false); //echo_decachunk_table(); //echo "
"; @@ -45,7 +51,6 @@ else { echo "missing chunkymap.php"; } ?> -
Powered by Chunkymap