From 4151fd1b6abf57c0ca7cca8bee9be415b0bdbb3a Mon Sep 17 00:00:00 2001 From: henk717 Date: Wed, 1 Sep 2021 17:41:18 +0200 Subject: [PATCH] Save story in plain text along the save Not just saving in .json but also in plain text, should help story writers get their stories out more easily. Especially since they can technically add some markdown into their stories manually in the interface. --- aiserver.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index 3e908331..248f049d 100644 --- a/aiserver.py +++ b/aiserver.py @@ -5,6 +5,7 @@ #==================================================================# # External packages +import os from os import path, getcwd import re import tkinter as tk @@ -1884,7 +1885,7 @@ def saveRequest(savpath): # Save path for future saves vars.savedir = savpath - + txtpath = os.path.splitext(savpath)[0] + ".txt" # Build json to write js = {} js["gamestarted"] = vars.gamestarted @@ -1893,7 +1894,7 @@ def saveRequest(savpath): js["authorsnote"] = vars.authornote js["actions"] = tuple(vars.actions.values()) js["worldinfo"] = [] - + # Extract only the important bits of WI for wi in vars.worldinfo: if(wi["constant"] or wi["key"] != ""): @@ -1904,14 +1905,35 @@ def saveRequest(savpath): "selective": wi["selective"], "constant": wi["constant"] }) - + + ln = len(vars.actions) + + if(ln > 0): + chunks = collections.deque() + i = 0 + for key in reversed(vars.actions): + chunk = vars.actions[key] + chunks.appendleft(chunk) + i += 1 + + if(ln > 0): + txt = vars.prompt + "".join(chunks) + elif(ln == 0): + txt = vars.prompt + # Write it file = open(savpath, "w") try: file.write(json.dumps(js, indent=3)) finally: file.close() - + + file = open(txtpath, "w") + try: + file.write(txt) + finally: + file.close() + print("{0}Story saved to {1}!{2}".format(colors.GREEN, path.basename(savpath), colors.END)) #==================================================================#