From 2af4a2df7eaab75063d34e0df4f596d55468a1b0 Mon Sep 17 00:00:00 2001 From: Brent Call <90073067+Brent-Call@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:21:07 -0400 Subject: [PATCH] Log Bugfixes & SETI QoL (#79) * Fix bugs related to recursive nature of renderConsoleLog * Upon purchasing SETI, hide the log filter for astro events & auto-complete the ongoing astro event if there is one. --- core.js | 11 ++++++++++- js/ui.js | 20 +++++++++++++------- js/workshop.js | 10 +++++++--- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/core.js b/core.js index 8d96eb752d..47a4faa2be 100644 --- a/core.js +++ b/core.js @@ -488,7 +488,16 @@ dojo.declare("com.nuclearunicorn.game.log.Console", null, { this.ui.renderConsoleLog(); }, - + //Sets a single filter to be not unlocked anymore + lockFilter: function(filterName) { + var filter = this.filters[filterName]; + if (filter) { + filter.unlocked = false; + this.ui.renderFilters(); + } else { + console.error("Error: Invalid filter name passed to lockFilter."); + } + }, resetState: function (){ for (var fId in this.filters){ diff --git a/js/ui.js b/js/ui.js index 88cff29afd..b1d6399df9 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1029,7 +1029,7 @@ dojo.declare("classes.ui.DesktopUI", classes.ui.UISystem, { || messageLatest.seasonTitle !== messagePrevious.seasonTitle; if (!messageLatest.span) { - var span = dojo.create("span", {className: "msg" }, gameLog); + var span = dojo.create("span", {className: "msg", innerHTML: messageLatest.text}, gameLog); if (messageLatest.type) { dojo.addClass(span, "type_" + messageLatest.type); @@ -1041,6 +1041,7 @@ dojo.declare("classes.ui.DesktopUI", classes.ui.UISystem, { } if (insertDateHeader) { + //Calling msg will itself trigger another call to renderConsoleLog if (!messageLatest.year || !messageLatest.seasonTitle) { this.game.console.msg($I("ui.log.link"), "date", null, false); } else { @@ -1050,15 +1051,20 @@ dojo.declare("classes.ui.DesktopUI", classes.ui.UISystem, { if (messageLatest.type === "date") { dojo.place(messageLatest.span, gameLog, "first"); - } else { - dojo.place(messageLatest.span, gameLog, 1); + //Skip the housekeeping logic because the function-call stack contains + // another instance of renderConsoleLog that will take care of it for us. + //At the moment, the last message in the log is the one we wanted to create-- + // it hasn't been dojo.place'd in its proper spot yet. + return; } + //------------ else: non-date, non-header messages ------------ + + //Place current message immediately below the date header. + dojo.place(messageLatest.span, gameLog, 1); - dojo.attr(messageLatest.span, {innerHTML: messageLatest.text}); //Destroy child nodes if there are too many. - var logLength = dojo.byId("gameLog").childNodes.length; - if (logLength > _console.maxMessages) { - dojo.destroy(dojo.byId("gameLog").childNodes[logLength - 1]); + while (gameLog.childNodes.length > _console.maxMessages) { + dojo.destroy(gameLog.lastChild); } //fade message spans as they get closer to being removed and replaced diff --git a/js/workshop.js b/js/workshop.js index 9dbe9a79b8..29a1e7f886 100644 --- a/js/workshop.js +++ b/js/workshop.js @@ -1608,12 +1608,16 @@ dojo.declare("classes.managers.WorkshopManager", com.nuclearunicorn.core.TabMana name: "seti", label: $I("workshop.seti.label"), description: $I("workshop.seti.desc"), - effects: { - }, prices:[ { name : "titanium", val: 250 }, { name : "science", val: 125000 } - ] + ], + handler: function(game) { + game.console.lockFilter("astronomicalEvent"); + if (game.calendar.observeRemainingTime > 0) { + game.calendar.observeHandler(); + } + } },{ name: "logistics", label: $I("workshop.logistics.label"),