Fixes for unusual story loading circumstances.
This PR does three things when loading a story from within the browser: 1. Prevents an error if a story file is not valid JSON. 2. Catches an error is a file is JSON, but lacks an actions property. 3. Replaces getcwd() and instead uses the path of the script file itself in case someone does not start the app from the current working directory.
This commit is contained in:
parent
97aba93ef1
commit
bbe3a92ce4
18
fileops.py
18
fileops.py
|
@ -59,14 +59,22 @@ def getdirpath(dir, title):
|
|||
#==================================================================#
|
||||
def getstoryfiles():
|
||||
list = []
|
||||
for file in listdir(getcwd()+"/stories"):
|
||||
for file in listdir(path.dirname(path.realpath(__file__))+"/stories"):
|
||||
if file.endswith(".json"):
|
||||
ob = {}
|
||||
ob["name"] = file.replace(".json", "")
|
||||
f = open(getcwd()+"/stories/"+file, "r")
|
||||
js = json.load(f)
|
||||
f = open(path.dirname(path.realpath(__file__))+"/stories/"+file, "r")
|
||||
try:
|
||||
js = json.load(f)
|
||||
except:
|
||||
print("Browser loading error: Story file is malformed or not a JSON file.")
|
||||
f.close()
|
||||
continue
|
||||
f.close()
|
||||
ob["actions"] = len(js["actions"])
|
||||
try:
|
||||
ob["actions"] = len(js["actions"])
|
||||
except TypeError:
|
||||
print("Browser loading error: Story file has incorrect format.")
|
||||
list.append(ob)
|
||||
return list
|
||||
|
||||
|
@ -74,4 +82,4 @@ def getstoryfiles():
|
|||
# Returns True if json file exists with requested save name
|
||||
#==================================================================#
|
||||
def saveexists(name):
|
||||
return path.exists(getcwd()+"/stories/"+name+".json")
|
||||
return path.exists(path.dirname(os.path.realpath(__file__))+"/stories/"+name+".json")
|
Loading…
Reference in New Issue