basic stub of encounter human
This commit is contained in:
		@@ -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]
 | 
			
		||||
    #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")
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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)) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user