giant freakin documentation and reorganization pass, it also uses cmake because all the building was getting too complicated for shell scripts
This commit is contained in:
@@ -4,6 +4,7 @@ import pathlib
|
||||
import sys
|
||||
|
||||
import flask
|
||||
from flask_cors import CORS
|
||||
|
||||
log = logging.getLogger()
|
||||
pipe_stderr = logging.StreamHandler(sys.stderr)
|
||||
@@ -16,11 +17,16 @@ else:
|
||||
path_appdir = pathlib.Path.cwd()
|
||||
log.critical(path_appdir)
|
||||
|
||||
## \internal
|
||||
# \brief Signals whether we are a desktop application (as opposed to a Docker container).
|
||||
desktop_mode = False
|
||||
|
||||
from . import gamedata
|
||||
|
||||
## \internal
|
||||
# \brief The Flask instance. See <a href="https://flask.palletsprojects.com/en/stable/api/">Flask documentation</a>.
|
||||
app = flask.Flask("seagull-game", root_path=path_appdir, template_folder="templates", static_folder="static")
|
||||
CORS(app)
|
||||
orig_url_for = app.url_for
|
||||
|
||||
xml_namespaces = {
|
||||
@@ -34,6 +40,10 @@ xml_namespaces = {
|
||||
#REDIS_PASS="i am not a real password"
|
||||
#state_cache = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, username=REDIS_USER, password=REDIS_PASS)
|
||||
|
||||
# ham5 standing by...
|
||||
|
||||
## \internal
|
||||
# \brief Returns CDN URLs for files not present within the container itself, or copies VFS data out so Flask etc can use it.
|
||||
def url_for_override(endpoint, *posargs, _anchor=None, _method=None, _scheme=None, _external=None, self=app, **values):
|
||||
if endpoint == "static":
|
||||
if not gamedata.vfs.exists(f"static/{values["filename"]}"):
|
||||
@@ -48,17 +58,25 @@ def url_for_override(endpoint, *posargs, _anchor=None, _method=None, _scheme=Non
|
||||
|
||||
app.url_for = url_for_override
|
||||
|
||||
## \internal
|
||||
# \brief Base Flask rendering context. Generated with render_base_context().
|
||||
base_context = {}
|
||||
base_context_live = False
|
||||
|
||||
## \brief Renders a dialog template and sends it to the client.
|
||||
# \param dialog The dialog to render.
|
||||
# \api{GET} /dialog/`<dialog>`
|
||||
@app.route("/dialog/<dialog>")
|
||||
def render_dialog(dialog):
|
||||
if gamedata.vfs.exists(f"templates/{dialog}.j2"):
|
||||
gamedata.vfs.copy_out(f"templates/{dialog}.j2", dest=path_appdir.as_posix())
|
||||
if gamedata.vfs.exists(f"static/js/dlg-{dialog}.js"):
|
||||
gamedata.vfs.copy_out(f"static/js/dlg-{dialog}.js", dest=path_appdir.as_posix())
|
||||
return flask.render_template(f"{dialog}.j2")
|
||||
else:
|
||||
return "", 404
|
||||
|
||||
## \brief Prepares the base rendering context for Flask to serve our content.
|
||||
def render_base_context():
|
||||
global base_context
|
||||
global base_context_live
|
||||
@@ -68,19 +86,32 @@ def render_base_context():
|
||||
domain_components = flask.request.host.split(".")
|
||||
base_domain = ".".join(domain_components[-2:])
|
||||
|
||||
gamedata.vfs.copy_out("static/js/mermaid.esm.min.mjs", dest=path_appdir.as_posix())
|
||||
|
||||
# all this wind up for...
|
||||
if base_domain == "otl-hga.net": # production, use assets from S3
|
||||
base_context["styles"] = ["https://cdn.otl-hga.net/seagull/css/seagull.css"]
|
||||
base_context["scripts"] = ["https://cdn.otl-hga.net/seagull/js/seagull.js"]
|
||||
base_context["scripts"] = ["https://cdn.otl-hga.net/seagull/js/seagull.js", "https://cdn.otl-hga.net/seagull/js/konami.js"]
|
||||
base_context["seagull_pic"] = "https://cdn.otl-hga.net/seagull/image/seagull.jpg"
|
||||
else: # dev, serve files from here
|
||||
#print(base_domain)
|
||||
base_context["styles"] = [app.url_for("static", filename="css/seagull.css")]
|
||||
base_context["scripts"] = [app.url_for("static", filename="js/seagull.js")]
|
||||
base_context["scripts"] = [(app.url_for("static", filename="js/konami.js"), True), (app.url_for("static", filename="js/seagull.js"), True)]
|
||||
base_context["seagull_pic"] = app.url_for("static", filename="image/seagull.jpg")
|
||||
|
||||
base_context_live = True
|
||||
|
||||
## \brief Returns OK. Useful for health checks.
|
||||
# \api{GET} /core/ping
|
||||
@app.route("/core/ping")
|
||||
def healthcheck_ping():
|
||||
return flask.Response("OK", content_type="text/plain")
|
||||
|
||||
## \brief Informs the game we're about to request a file from JavaScript.
|
||||
# \internal
|
||||
# \api{POST} /core/ready_file
|
||||
# \apidata Plaintext path to the intended file.
|
||||
@app.route("/core/ready_file", methods=["POST"])
|
||||
def ready_file():
|
||||
gamedata.vfs.copy_out(flask.request.data)
|
||||
return flask.Response("OK", content_type="text/plain")
|
Reference in New Issue
Block a user