Browse Source

working on player position

minetestmapper-numpy did not print pngMinX nor pngMinZ which may be
necessary to determine left/top/right/bottom is missing if partial chunk
was rendered
master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
1bfa9b0cd0
  1. 157
      chunkymap-regen.py
  2. 2
      minetestmapper-numpy.py
  3. 100
      web/chunkymap.php
  4. BIN
      web/images/chunkymap_character-face.png

157
chunkymap-regen.py

@ -13,6 +13,58 @@ import traceback
#sector_ymax = args.self.maxheight/16
#region server-specific options
def get_dict_from_conf_file(path,assignment_operator="="):
results = None
print ("Checking "+str(path)+" for settings...")
if os.path.isfile(path):
results = {}
ins = open(path, 'r')
line = True
while line:
line = ins.readline()
if line and len(line)>0:
line_strip=line.strip()
if not line_strip[0]=="#": # if not comment
if not line_strip[0]=="-": # ignore yaml arrays
ao_index = line_strip.find(assignment_operator)
if ao_index>=1: # intentionally skip zero-length variable names
if ao_index<len(line_strip)-1: # skip yaml implicit nulls or yaml objects
result_name = line_strip[:ao_index].strip()
result_value = line_strip[ao_index+1:].strip()
print (" CHECKING... "+result_name+":"+result_value)
results[result_name]=result_value
ins.close()
return results
def get_tuple_from_notation(line, debug_src_name="<unknown object>"):
result = None
if line is not None:
# mark chunk
tuple_noparen_pos_string = line.strip("() \n\r")
pos_strings = tuple_noparen_pos_string.split(",")
if len(pos_strings) == 3:
try:
player_x = float(pos_strings[0])
player_y = float(pos_strings[1])
player_z = float(pos_strings[2])
except:
player_x = int(pos_strings[0])
player_y = int(pos_strings[1])
player_z = int(pos_strings[2])
result = player_x, player_y, player_z
else:
print("'"+debug_src_name+"' has bad position data--should be 3-length (x,y,z) in position value: "+str(pos_strings))
return result
def is_same_fvec3(list_a, list_b):
result = False
if list_a is not None and list_b is not None:
if len(list_a)>=3 and len(list_b)>=3:
result = (float(list_a[0]) == float(list_b[0])) and (float(list_a[1]) == float(list_b[1])) and (float(list_a[2]) == float(list_b[2]))
return False
class MTChunk:
x = None
z = None
@ -252,28 +304,6 @@ class MTChunks:
ins.close()
def get_dict_from_conf_file(self, path,assignment_operator="="):
results = None
print ("Checking "+str(path)+" for settings...")
if os.path.isfile(path):
results = {}
ins = open(path, 'r')
line = True
while line:
line = ins.readline()
if line and len(line)>0:
line_strip=line.strip()
if not line_strip[0]=="#": # if not comment
if not line_strip[0]=="-": # ignore yaml arrays
ao_index = line_strip.find(assignment_operator)
if ao_index>=1: # intentionally skip zero-length variable names
if ao_index<len(line_strip)-1: # skip yaml implicit nulls or yaml objects
result_name = line_strip[:ao_index].strip()
result_value = line_strip[ao_index+1:].strip()
print (" CHECKING... "+result_name+":"+result_value)
results[result_name]=result_value
ins.close()
return results
def deny_http_access(self, dir_path):
@ -484,6 +514,7 @@ class MTChunks:
return result
def check_players(self):
self.chunkymap_data_path=os.path.join(self.website_root,"chunkymapdata")
@ -526,45 +557,67 @@ class MTChunks:
break
ins.close()
player_dest_path = os.path.join(chunkymap_players_path,filename+".yml")
if player_position is not None:
# mark chunk
tuple_noparen_pos_string = player_position.strip("() \n\r")
pos_strings = tuple_noparen_pos_string.split(",")
if len(pos_strings) == 3:
player_x = None
player_y = None
player_z = None
try:
player_x = float(pos_strings[0])
player_y = float(pos_strings[1])
player_z = float(pos_strings[2])
except:
player_x = int(pos_strings[0])
player_y = int(pos_strings[1])
player_z = int(pos_strings[2])
chunk_x = int((float(player_x)/self.chunk_size))
chunk_y = int((float(player_y)/self.chunk_size))
chunk_z = int((float(player_z)/self.chunk_size))
chunk_luid = self.get_chunk_luid(chunk_x, chunk_z)
self.prepare_chunk_meta(chunk_luid)
self.chunks[chunk_luid].is_player_in_this_chunk = True
else:
print("Player '"+filename+"' has bad position data--should be 3-length (x,y,z) in position value: "+str(pos_strings))
player_x = None
player_y = None
player_z = None
chunk_x = None
chunk_y = None
chunk_z = None
player_position_tuple = get_tuple_from_notation(player_position, filename)
if player_position_tuple is not None:
player_x, player_y, player_z = player_position_tuple
player_x = float(player_x)
player_y = float(player_y)
player_z = float(player_z)
chunk_x = int((float(player_x)/self.chunk_size))
chunk_y = int((float(player_y)/self.chunk_size))
chunk_z = int((float(player_z)/self.chunk_size))
chunk_luid = self.get_chunk_luid(chunk_x, chunk_z)
self.prepare_chunk_meta(chunk_luid)
self.chunks[chunk_luid].is_player_in_this_chunk = True
#if is_enough_data:
#if player_name!="singleplayer":
map_player_dict = self.get_dict_from_conf_file(player_dest_path,":")
if (map_player_dict is None) or (map_player_dict["position"]!=player_position):
map_player_dict = get_dict_from_conf_file(player_dest_path,":")
#map_player_position_tuple = None
saved_player_x = None
saved_player_y = None
saved_player_y = None
if map_player_dict is not None:
#map_player_position_tuple = saved_player_x, saved_player_y, saved_player_z
if "x" in map_player_dict.keys():
saved_player_x = float(map_player_dict["x"])
if "y" in map_player_dict.keys():
saved_player_y = float(map_player_dict["y"])
if "z" in map_player_dict.keys():
saved_player_z = float(map_player_dict["z"])
#if (map_player_dict is None) or not is_same_fvec3( map_player_position_tuple, player_position_tuple):
if (map_player_dict is None) or (saved_player_x is None) or (saved_player_z is None) or (int(saved_player_x)!=int(player_x)) or (int(saved_player_z)!=int(player_z)):
# don't check y since y is elevation in minetest, don't use float since subblock position doesn't matter to map
if map_player_dict is not None and saved_player_x is not None and saved_player_z is not None:
#print("PLAYER MOVED: "+str(player_name)+" moved from "+str(map_player_position_tuple)+" to "+str(player_position_tuple))
print("PLAYER MOVED: "+str(player_name)+" moved from "+str(saved_player_x)+","+str(saved_player_y)+","+str(saved_player_z)+" to "+str(player_x)+","+str(player_y)+","+str(player_z))
outs = open(player_dest_path, 'w')
if player_name is not None:
outs.write("name:"+player_name+"\n") # python automatically uses correct newline for your os when you put "\n"
if player_position is not None:
outs.write("position:"+player_position+"\n")
#if player_position is not None:
# outs.write("position:"+player_position+"\n")
if player_x is not None:
outs.write("x:"+str(player_x)+"\n")
if player_y is not None:
outs.write("y:"+str(player_y)+"\n")
if player_z is not None:
outs.write("z:"+str(player_z)+"\n")
outs.write("is_enough_data:"+str(is_enough_data))
outs.close()
player_written_count += 1
else:
print("DIDN'T MOVE: "+str(player_name))
player_count += 1
def is_player_at_luid(self, chunk_luid):
result = False
@ -593,7 +646,7 @@ class MTChunks:
if not os.path.isfile(htaccess_path):
self.deny_http_access(self.chunkymap_data_path)
mapvars = self.get_dict_from_conf_file(world_yaml_path,":")
mapvars = get_dict_from_conf_file(world_yaml_path,":")
#is_testonly == (os_name=="windows")
if mapvars is not None and set(['world_name']).issubset(mapvars):

2
minetestmapper-numpy.py

@ -1016,6 +1016,8 @@ def draw_image(world,uid_to_color):
print("Saving to: "+ args.output)
print("PNG Region: ", pngregion)
print("pngMinX: ", str(pngminx))
print("pngMaxZ: ", str(pngmaxz))
print("Pixels PerNode: ", args.pixelspernode)
print("border: ", border)

100
web/chunkymap.php

@ -40,13 +40,13 @@ $chunkymapdata_path = "chunkymapdata";
$showplayers=true;
// NOT OPTIONAL:
$chunkymap_tile_original_w=80;
$chunkymap_tile_original_h=80;
$chunkymap_tile_original_w=16;
$chunkymap_tile_original_h=16;
$chunk_dimension_min=$chunkymap_tile_original_w;
if ($chunkymap_tile_original_h<$chunk_dimension_min) $chunk_dimension_min=$chunkymap_tile_original_h;
$chunkymap_view_zoom_min=1.0/$chunk_dimension_min; //should be a number that would get to exactly 100 eventually if multiplied by 2 repeatedly (such as 0.09765625); 0.005 doesn't work since tiles are 80x80 pixels
$chunkymap_view_zoom_min=1.0/$chunk_dimension_min; //should be a number that would get to exactly 100 eventually if multiplied by 2 repeatedly (such as 0.09765625); 0.005 was avoided since tiles used to be 80x80 pixels
$chunkymap_view_zoom_max=13107200.0;
function echo_error($val) {
@ -263,7 +263,8 @@ function echo_chunkymap_table() {
global $showplayers;
$players = array();
$player_count = 0;
$character_icon_w=8;
$character_icon_h=8;
if ($showplayers==true) {
$chunkymap_players_path = $chunkymapdata_path."/players";
if ($handle = opendir($chunkymap_players_path)) {
@ -273,38 +274,52 @@ function echo_chunkymap_table() {
if (endsWith($file_lower, ".yml")) {
$player_id=substr($file,0,strlen($file)-4); //-4 for .yml
$file_path = $chunkymap_players_path."/".$file;
$player_dict = get_dict_from_conf($file_path);
$player_dict = get_dict_from_conf($file_path,":");
$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"])) {
$tuple_string=trim($player_dict["position"]);
if ( startsWith($tuple_string, "(") and endsWith($tuple_string, ")") ) {
$tuple_string=substr($tuple_string,1,strlen($tuple_string)-2);
//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) {
//$smallx=(int)$coordinates[0];
//$smallz=(int)$coordinates[2];
$smallx=(int)$player_dict["x"];
$smallz=(int)$player_dict["z"];
$x = (int)( $smallx/$chunkymap_tile_original_w );
$z = (int)( $smallz/$chunkymap_tile_original_h );
$chunk_luid = "x".$x."z".$z;
$rel_x = $smallx - ($x*$chunkymap_tile_original_w);
$rel_z = $smallz - ($z*$chunkymap_tile_original_h);
if (!isset($chunk_assoc[$chunk_luid])) {
$chunk_assoc[$chunk_luid] = array();
}
$coordinates = explode(",", $tuple_string);
if (count($coordinates)==3) {
$chunk_luid = "x".$x."z".$z;
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;
}
if (isset($player_dict["name"])) {
$chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "name" ] = $player_dict["name"]
}
else {
$chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "name" ] = $player_dict["id"]
}
$chunk_assoc[$chunk_luid]["players_count"] += 1;
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
$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"] ][ "rel_x" ] = $rel_x;
$chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "rel_z" ] = $rel_z;
if (isset($player_dict["name"])) {
$chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "name" ] = $player_dict["name"];
}
else {
echo_error("Bad coordinates $tuple_string for player.");
$chunk_assoc[$chunk_luid][ "players" ][ $chunk_assoc[$chunk_luid]["players_count"] ][ "name" ] = $player_dict["id"];
}
$chunk_assoc[$chunk_luid]["players_count"] += 1;
//}
//else {
// echo_error("Bad coordinates $tuple_string for player.");
//}
}
//$player_count++;
@ -313,12 +328,6 @@ function echo_chunkymap_table() {
}
}
}
if (isset($chunk_assoc[$chunk_luid]["players_count"])) {
$nonprivate_name_beginning_char_count = 2;
for ($player_count=0; $player_count<$chunk_assoc[$chunk_luid]["players_count"]; $player_count++) {
//echo "<div >".substr($chunk_assoc[$chunk_luid]["players"][$player_count]["name"], 0, $nonprivate_name_beginning_char_count)."</div>";
}
}
//if ($map_dict != null) {
// $chunkx_min = $map_dict["chunkx_min"];
// $chunkz_min = $map_dict["chunkz_min"];
@ -498,6 +507,27 @@ function echo_chunkymap_table() {
else {
//echo_hold( "<span style=\"font-size:1px\">&nbsp;</span>");
}
if (isset($chunk_assoc[$chunk_luid]["players_count"])) {
$nonprivate_name_beginning_char_count = 2;
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"];
$player_name = $chunk_assoc[$chunk_luid]["players"][$player_count]["name"];
if (strlen($chunk_assoc[$chunk_luid]["players"][$player_count]["name"])>$nonprivate_name_beginning_char_count) {
$player_name = substr($player_name, 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);
echo_hold( "<div style=\"position:absolute; left:$rel_x; top:$rel_z; width: $zoomed_head_w; height: $zoomed_head_h; border: 1px solid #73AD21\"><img src=\"images/chunkymap_character-head.png\"/>$player_name</div>" );
//$position_offset_x+=$character_icon_w;
}
}
//echo " <br/>".$x.",0,".$z;
echo_hold($alignment_comment);
echo_hold( "</td>\r\n");

BIN
web/images/chunkymap_character-face.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Loading…
Cancel
Save