From 7f51bccf477460d94e8c7775d29848f6f5597a96 Mon Sep 17 00:00:00 2001 From: JacobF Date: Tue, 6 Sep 2011 15:11:46 -0400 Subject: [PATCH] update minetestmapper so it can read the database also --- util/minetestmapper.py | 73 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/util/minetestmapper.py b/util/minetestmapper.py index e13a1bdc3..c7ec0774e 100755 --- a/util/minetestmapper.py +++ b/util/minetestmapper.py @@ -85,6 +85,13 @@ def int_to_hex4(i): return "%04X" % i +def getBlockAsInteger(p): + return p[2]*16777216 + p[1]*4096 + p[0] + +def getIntegerAsBlock(i): + return i%4096, int(i/4096)%4096, int(i/16777216)%4096 + + def limit(i, l, h): if(i > h): i = h @@ -169,6 +176,30 @@ zlist = [] # List all sectors to memory and calculate the width and heigth of the # resulting picture. + +conn = None +cur = None +if os.path.exists(path + "map.sqlite"): + import sqlite3 + conn = sqlite3.connect(path + "map.sqlite") + cur = conn.cursor() + + cur.execute("SELECT `pos` FROM `blocks`") + while True: + r = cur.fetchone() + if not r: + break + + x, y, z = getIntegerAsBlock (r[0]) + + if x < sector_xmin or x > sector_xmax: + continue + if z < sector_zmin or z > sector_zmax: + continue + + xlist.append(x) + zlist.append(z) + if os.path.exists(path + "sectors2"): for filename in os.listdir(path + "sectors2"): for filename2 in os.listdir(path + "sectors2/" + filename): @@ -305,6 +336,16 @@ for n in range(len(xlist)): sectortype = "" + if cur: + ps = getBlockAsInteger((xpos, 0, zpos)) + cur.execute("SELECT `pos` FROM `blocks` WHERE `pos`>=? AND `pos` 0: for (ypos, filename) in ylist2: + ps = getBlockAsInteger((xpos, ypos, zpos)) + cur.execute("SELECT `data` FROM `blocks` WHERE `pos`==? LIMIT 1", (ps,)) + r = cur.fetchone() + if not r: + continue + filename = "mtm_tmp" + f = file(filename, 'wb') + f.write(r[0]) + f.close() + f = file(filename, "rb") version = ord(f.read(1)) @@ -495,5 +557,8 @@ if drawplayers: except OSError: pass +if os.path.isfile("mtm_tmp"): + os.remove("mtm_tmp") + print "Saving" im.save(output)