mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Merge https://github.com/KoboldAI/KoboldAI-Client/pull/58 into misc
This commit is contained in:
15
fileops.py
15
fileops.py
@@ -59,14 +59,23 @@ def getdirpath(dir, title):
|
|||||||
#==================================================================#
|
#==================================================================#
|
||||||
def getstoryfiles():
|
def getstoryfiles():
|
||||||
list = []
|
list = []
|
||||||
for file in listdir(getcwd()+"/stories"):
|
for file in listdir(path.dirname(path.realpath(__file__))+"/stories"):
|
||||||
if file.endswith(".json"):
|
if file.endswith(".json"):
|
||||||
ob = {}
|
ob = {}
|
||||||
ob["name"] = file.replace(".json", "")
|
ob["name"] = file.replace(".json", "")
|
||||||
f = open(getcwd()+"/stories/"+file, "r")
|
f = open(path.dirname(path.realpath(__file__))+"/stories/"+file, "r")
|
||||||
|
try:
|
||||||
js = json.load(f)
|
js = json.load(f)
|
||||||
|
except:
|
||||||
|
print("Browser loading error: Story file is malformed or not a JSON file.")
|
||||||
f.close()
|
f.close()
|
||||||
|
continue
|
||||||
|
f.close()
|
||||||
|
try:
|
||||||
ob["actions"] = len(js["actions"])
|
ob["actions"] = len(js["actions"])
|
||||||
|
except TypeError:
|
||||||
|
print("Browser loading error: Story file has incorrect format.")
|
||||||
|
continue
|
||||||
list.append(ob)
|
list.append(ob)
|
||||||
return list
|
return list
|
||||||
|
|
||||||
@@ -74,4 +83,4 @@ def getstoryfiles():
|
|||||||
# Returns True if json file exists with requested save name
|
# Returns True if json file exists with requested save name
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def saveexists(name):
|
def saveexists(name):
|
||||||
return path.exists(getcwd()+"/stories/"+name+".json")
|
return path.exists(path.dirname(path.realpath(__file__))+"/stories/"+name+".json")
|
||||||
|
Reference in New Issue
Block a user