diff --git a/chunk.py b/chunk.py index f801809..05ccd4b 100644 --- a/chunk.py +++ b/chunk.py @@ -365,140 +365,67 @@ class ChunkRenderer(object): return self._up_left_blocks up_left_blocks = property(_load_up_left_blocks) - def generate_pseudo_ancildata(self,x,y,z,blockid): + def generate_pseudo_ancildata(self,x,y,z,blockid, north_position = 0 ): """ Generates a pseudo ancillary data for blocks that depend of - what are surrounded and don't have ancillary data""" + what are surrounded and don't have ancillary data + + This uses a binary number of 4 digits to encode the info. + The encode is: + + Bit: 1 2 3 4 + Side: x y -x -y + Values: bit = 0 -> The corresponding side block has different blockid + bit = 1 -> The corresponding side block has same blockid + Example: if the bit1 is 1 that means that there is a block with + blockid in the side of the +x direction. + + You can rotate the pseudo data multiplying by 2 and + if it is > 15 subtracting 15 and adding 1. (moving bits + in the left direction is like rotate 90 degree in anticlockwise + direction). In this way can be used for maps with other + north orientation. + + North position can have the values 0, 1, 2, 3, corresponding to + north in bottom-left, bottom-right, top-right and top-left of + the screen. + + The rotation feature is not used anywhere yet. + """ blocks = self.blocks up_left_blocks = self.up_left_blocks up_right_blocks = self.up_right_blocks left_blocks = self.left_blocks right_blocks = self.right_blocks - - if ( # The block is surrounded by 0 blocks with same blockid - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 1 - # Now 3 in line, they should be more common: - - elif ( # The block is surrounded by 2 blocks with same blockid, along x axis - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 2 + pseudo_data = 0 - elif ( # The block is surrounded by 2 blocks with same blockid, along y axis - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 3 + # first check if we are in the border of a chunk, next check for chunks adjacent to this + # and finally check for a block with same blockid. I we aren't in the border of a chunk, + # check for the block having the sme blockid. - # Now 3 in corner: + if (up_right_blocks != None and up_right_blocks[0,y,z] == blockid) if x == 15 else blocks[x+1,y,z] == blockid: + pseudo_data = pseudo_data | 0b1000 - elif ( # The block is surrounded by 2 blocks with same blockid, in a -y to x corner - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 4 + if (right_blocks != None and right_blocks[x,0,z] == blockid) if y == 15 else blocks[x,y + 1,z] == blockid: + pseudo_data = pseudo_data | 0b0100 + + if (left_blocks != None and left_blocks[15,y,z] == blockid) if x == 0 else blocks[x - 1,y,z] == blockid: + pseudo_data = pseudo_data | 0b0010 + + if (up_left_blocks != None and up_left_blocks[x,15,z] == blockid) if y == 0 else blocks[x,y - 1,z] == blockid: + pseudo_data = pseudo_data | 0b0001 - elif ( # The block is surrounded by 2 blocks with same blockid, in a -y to -x corner - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 5 + # rotate the bits for other north orientations + while north_position > 0: + pseudo_data *= 2 + if pseudo_data > 15: + pseudo_data -= 16 + pseudo_data +=1 + north_position -= 1 + + return pseudo_data - elif ( # The block is surrounded by 2 blocks with same blockid, in a y to -x corner - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 6 - - elif ( # The block is surrounded by 2 blocks with same blockid, in a y to x corner - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 7 - - # Now 1 in dead end: - - elif ( # The block is surrounded by 1 blocks with same blockid, in +x - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 8 - - elif ( # The block is surrounded by 1 blocks with same blockid, in -y - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 9 - - elif ( # The block is surrounded by 1 blocks with same blockid, in -x - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 10 - - elif ( # The block is surrounded by 1 blocks with same blockid, in +y - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 11 - - # Now surrounded by 3 identical blocks: - - elif ( # The block is surrounded by 3 blocks with same blockid, in postiions -x, -y, +x - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] != blockid if y == 15 else blocks[x,y + 1,z] != blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 12 - - elif ( # The block is surrounded by 3 blocks with same blockid, in postiions +y, -y, -x - (up_right_blocks[0,y,z] != blockid if x == 15 else blocks[x+1,y,z] != blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 13 - - elif ( # The block is surrounded by 3 blocks with same blockid, in postiions -x, +y, +x - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] != blockid if y == 0 else blocks[x,y - 1,z] != blockid) - ): return 14 - - elif ( # The block is surrounded by 3 blocks with same blockid, in postiions +y, -y, +x - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] != blockid if x == 0 else blocks[x - 1,y,z] != blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 15 - - # Block completely sourrounded by 4 blocks: - - elif ( # The block is surrounded completely - (up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid) and - (left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid) and - (right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid) and - (up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid) - ): return 16 - - else: return None - def _hash_blockarray(self): """Finds a hash of the block array""" if hasattr(self, "_digest"): diff --git a/config.js b/config.js index ac301cc..c841130 100644 --- a/config.js +++ b/config.js @@ -5,6 +5,7 @@ defaultZoom: 1, maxZoom: {maxzoom}, cacheMinutes: 0, // Change this to have browsers automatically request new images every x minutes + bg_color: '#1A1A1A', debug: false }; @@ -36,12 +37,14 @@ var signGroups = [ * Required: * label : string. Displayed on the control. * path : string. Location of the rendered tiles. + * Optional: + * base : string. Base of the url path for tile locations, useful for serving tiles from a different server than the js/html server. */ var mapTypeData=[ {'label': 'Unlit', 'path': 'tiles'}, // {'label': 'Day', 'path': 'lighting/tiles'}, // {'label': 'Night', 'path': 'night/tiles'}, -// {'label': 'Spawn', 'path': 'spawn/tiles'} +// {'label': 'Spawn', 'path': 'spawn/tiles', 'base': 'http://example.cdn.amazon.com/'} ]; // Please leave the following variables here: diff --git a/quadtree.py b/quadtree.py index ead65e8..088f917 100644 --- a/quadtree.py +++ b/quadtree.py @@ -26,6 +26,8 @@ import json import logging import util import cPickle +import stat +from time import gmtime, strftime from PIL import Image @@ -38,6 +40,26 @@ This module has routines related to generating a quadtree of tiles """ +def mirror_dir(src, dst, entities=None): + '''copies all of the entities from src to dst''' + if not os.path.exists(dst): + os.mkdir(dst) + if entities and type(entities) != list: raise Exception("Expected a list, got a %r instead" % type(entities)) + + for entry in os.listdir(src): + if entities and entry not in entities: continue + if os.path.isdir(os.path.join(src,entry)): + mirror_dir(os.path.join(src, entry), os.path.join(dst, entry)) + elif os.path.isfile(os.path.join(src,entry)): + try: + shutil.copy(os.path.join(src, entry), os.path.join(dst, entry)) + except IOError: + # maybe permission problems? + os.chmod(os.path.join(src, entry), stat.S_IRUSR) + os.chmod(os.path.join(dst, entry), stat.S_IWUSR) + shutil.copy(os.path.join(src, entry), os.path.join(dst, entry)) + # if this stills throws an error, let it propagate up + def iterate_base4(d): """Iterates over a base 4 number with d digits""" return itertools.product(xrange(4), repeat=d) @@ -147,9 +169,17 @@ class QuadtreeGen(object): blank.save(os.path.join(tileDir, "blank."+self.imgformat)) # copy web assets into destdir: - for root, dirs, files in os.walk(os.path.join(util.get_program_path(), "web_assets")): - for f in files: - shutil.copy(os.path.join(root, f), self.destdir) + mirror_dir(os.path.join(util.get_program_path(), "web_assets"), self.destdir) + + # Add time in index.html + indexpath = os.path.join(self.destdir, "index.html") + + index = open(indexpath, 'r').read() + index = index.replace( + "{time}", str(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))) + + with open(os.path.join(self.destdir, "index.html"), 'w') as output: + output.write(index) if skipjs: return diff --git a/setup.py b/setup.py index bc4ca85..55ee8bb 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ setup_kwargs['cmdclass'] = {} if py2exe != None: setup_kwargs['console'] = ['gmap.py'] - setup_kwargs['data_files'] = [('textures', ['textures/lava.png', 'textures/water.png']), + setup_kwargs['data_files'] = [('textures', ['textures/lava.png', 'textures/water.png', 'textures/fire.png']), ('', ['config.js', 'COPYING.txt', 'README.rst']), ('web_assets', glob.glob('web_assets/*'))] setup_kwargs['zipfile'] = None diff --git a/textures.py b/textures.py index 5efb889..bc2eb41 100644 --- a/textures.py +++ b/textures.py @@ -761,115 +761,21 @@ def generate_special_texture(blockID, data): # +y axis points bottom right direction # First compose small sticks in the back of the image, # then big stick and thecn small sticks in the front. - if data == 1: - img = fence_big - return (img.convert("RGB"),img.split()[3]) - - elif data == 2: #fence in line with x axis + + if (data & 0b0001) == 1: + composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left + if (data & 0b1000) == 8: composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - elif data == 3: #fence in line with y axis - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 4: #fence corner +x, -y - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - return (img.convert("RGB"),img.split()[3]) - - elif data == 5: #fence corner -x, -y - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - - elif data == 6: #fence corner -x, +y - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) + composite.alpha_over(img,fence_big,(0,0),fence_big) - elif data == 7: #fence corner +x, +y - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 8: #fence dead end +x - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - return (img.convert("RGB"),img.split()[3]) - - elif data == 9: #fence dead end -y - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - return (img.convert("RGB"),img.split()[3]) - - elif data == 10: #fence dead end -x - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - - elif data == 11: #fence dead end +y - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 12: #fence cross with +y missing - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - - elif data == 13: #fence cross with +x missing - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) + if (data & 0b0010) == 2: composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left + if (data & 0b0100) == 4: composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - elif data == 14: #fence cross with -y missing - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - elif data == 15: #fence cross with -x missing - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 16: #fence cross - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - elif data == None: # This can happend if a fence is in the border - # of a chunk and the chunk is in the border of the map. - composite.alpha_over(img,fence_big,(0,0),) - return (img.convert("RGB"), img.split()[3]) - - else: # just in case - composite.alpha_over(img,fence_big,(0,0),) - return (img.convert("RGB"), img.split()[3]) + return (img.convert("RGB"),img.split()[3]) + return None diff --git a/web_assets/functions.js b/web_assets/functions.js index ff8da92..9b42fda 100644 --- a/web_assets/functions.js +++ b/web_assets/functions.js @@ -184,7 +184,7 @@ function initMarkers() { if (item.type == 'sign') { iconURL = 'signpost_icon.png';} - console.log(signGroup.icon); + //console.log(signGroup.icon); if (signGroup.icon) { iconURL = signGroup.icon; } @@ -280,6 +280,7 @@ function initialize() { }, mapTypeId: mapTypeIdDefault, streetViewControl: false, + backgroundColor: config.bg_color, }; map = new google.maps.Map(document.getElementById('mcmap'), mapOptions); @@ -383,9 +384,10 @@ function initialize() { return new google.maps.LatLng(lat, lng); } -function getTileUrlGenerator(path) { +function getTileUrlGenerator(path, path_base) { return function(tile, zoom) { var url = path; + var url_base = ( path_base ? path_base : '' ); if(tile.x < 0 || tile.x >= Math.pow(2, zoom) || tile.y < 0 || tile.y >= Math.pow(2, zoom)) { url += '/blank'; } else if(zoom == 0) { @@ -402,7 +404,7 @@ function getTileUrlGenerator(path) { var d = new Date(); url += '?c=' + Math.floor(d.getTime() / (1000 * 60 * config.cacheMinutes)); } - return(url); + return(url_base + url); } } @@ -414,7 +416,7 @@ for (idx in mapTypeData) { var view = mapTypeData[idx]; MCMapOptions[view.label] = { - getTileUrl: getTileUrlGenerator(view.path), + getTileUrl: getTileUrlGenerator(view.path, view.base), tileSize: new google.maps.Size(config.tileSize, config.tileSize), maxZoom: config.maxZoom, minZoom: 0, diff --git a/web_assets/index.html b/web_assets/index.html index e77fee7..89554e8 100644 --- a/web_assets/index.html +++ b/web_assets/index.html @@ -12,6 +12,7 @@ +