diff --git a/Dockerfile b/Dockerfile index 7e5da56..fab4764 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,8 @@ RUN apk del rustup gcc musl-dev FROM base AS app RUN mkdir -p /lib/wordlist COPY ext/imsky/wordlists /lib/wordlist -#RUN python /lib/wordlist/render.py -o rant /app/rant/wordlist.rant +RUN mkdir -p /app/rant +RUN python /lib/wordlist/render.py -o rant /app/rant/wordlist.rant # installing app COPY app /app diff --git a/app/pylocal/core.py b/app/pylocal/core.py index 0425675..2646049 100644 --- a/app/pylocal/core.py +++ b/app/pylocal/core.py @@ -1,8 +1,22 @@ - +import os +import sys import flask app = flask.Flask("seagull-game", root_path="/app") +orig_url_for = app.url_for + +def url_for_override(endpoint, *posargs, _anchor=None, _method=None, _scheme=None, _external=None, self=app, **values): + if endpoint == "static": + # bandaid for #1 + if not os.path.exists("/app/static/" + values["filename"]): + sys.stderr.write("WARN:: requested {0} from local file, but it doesn't exist in this container. Redirecting to CDN...\n".format(values["filename"])) + sys.stderr.flush() + return "https://cdn.otl-hga.net/seagull/" + values["filename"] + + return orig_url_for(endpoint, *posargs, _anchor=_anchor, _method=_method, _scheme=_scheme, _external=_external, **values) + +app.url_for = url_for_override base_context = {} base_context_live = False @@ -23,9 +37,9 @@ def render_base_context(): 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"] = [flask.url_for("static", filename="css/seagull.css")] - base_context["scripts"] = [flask.url_for("static", filename="js/seagull.js")] - base_context["seagull_pic"] = flask.url_for("static", filename="image/seagull.jpg") + base_context["styles"] = [app.url_for("static", filename="css/seagull.css")] + base_context["scripts"] = [app.url_for("static", filename="js/seagull.js")] + base_context["seagull_pic"] = app.url_for("static", filename="image/seagull.jpg") base_context_live = True diff --git a/app/pylocal/tick.py b/app/pylocal/tick.py index 7d7335c..08eaf86 100644 --- a/app/pylocal/tick.py +++ b/app/pylocal/tick.py @@ -1,8 +1,13 @@ import json import random +import subprocess from . import core +def generate_flavor_text(): + proc_rant = subprocess.run(["rant", "/app/rant/flavor.rant"], capture_output=True) + return proc_rant.stdout.decode() + @core.app.route("/tick") def tick(): - return random.choices([json.dumps({"code": 200, "event_type": 0}), json.dumps({"code": 200, "event_type": 1, "log": "The server chose a flavor text event, which hasn't been fully implemented yet."})], weights=[16, 1])[0] \ No newline at end of file + return random.choices([json.dumps({"code": 200, "event_type": 0}), json.dumps({"code": 200, "event_type": 1, "log": generate_flavor_text()})], weights=[16, 1])[0] \ No newline at end of file diff --git a/app/rant/flavor.rant b/app/rant/flavor.rant new file mode 100644 index 0000000..2b12ad4 --- /dev/null +++ b/app/rant/flavor.rant @@ -0,0 +1,26 @@ +@require "wordlist" + +{ + You meet { + a `[pick: ] | + `{ + [pick: ] | + [pick: ] | + [pick: ] | + [pick: ] | + [pick: ] | + [pick: ] | + [pick: ] | + [pick: ] + } the `[pick: ] + }. { + It completely ignores you. | + You have a polite conversation about birdly affairs. | + It scoffs and flies away. + } + | + You encounter a human and attempt to steal their `{ + [pick: ] | + [pick: ] + }. +} \ No newline at end of file diff --git a/app/rant/wordlist.rant b/app/rant/wordlist.rant new file mode 100644 index 0000000..5121373 --- /dev/null +++ b/app/rant/wordlist.rant @@ -0,0 +1,172 @@ +<%module = (::)> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/templates/main_page.j2 b/app/templates/main_page.j2 index 3e8ca88..64e571d 100644 --- a/app/templates/main_page.j2 +++ b/app/templates/main_page.j2 @@ -24,7 +24,7 @@

Lv 1 LoadError

- Colony: 1337
+ Colony: 1337
Shinies: 420

diff --git a/static/js/seagull.js b/static/js/seagull.js index cc828b2..c602d7a 100644 --- a/static/js/seagull.js +++ b/static/js/seagull.js @@ -3,10 +3,14 @@ const sleep = ms => new Promise(r => setTimeout(r, ms)); // sleep(int ms) var page_elements = {}; var gamestate = {}; +var ticks_since_last_save = 0; const gamestate_default = { + "statever": "1", "tick": 1, - "name": "Nameless" + "name": "Nameless", + "level": 1, + "autosave": 35 }; function prepare_gamestate() { @@ -42,6 +46,9 @@ var tick_meter_running = true; async function game_tick() { gamestate["tick"] += 1; + ticks_since_last_save += 1; + // temp + page_elements["lbl_colony"].innerHTML = ticks_since_last_save; page_elements["lbl_tick"].innerHTML = gamestate["tick"]; var tickdata = await fetch("/tick") .then(res => { @@ -66,6 +73,15 @@ async function game_tick() { //await sleep(12000); //game_tick(); } + + // sanity check + if (!("autosave" in gamestate)) { + gamestate["autosave"] = 35; + } + if (ticks_since_last_save % gamestate["autosave"] == 0 && ticks_since_last_save != 0) { + save_game(); + ticks_since_last_save = 0; + } } document.addEventListener("DOMContentLoaded", function (ev) { @@ -73,6 +89,7 @@ document.addEventListener("DOMContentLoaded", function (ev) { page_elements["div_name"] = document.querySelector("#side-seagull-name"); page_elements["div_name_editor"] = document.querySelector("#side-seagull-name-editor"); page_elements["lbl_name"] = document.querySelector("#lbl-seagull-name"); + page_elements["lbl_colony"] = document.querySelector("#lbl-seagull-colony"); page_elements["edt_name"] = document.querySelector("#edt-seagull-name"); page_elements["lbl_tick"] = document.querySelector("#main-day-counter");