Browse Source

working on loading new chunk folder layout

master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
faaf94f9f8
  1. 17
      chunkymap-regen.py
  2. 84
      web/chunkymap.php

17
chunkymap-regen.py

@ -59,6 +59,9 @@ class InstalledFile:
self.source_dir_path=source_dir_path self.source_dir_path=source_dir_path
self.dest_dir_path=dest_dir_path self.dest_dir_path=dest_dir_path
def ivec2_equals(pos1, pos2):
return (int(pos1[0])==int(pos2[0])) and (int(pos1[1])==int(pos2[1]))
def get_dict_from_conf_file(path,assignment_operator="="): def get_dict_from_conf_file(path,assignment_operator="="):
results = None results = None
results = get_dict_modified_by_conf_file(results, path, assignment_operator) results = get_dict_modified_by_conf_file(results, path, assignment_operator)
@ -783,8 +786,8 @@ class MTChunks:
chunk16_coord_list.append( coords ) chunk16_coord_list.append( coords )
if self.todo_index<len(self.todo_positions): if self.todo_index<len(self.todo_positions):
for index in range(self.todo_index,len(self.todo_positions)): for index in range(self.todo_index,len(self.todo_positions)):
if self.todo_positions == coords: if ivec2_equals(self.todo_positions[self.todo_index], coords):
is_any_part_queued = False is_any_part_queued = True
break break
if is_any_part_queued: if is_any_part_queued:
break break
@ -799,7 +802,7 @@ class MTChunks:
decachunk_yaml_path = self.get_decachunk_yaml_path_from_decachunk(decachunky_x, decachunky_z) decachunk_yaml_path = self.get_decachunk_yaml_path_from_decachunk(decachunky_x, decachunky_z)
decachunk_image_path = self.get_decachunk_image_path_from_decachunk(decachunky_x, decachunky_z) decachunk_image_path = self.get_decachunk_image_path_from_decachunk(decachunky_x, decachunky_z)
combined_count = 0 combined_count = 0
luid_list = list() contains_chunk_luids = list()
for coord in chunk16_coord_list: for coord in chunk16_coord_list:
chunky_x, chunky_z = coord chunky_x, chunky_z = coord
chunk_image_path = self.get_chunk_image_path(chunky_x, chunky_z) chunk_image_path = self.get_chunk_image_path(chunky_x, chunky_z)
@ -817,7 +820,7 @@ class MTChunks:
chunk_local_coords = chunk_global_coords[0]-decachunk_global_coords[0], chunk_global_coords[1]-decachunk_global_coords[1] chunk_local_coords = chunk_global_coords[0]-decachunk_global_coords[0], chunk_global_coords[1]-decachunk_global_coords[1]
offset = chunk_local_coords[0], 160-chunk_local_coords[1] # convert to inverted cartesian since that's the coordinate system of images offset = chunk_local_coords[0], 160-chunk_local_coords[1] # convert to inverted cartesian since that's the coordinate system of images
im.paste(chunk_im, offset) im.paste(chunk_im, offset)
luid_list.append(self.get_chunk_luid(chunky_x, chunky_z)) contains_chunk_luids.append(self.get_chunk_luid(chunky_x, chunky_z))
except: except:
print("Could not finish "+participle+" in check_decachunk_containing_chunk:") print("Could not finish "+participle+" in check_decachunk_containing_chunk:")
view_traceback() view_traceback()
@ -834,10 +837,10 @@ class MTChunks:
this_second = int(time.time()) this_second = int(time.time())
#if int(self.decachunks[decachunk_luid].metadata["last_saved_utc_second"]) != this_second: #if int(self.decachunks[decachunk_luid].metadata["last_saved_utc_second"]) != this_second:
self.decachunks[decachunk_luid].metadata["last_saved_utc_second"] = this_second # time.time() returns float even if OS doesn't give a time in increments smaller than seconds self.decachunks[decachunk_luid].metadata["last_saved_utc_second"] = this_second # time.time() returns float even if OS doesn't give a time in increments smaller than seconds
if len(luid_list)>0: if len(contains_chunk_luids)>0:
self.decachunks[decachunk_luid].metadata["luid_list"] = ','.join(luid_list) self.decachunks[decachunk_luid].metadata["contains_chunk_luids"] = ','.join(contains_chunk_luids)
else: else:
self.decachunks[decachunk_luid].metadata["luid_list"] = None self.decachunks[decachunk_luid].metadata["contains_chunk_luids"] = None
self.decachunks[decachunk_luid].save_yaml(decachunk_yaml_path) self.decachunks[decachunk_luid].save_yaml(decachunk_yaml_path)
def get_chunk_folder_path(self, chunky_x, chunky_z): def get_chunk_folder_path(self, chunky_x, chunky_z):

84
web/chunkymap.php

@ -39,7 +39,7 @@ if (!isset($chunkymap_view_zoom_multiplier)) {
// OPTIONAL: // OPTIONAL:
$chunkymapdata_path = "chunkymapdata"; $chunkymapdata_path = "chunkymapdata";
$chunkymap_16px_path = "chunkymapdata/16px"; $chunkymapdata_thisworld_path = null;
$showplayers=true; $showplayers=true;
// NOT OPTIONAL: // NOT OPTIONAL:
@ -88,8 +88,7 @@ function get_dict_from_conf($path, $assignment_operator) {
} }
return $result; return $result;
}//end get_dict_from_conf }//end get_dict_from_conf
$map_dict = null;
$map_dict = get_dict_from_conf($chunkymapdata_path."/generated.yml",":");
//startsWith and endsWith are from: //startsWith and endsWith are from:
//Salmon A. stackoverflow. <http://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php>. 5 Feb 2016. 19 Feb, 2016. //Salmon A. stackoverflow. <http://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php>. 5 Feb 2016. 19 Feb, 2016.
@ -209,8 +208,17 @@ function echo_chunkymap_controls($callback_php_path) {
$in_html="<img src=\"images/$in_img_name\" style=\"width:16pt; height:16pt\" />"; $in_html="<img src=\"images/$in_img_name\" style=\"width:16pt; height:16pt\" />";
$out_html="<img src=\"images/$out_img_name\" style=\"width:16pt; height:16pt\" />"; $out_html="<img src=\"images/$out_img_name\" style=\"width:16pt; height:16pt\" />";
if ($is_in) $in_html="<a href=\"?chunkymap_view_zoom_multiplier=$in_zoom#$chunkymap_anchor_name\">$in_html</a>"; global $world_name;
if ($is_out) $out_html="<a href=\"?chunkymap_view_zoom_multiplier=$out_zoom#$chunkymap_anchor_name\">$out_html</a>"; $append_vars="&";
if (isset($world_name)) {
$prefix = "";
if (strlen($append_vars)>0 && !endsWith($append_vars,"&") ) {
$prefix = "&";
}
$append_vars.="$prefix"."world_name=$world_name";
}
if ($is_in) $in_html="<a href=\"?chunkymap_view_zoom_multiplier=$in_zoom"."$append_vars"."#$chunkymap_anchor_name\">$in_html</a>";
if ($is_out) $out_html="<a href=\"?chunkymap_view_zoom_multiplier=$out_zoom"."$append_vars"."#$chunkymap_anchor_name\">$out_html</a>";
echo $in_html; echo $in_html;
echo $out_html; echo $out_html;
} }
@ -243,7 +251,7 @@ function echo_map_heading_text() {
// else echo "<span style=\"color:red\">(missing world name)</span>"; // else echo "<span style=\"color:red\">(missing world name)</span>";
// } // }
function get_chunk_folder_path($x, $z) { function get_chunk_folder_path($x, $z) {
global $chunkymapdata_path; global $chunkymapdata_thisworld_path;
//NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0 //NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0
$decachunk_x = intval(floor($x/10)); $decachunk_x = intval(floor($x/10));
$decachunk_z = intval(floor($z/10)); $decachunk_z = intval(floor($z/10));
@ -251,16 +259,16 @@ function get_chunk_folder_path($x, $z) {
//else { $decachunk_x = $x - $x%10; } //else { $decachunk_x = $x - $x%10; }
//if ($z<0) { $decachunk_z = $z + $z%10; } //if ($z<0) { $decachunk_z = $z + $z%10; }
//else { $decachunk_z = $z - $z%10; } //else { $decachunk_z = $z - $z%10; }
$result = $chunkymapdata_path.'/16px/'.$decachunk_x.'/'.$decachunk_z; $result = $chunkymapdata_thisworld_path.'/16px/'.$decachunk_x.'/'.$decachunk_z;
return $result; return $result;
} }
function get_superchunk_folder_path($x, $z) { function get_superchunk_folder_path($x, $z) {
global $chunkymapdata_path; global $chunkymapdata_thisworld_path;
//NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0 //NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0
$hectochunk_x = intval(floor($x/100)); $hectochunk_x = intval(floor($x/100));
$hectochunk_z = intval(floor($z/100)); $hectochunk_z = intval(floor($z/100));
$result = $chunkymapdata_path.'/160px/'.$hectochunk_x.'/'.$hectochunk_z; $result = $chunkymapdata_thisworld_path.'/160px/'.$hectochunk_x.'/'.$hectochunk_z;
return $result; return $result;
} }
@ -284,6 +292,8 @@ function echo_entire_chunkymap_as_chunk_table() {
global $chunkymap_tile_original_w; global $chunkymap_tile_original_w;
global $chunkymap_tile_original_h; global $chunkymap_tile_original_h;
global $chunkymap_view_zoom_max; global $chunkymap_view_zoom_max;
global $world_name;
if ($chunkymap_view_zoom_multiplier<$chunkymap_view_zoom_min) $chunkymap_view_zoom_multiplier = $chunkymap_view_zoom_min; if ($chunkymap_view_zoom_multiplier<$chunkymap_view_zoom_min) $chunkymap_view_zoom_multiplier = $chunkymap_view_zoom_min;
if ($chunkymap_view_zoom_multiplier>$chunkymap_view_zoom_max) $chunkymap_view_zoom_multiplier = $chunkymap_view_zoom_max; if ($chunkymap_view_zoom_multiplier>$chunkymap_view_zoom_max) $chunkymap_view_zoom_multiplier = $chunkymap_view_zoom_max;
//$zoom_divisor = (int)(100/$chunkymap_view_zoom_multiplier); //$zoom_divisor = (int)(100/$chunkymap_view_zoom_multiplier);
@ -301,8 +311,18 @@ function echo_entire_chunkymap_as_chunk_table() {
$player_count = 0; $player_count = 0;
$character_icon_w=8; $character_icon_w=8;
$character_icon_h=8; $character_icon_h=8;
global $chunkymapdata_thisworld_path;
if (isset($world_name)) {
$chunkymapdata_thisworld_path = $chunkymapdata_path."/".$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) { if ($showplayers==true) {
$chunkymap_players_path = $chunkymapdata_path."/players"; $chunkymap_players_path = $chunkymapdata_thisworld_path."/players";
if ($handle = opendir($chunkymap_players_path)) { if ($handle = opendir($chunkymap_players_path)) {
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
if (substr($file, 0, 1) != ".") { if (substr($file, 0, 1) != ".") {
@ -310,7 +330,12 @@ function echo_entire_chunkymap_as_chunk_table() {
if (endsWith($file_lower, ".yml")) { if (endsWith($file_lower, ".yml")) {
$player_id=substr($file,0,strlen($file)-4); //-4 for .yml $player_id=substr($file,0,strlen($file)-4); //-4 for .yml
$file_path = $chunkymap_players_path."/".$file; $file_path = $chunkymap_players_path."/".$file;
if (is_file($file_path)) {
$player_dict = get_dict_from_conf($file_path,":"); $player_dict = get_dict_from_conf($file_path,":");
}
else {
echo_error("Missing '$player_dict'");
}
$player_dict["id"]=$player_id; $player_dict["id"]=$player_id;
//$players[$player_count]=get_dict_from_conf($file_path); //$players[$player_count]=get_dict_from_conf($file_path);
//$players[$player_count]["id"]=$player_id; //$players[$player_count]["id"]=$player_id;
@ -379,7 +404,7 @@ function echo_entire_chunkymap_as_chunk_table() {
//else { //else {
//echo "calculating range..."; //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: //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_path.'/'."16px"; $chunks_16px_path = $chunkymapdata_thisworld_path.'/'."16px";
if ($chunks_16px_handle = opendir($chunks_16px_path)) { if ($chunks_16px_handle = opendir($chunks_16px_path)) {
while (false !== ($decachunk_x_name = readdir($chunks_16px_handle))) { while (false !== ($decachunk_x_name = readdir($chunks_16px_handle))) {
$decachunk_x_path = $chunks_16px_path."/".$decachunk_x_name; $decachunk_x_path = $chunks_16px_path."/".$decachunk_x_name;
@ -454,7 +479,7 @@ function echo_entire_chunkymap_as_chunk_table() {
$minute=60; $minute=60;
$player_file_age_expired_max_seconds=20*$minute-1; $player_file_age_expired_max_seconds=20*$minute-1;
$player_file_age_idle_max_seconds=5*$minute-1; $player_file_age_idle_max_seconds=5*$minute-1;
$chunks_16px_path = $chunkymapdata_path.'/'."16px"; $chunks_16px_path = $chunkymapdata_thisworld_path.'/'."16px";
while ($z >= $chunkz_min) { while ($z >= $chunkz_min) {
echo_hold( " <tr>\r\n"); echo_hold( " <tr>\r\n");
$x = (int)$chunkx_min; $x = (int)$chunkx_min;
@ -463,11 +488,11 @@ function echo_entire_chunkymap_as_chunk_table() {
$this_zoomed_h = $zoomed_h; $this_zoomed_h = $zoomed_h;
$chunk_yaml_name = $x_opener.$x.$z_opener.$z.$dot_yaml; $chunk_yaml_name = $x_opener.$x.$z_opener.$z.$dot_yaml;
//$chunk_yaml_path = $chunkymapdata_path.'/'.$chunk_yaml_name; //$chunk_yaml_path = $chunkymapdata_thisworld_path.'/'.$chunk_yaml_name;
//$chunk_yaml_path = $chunks_16px_path.'/'. //$chunk_yaml_path = $chunks_16px_path.'/'.
$chunk_yaml_path = get_chunk_folder_path($x, $z).'/'.$chunk_yaml_name; $chunk_yaml_path = get_chunk_folder_path($x, $z).'/'.$chunk_yaml_name;
//$chunk_genresult_name = $x_opener.$x.$z_opener.$z.$genresult_suffix_then_dot_then_ext; //$chunk_genresult_name = $x_opener.$x.$z_opener.$z.$genresult_suffix_then_dot_then_ext;
//$chunk_genresult_path = $chunkymapdata_path.'/'.$chunk_img_name; //$chunk_genresult_path = $chunkymapdata_thisworld_path.'/'.$chunk_img_name;
$td_style_suffix=""; $td_style_suffix="";
$element_align_style_suffix=""; $element_align_style_suffix="";
$alignment_comment=""; $alignment_comment="";
@ -625,4 +650,35 @@ function echo_entire_chunkymap_as_chunk_table() {
echo " </table>\r\n"; echo " </table>\r\n";
echo "</center>\r\n"; echo "</center>\r\n";
} }
else { //not isset($world_name)
echo "<h4>Choose world:</h4>";
echo "<ul>";
if ($chunkymapdata_handle = opendir($chunkymapdata_path)) {
$append_vars="&";
if (isset($chunkymap_view_zoom_multiplier)) {
$prefix = "";
if (strlen($append_vars)>0 and !endsWith($append_vars,"&")) {
$prefix = "&";
}
$append_vars.="$prefix"."&chunkymap_view_zoom_multiplier=$chunkymap_view_zoom_multiplier";
}
if (isset($chunkymap_anchor_name)) {
$prefix = "";
if (strlen($append_vars)>0) {
$prefix = "&";
}
$append_vars.="$prefix"."#$chunkymap_anchor_name";
}
global $chunkymap_anchor_name;
while (false !== ($this_world_name = readdir($chunkymapdata_handle))) {
if (substr($this_world_name, 0, 1) != ".") {
$this_world_path = $chunkymapdata_path."/".$this_world_name;
echo "<li><a href=\"?world_name=$this_world_name"."$append_vars#$chunkymap_anchor_name"."\">$this_world_name</a></li>";
}
}
closedir($chunkymapdata_handle);
}
echo "</ul>";
}
}
?> ?>

Loading…
Cancel
Save