working demo

This commit is contained in:
LockeShor
2026-09-19 19:36:30 -04:00
parent 3fcf542a7a
commit 5ffdc0bbb2
5 changed files with 304 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import json
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route("/")
def game():
gamecode = request.args.get('code')[:-1]
#return open("page copy.html", "r").read()
#print(buildHTML(gamecode))
return buildHTML(gamecode)
def buildHTML(gamecode):
with open("story.json", "r") as f:
print("\n\n")
story = json.loads(f.read())
nodeName = "start"
for action in gamecode:
nodeName = story[nodeName]["choices"][int(action) - 1]["next"]
print(action, nodeName)
info = story[nodeName]
currText = info["text"]
choices = ""
for i in range(len(info["choices"])):
choice = info["choices"][i]
choices += f"{(i + 1) * 10}: " + choice["text"] + "\\n"
print(str(request.user_agent) + "\n",currText,choices)
with open('page.html', "r") as page:
return page.read().replace("{{CurrText}}", currText.replace('"', '\\"')).replace("{{Choices}}", choices.replace('"', '\\"'))
if __name__ == '__main__':
app.run(debug=True, port=1387)