corrected world loading by name to handle renamed worlds
This commit is contained in:
12
gmap.py
12
gmap.py
@@ -70,14 +70,16 @@ def main():
|
|||||||
|
|
||||||
if not os.path.exists(worlddir):
|
if not os.path.exists(worlddir):
|
||||||
# world given is either world number, or name
|
# world given is either world number, or name
|
||||||
|
worlds = world.get_worlds()
|
||||||
try:
|
try:
|
||||||
worldnum = int(worlddir)
|
worldnum = int(worlddir)
|
||||||
worlddir = world.get_worlds()[worldnum]['path']
|
worlddir = worlds[worldnum]['path']
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# it wasn't a number, try using it as a name
|
# it wasn't a number or path, try using it as a name
|
||||||
worlddir = os.path.join(world.get_save_dir(), worlddir)
|
try:
|
||||||
if not os.path.exists(worlddir):
|
worlddir = worlds[worlddir]['path']
|
||||||
# still doesn't exist! print help and die.
|
except KeyError:
|
||||||
|
# it's not a number, name, or path
|
||||||
print "Invalid world name or path"
|
print "Invalid world name or path"
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
12
world.py
12
world.py
@@ -392,7 +392,7 @@ def get_save_dir():
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
def get_worlds():
|
def get_worlds():
|
||||||
"Returns {world # : level.dat information}"
|
"Returns {world # or name : level.dat information}"
|
||||||
ret = {}
|
ret = {}
|
||||||
save_dir = get_save_dir()
|
save_dir = get_save_dir()
|
||||||
|
|
||||||
@@ -401,12 +401,14 @@ def get_worlds():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
for dir in os.listdir(save_dir):
|
for dir in os.listdir(save_dir):
|
||||||
|
world_dat = os.path.join(save_dir, dir, "level.dat")
|
||||||
|
if not os.path.exists(world_dat): continue
|
||||||
|
info = nbt.load(world_dat)[1]
|
||||||
|
info['Data']['path'] = os.path.join(save_dir, dir)
|
||||||
if dir.startswith("World") and len(dir) == 6:
|
if dir.startswith("World") and len(dir) == 6:
|
||||||
world_n = int(dir[-1])
|
world_n = int(dir[-1])
|
||||||
world_dat = os.path.join(save_dir, dir, "level.dat")
|
|
||||||
if not os.path.exists(world_dat): continue
|
|
||||||
info = nbt.load(world_dat)[1]
|
|
||||||
info['Data']['path'] = os.path.join(save_dir, dir)
|
|
||||||
ret[world_n] = info['Data']
|
ret[world_n] = info['Data']
|
||||||
|
if 'LevelName' in info['Data'].keys():
|
||||||
|
ret[info['Data']['LevelName']] = info['Data']
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
Reference in New Issue
Block a user