Skip to content

Commit

Permalink
Log Bugfixes & SETI QoL (nuclear-unicorn#79)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Brent-Call authored Sep 2, 2024
1 parent 8d78a55 commit 2af4a2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
11 changes: 10 additions & 1 deletion core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
20 changes: 13 additions & 7 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions js/workshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 2af4a2d

Please sign in to comment.