make it easier for the user to use a map in an expected location, show some information about found saves
This commit is contained in:
34
gmap.py
34
gmap.py
@@ -6,12 +6,13 @@ import os.path
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import re
|
import re
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import time
|
||||||
|
|
||||||
import world
|
import world
|
||||||
import quadtree
|
import quadtree
|
||||||
|
|
||||||
helptext = """
|
helptext = """
|
||||||
%prog [-p PROCS] [-d] <Path to World> <tiles dest dir>
|
%prog [-p PROCS] [-d] <World # / Path to World> <tiles dest dir>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -27,18 +28,28 @@ def main():
|
|||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
print "You need to give me your world directory"
|
print "You need to give me your world number or directory"
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
list_worlds()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
worlddir = args[0]
|
worlddir = args[0]
|
||||||
|
|
||||||
|
if not os.path.exists(worlddir):
|
||||||
|
try:
|
||||||
|
worldnum = int(worlddir)
|
||||||
|
worlddir = world.get_worlds()[worldnum]['path']
|
||||||
|
except (ValueError, KeyError):
|
||||||
|
print "Invalid world number or directory"
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
parser.error("Where do you want to save the tiles?")
|
parser.error("Where do you want to save the tiles?")
|
||||||
destdir = args[1]
|
destdir = args[1]
|
||||||
|
|
||||||
if options.delete:
|
if options.delete:
|
||||||
return delete_all(worlddir, destdir)
|
return delete_all(worlddir, destdir)
|
||||||
|
|
||||||
# First generate the world's chunk images
|
# First generate the world's chunk images
|
||||||
w = world.WorldRenderer(worlddir)
|
w = world.WorldRenderer(worlddir)
|
||||||
w.go(options.procs)
|
w.go(options.procs)
|
||||||
@@ -67,5 +78,22 @@ def delete_all(worlddir, tiledir):
|
|||||||
print "Deleting {0}".format(filepath)
|
print "Deleting {0}".format(filepath)
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
|
|
||||||
|
def list_worlds():
|
||||||
|
"Prints out a brief summary of saves found in the default directory"
|
||||||
|
print
|
||||||
|
worlds = world.get_worlds()
|
||||||
|
if not worlds:
|
||||||
|
print 'No world saves found in the usual place'
|
||||||
|
return
|
||||||
|
print "Detected saves:"
|
||||||
|
for num, info in sorted(worlds.iteritems()):
|
||||||
|
timestamp = time.strftime("%Y-%m-%d %H:%M",
|
||||||
|
time.localtime(info['LastPlayed'] / 1000))
|
||||||
|
playtime = info['Time'] / 20
|
||||||
|
playstamp = '%d:%02d' % (playtime / 3600, playtime / 60 % 60)
|
||||||
|
size = "%.2fMB" % (info['SizeOnDisk'] / 1024. / 1024.)
|
||||||
|
print "World %s: %s Playtime: %s Modified: %s" % (num, size, playstamp, timestamp)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
34
world.py
34
world.py
@@ -6,9 +6,11 @@ import multiprocessing
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
import chunk
|
import chunk
|
||||||
|
import nbt
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This module has routines related to generating all the chunks for a world
|
This module has routines related to generating all the chunks for a world
|
||||||
|
and for extracting information about available worlds
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -119,3 +121,35 @@ class WorldRenderer(object):
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def get_save_dir():
|
||||||
|
"""Returns the path to the local saves directory
|
||||||
|
* On Windows, at %APPDATA%/.minecraft/saves/
|
||||||
|
* On Darwin, at $HOME/Library/Application Support/minecraft/saves/
|
||||||
|
* at $HOME/.minecraft/saves/
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
savepaths = []
|
||||||
|
if "APPDATA" in os.environ:
|
||||||
|
savepaths += [os.path.join(os.environ['APPDATA'], ".minecraft", "saves")]
|
||||||
|
if "HOME" in os.environ:
|
||||||
|
savepaths += [os.path.join(os.environ['HOME'], "Library",
|
||||||
|
"Application Support", "minecraft", "saves")]
|
||||||
|
savepaths += [os.path.join(os.environ['HOME'], ".minecraft", "saves")]
|
||||||
|
|
||||||
|
for path in savepaths:
|
||||||
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
|
||||||
|
def get_worlds():
|
||||||
|
"Returns {world # : level.dat information}"
|
||||||
|
ret = {}
|
||||||
|
save_dir = get_save_dir()
|
||||||
|
for dir in os.listdir(save_dir):
|
||||||
|
if dir.startswith("World"):
|
||||||
|
world_n = int(dir[-1])
|
||||||
|
info = nbt.load(os.path.join(save_dir, dir, "level.dat"))[1]
|
||||||
|
info['Data']['path'] = os.path.join(save_dir, dir)
|
||||||
|
ret[world_n] = info['Data']
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|||||||
Reference in New Issue
Block a user