state sync

This commit is contained in:
2025-11-23 14:59:17 -08:00
parent 537bdf1ad7
commit 39f4a8d3fc
812 changed files with 373062 additions and 84 deletions

View File

@@ -29,6 +29,7 @@ globalThis.gamestate_default = {
"agility": 0,
"instinct": 0,
"leadership": 0,
"unspent-attr": 0,
"income": {
"last_food": Array(10).fill(0),
"last_shinies": Array(10).fill(0),
@@ -37,7 +38,8 @@ globalThis.gamestate_default = {
},
"modifiers": {
"speed": [],
"chancesteal": []
"chancesteal": [],
"harvestamount": [],
},
"upgrades": []
};
@@ -72,6 +74,16 @@ globalThis.record_log = function (text) {
page_elements["div_log"].append(div_logrow);
}
var choice_row = null;
globalThis.choice_made = function () {
if (choice_row == null) { return; }
tick_meter_running = true;
choice_row.remove();
choice_row = null;
}
function record_log_with_choices() {
const div_logrow = document.createElement("div");
if (bool_log_alt) { div_logrow.className = "log-line"; }
@@ -92,6 +104,7 @@ function record_log_with_choices() {
const div_logactions = document.createElement("div");
div_logactions.className = "log-button-row";
choice_row = div_logactions;
for (var i = 1; i < arguments.length; i += 2) {
console.log(i)
@@ -101,7 +114,7 @@ function record_log_with_choices() {
var btn_action = document.createElement("button");
btn_action.innerHTML = label;
btn_action.className = "log-action-button";
btn_action.setAttribute("onclick", callback + "; tick_meter_running = true;");
btn_action.setAttribute("onclick", callback + "; choice_made();");
div_logactions.append(btn_action);
}
div_logdata.append(div_logactions);
@@ -113,6 +126,7 @@ function record_log_with_choices() {
globalThis.modal_dialog_open = false;
globalThis.modal_dialog_scripted = false;
globalThis.modal_was_ticking = false;
globalThis.modal_dialog_name = "";
var dialog_queue = [];
@@ -120,6 +134,7 @@ function modal_no_prop(event) { event.stopPropagation(); }
async function open_modal_dialog(dialog) {
if (!modal_dialog_open) {
modal_was_ticking = tick_meter_running;
tick_meter_running = false;
modal_dialog_open = true;
modal_dialog_name = dialog;
@@ -153,12 +168,22 @@ async function open_modal_dialog(dialog) {
document.head.appendChild(script);
modal_dialog_scripted = true;
}
if (urlExists(`/static/js/dlg-${dialog}.mjs`)) {
var script = document.createElement("script");
script.setAttribute("id", "dialog-script");
script.setAttribute("type", "module");
script.src = `/static/js/dlg-${dialog}.mjs`;
document.head.appendChild(script);
modal_dialog_scripted = true;
}
} else {
var dialog_data = await fetch(`/dialog/${dialog}`)
.then(res => { return res.text(); });
var dialog_script = null;
if (urlExists(`/static/js/dlg-${dialog}.js`)) {
dialog_script = `/static/js/dlg-${dialog}.js`;
} else if (urlExists(`/static/js/dlg-${dialog}.mjs`)) {
dialog_script = `/static/js/dlg-${dialog}.mjs`
}
dialog_queue.push([dialog_data, dialog_script, dialog]);
@@ -180,7 +205,7 @@ async function close_modal_dialog() {
modal_background.style.visibility = "hidden";
document.body.removeChild(modal_background);
tick_meter_running = true;
tick_meter_running = modal_was_ticking;
modal_dialog_open = false;
modal_dialog_name = "";
modal_dialog_scripted = false;
@@ -299,6 +324,18 @@ const hnd_devtoolkit = new Konami(() => {
}
})
globalThis.harvest_fish = function () {
gamestate["food"] += 1;
tickdiffs["food"] += 1;
gamestate["modifiers"]["harvestamount"].forEach((mod) => {
gamestate["food"] += mod[1];
tickdiffs["food"] += mod[1];
});
update_ui();
}
async function game_tick() {
gamestate["tick"] += 1;
ticks_since_last_save += 1;
@@ -387,6 +424,15 @@ async function game_tick() {
break;
case "steal-food":
if (tickdata.items.food.length == 0) {
record_log("You have encountered a human. Attempting to steal shinies.");
tickdata.items.shinies.forEach((item) => {
total_shinies += item["amount"];
shinies_descs.push(item["desc"]);
})
steal_resource("shinies", "humans", total_shinies, shinies_descs.toString());
break;
}
record_log("You have encountered a human. Attempting to steal food.");
tickdata.items.food.forEach((item) => {
total_food += item["amount"];
@@ -395,6 +441,15 @@ async function game_tick() {
steal_resource("food", "humans", total_food, food_descs.toString());
break;
case "steal-shinies":
if (tickdata.items.shinies.length == 0) {
record_log("You have encountered a human. Attempting to steal food.");
tickdata.items.food.forEach((item) => {
total_food += item["amount"];
food_descs.push(item["desc"]);
})
steal_resource("food", "humans", total_food, food_descs.toString());
break;
}
record_log("You have encountered a human. Attempting to steal shinies.");
tickdata.items.shinies.forEach((item) => {
total_shinies += item["amount"];
@@ -528,11 +583,13 @@ target.addEventListener(start_event, function (ev) {
page_elements["btn_charsheet"] = document.querySelector("#button-charsheet");
page_elements["btn_settings"] = document.querySelector("#button-settings");
page_elements["btn_about"] = document.querySelector("#button-about");
page_elements["btn_harvest"] = document.querySelector("#button-harvest-fish");
page_elements["menu_enc_human"].addEventListener("change", (ev) => {update_action("human", ev.target.value)});
page_elements["menu_enc_seagull"].addEventListener("change", (ev) => {update_action("seagull", ev.target.value)});
page_elements["btn_charsheet"].addEventListener("click", (ev) => {open_modal_dialog("charsheet")});
page_elements["btn_about"].addEventListener("click", (ev) => {open_modal_dialog("about")});
page_elements["btn_harvest"].addEventListener("click", (ev) => {harvest_fish()});
prepare_gamestate();