support for opening worlds by name
This commit is contained in:
@@ -123,7 +123,7 @@ Running
|
|||||||
-------
|
-------
|
||||||
To generate a set of Google Map tiles, use the gmap.py script like this::
|
To generate a set of Google Map tiles, use the gmap.py script like this::
|
||||||
|
|
||||||
python gmap.py [OPTIONS] <World Number / Path to World> <Output Directory>
|
python gmap.py [OPTIONS] <World # / Name / Path to World> <Output Directory>
|
||||||
|
|
||||||
The output directory will be created if it doesn't exist. This will generate a
|
The output directory will be created if it doesn't exist. This will generate a
|
||||||
set of image tiles for your world in the directory you choose. When it's done,
|
set of image tiles for your world in the directory you choose. When it's done,
|
||||||
|
|||||||
18
gmap.py
18
gmap.py
@@ -36,8 +36,8 @@ import world
|
|||||||
import quadtree
|
import quadtree
|
||||||
|
|
||||||
helptext = """
|
helptext = """
|
||||||
%prog [OPTIONS] <World # / Path to World> <tiles dest dir>
|
%prog [OPTIONS] <World # / Name / Path to World> <tiles dest dir>
|
||||||
%prog -d <World # / Path to World / Path to cache dir> [tiles dest dir]"""
|
%prog -d <World # / Name / Path to World / Path to cache dir> [tiles dest dir]"""
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@@ -69,11 +69,21 @@ def main():
|
|||||||
worlddir = args[0]
|
worlddir = args[0]
|
||||||
|
|
||||||
if not os.path.exists(worlddir):
|
if not os.path.exists(worlddir):
|
||||||
|
# world given is either world number, or name
|
||||||
try:
|
try:
|
||||||
worldnum = int(worlddir)
|
worldnum = int(worlddir)
|
||||||
worlddir = world.get_worlds()[worldnum]['path']
|
worlddir = world.get_worlds()[worldnum]['path']
|
||||||
except (ValueError, KeyError):
|
except ValueError:
|
||||||
print "Invalid world number or directory"
|
# it wasn't a number, try using it as a name
|
||||||
|
worlddir = os.path.join(world.get_save_dir(), worlddir)
|
||||||
|
if not os.path.exists(worlddir):
|
||||||
|
# still doesn't exist! print help and die.
|
||||||
|
print "Invalid world name or path"
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
except KeyError:
|
||||||
|
# it was an invalid number
|
||||||
|
print "Invalid world number"
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user