From 0c9bff9fc390501e6604cb64d3a30e3b23f10bda Mon Sep 17 00:00:00 2001 From: Nicole O'Connor Date: Mon, 27 Feb 2023 20:22:36 -0800 Subject: [PATCH] basic stub of encounter human --- app/pylocal/tick.py | 35 ++++++++++++++++++++++++++++++++++- static/css/seagull.css | 21 +++++++++++++++++++++ static/js/seagull.js | 15 +++++++++------ 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/app/pylocal/tick.py b/app/pylocal/tick.py index 08eaf86..41a032f 100644 --- a/app/pylocal/tick.py +++ b/app/pylocal/tick.py @@ -2,12 +2,45 @@ import json import random import subprocess +import flask + from . import core def generate_flavor_text(): proc_rant = subprocess.run(["rant", "/app/rant/flavor.rant"], capture_output=True) return proc_rant.stdout.decode() +class TickEvent(object): + def __init__(self, tickno, tickweight, tickcode): + self.tickno = tickno + self.tickweight = tickweight + self.tickcode = tickcode + +tick_event_list = [] +tick_event_list.append(TickEvent(0, 16, "XYZZY")) # nothing happens +tick_event_list.append(TickEvent(1, 1, "FLAVOR")) # procedurally generated event of no consequence +tick_event_list.append(TickEvent(10, 2, "ENCHUMAN")) # encounter: human + @core.app.route("/tick") def tick(): - 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 + #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] + ticktypes = [] + tickweights = [] + + for event in tick_event_list: + ticktypes.append(event.tickno) # unce unce unce + tickweights.append(event.tickweight) + + result = {} + result["code"] = 200 + result["event_type"] = random.choices(ticktypes, weights=tickweights)[0] + + match result["event_type"]: + case 1: # FLAVOR + result["log"] = generate_flavor_text() + case 10: # ENCHUMAN + result["items"] = [] # TODO: implement items + case _: + print("undefined tick: {0}".format(result["event_type"])) + + return flask.Response(json.dumps(result), status=200, content_type="application/json") \ No newline at end of file diff --git a/static/css/seagull.css b/static/css/seagull.css index 0ef2476..155618e 100644 --- a/static/css/seagull.css +++ b/static/css/seagull.css @@ -32,6 +32,12 @@ div#main-content { padding-left: 5px; } +div#main-day-stats { + min-height: 100px; + vertical-align: middle; + + border-bottom: 0.125em solid rgb(192,192,192); +} div#main-log { display: flex; @@ -41,6 +47,21 @@ div#main-log { div.log-line { display: flex; flex-direction: row; + vertical-align: top; + width: 100%; + min-height: 1.5em; + padding-top: 5px; +} + +div.log-line-alt { + display: flex; + flex-direction: row; + vertical-align: top; + width: 100%; + min-height: 1.5em; + padding-top: 5px; + + background-color: rgb(192, 192, 192); } div.log-tick { diff --git a/static/js/seagull.js b/static/js/seagull.js index 08af011..7108efd 100644 --- a/static/js/seagull.js +++ b/static/js/seagull.js @@ -29,9 +29,12 @@ function prepare_gamestate() { } } +var bool_log_alt = false function record_log(text) { const div_logrow = document.createElement("div"); - div_logrow.className = "log-line"; + if (bool_log_alt) { div_logrow.className = "log-line"; } + else { div_logrow.className = "log-line-alt"; } + bool_log_alt = !bool_log_alt; const div_logtick = document.createElement("div"); div_logtick.className = "log-tick" @@ -74,14 +77,14 @@ async function game_tick() { } if (tickdata["event_type"] == 0) { - //sleep(12000); - //game_tick(); + // pass } else if (tickdata["event_type"] == 1) { // Flavor event - no gameplay effect, but occasionally says something fun. record_log(tickdata["log"]); - //await sleep(12000); - //game_tick(); - } + } else if (tickdata["event_type"] == 10) { + // Human encounter. This is a stub. + record_log("You have encountered a human."); + } // sanity check if (!("autosave" in gamestate)) {