0

removes tiles if they no longer exist

This commit is contained in:
Andrew Brown
2010-09-07 21:52:56 -04:00
parent b0b9a9a71a
commit b6ceb536da

View File

@@ -426,6 +426,7 @@ def quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, quadr
# If one does exist, from a previous world or something, it is not # If one does exist, from a previous world or something, it is not
# deleted, but None is returned to indicate to our caller this tile # deleted, but None is returned to indicate to our caller this tile
# is blank. # is blank.
remove_tile(prefix, quadrant)
return None, newhash return None, newhash
if img is True: if img is True:
# No image was returned because the hashes matched. Return the path # No image was returned because the hashes matched. Return the path
@@ -516,10 +517,9 @@ def quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, quadr
# filenames are None, this tile should not be rendered. However, we # filenames are None, this tile should not be rendered. However, we
# still need to return a valid hash for it, so that's why this check is # still need to return a valid hash for it, so that's why this check is
# below the hash check. # below the hash check.
# For the confused: Python boolean values are a subclass of integers, if not (bool(quad0file) or bool(quad1file) or bool(quad2file) or
# and True has value 1, so I can do this: bool(quad3file)):
if (bool(quad0file) + bool(quad1file) + bool(quad2file) + remove_tile(prefix, quadrant)
bool(quad3file)) == 0:
return None, newhash return None, newhash
img = Image.new("RGBA", (384, 384)) img = Image.new("RGBA", (384, 384))
@@ -553,3 +553,17 @@ def quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, quadr
# Return the location and hash of this tile # Return the location and hash of this tile
return path, newhash return path, newhash
def remove_tile(prefix, quadrent):
"""Called when a tile doesn't exist, this deletes an existing tile if it
does
"""
path = os.path.join(prefix, quadrent)
img = path + ".png"
hash = path + ".hash"
if os.path.exists(img):
print "removing", img
os.unlink(img)
if os.path.exists(hash):
os.unlink(hash)