Skip to content

Commit

Permalink
feat(ui): Filter all KG log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Dec 22, 2023
1 parent 458d0f3 commit bd33d7e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/documentation/docs/sections/log-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

You can control which events will be logged to the game log. Disable any option if the log message in that category get too excessive.

## All KG log entries

This will just uncheck all the log filters in KG itself, so that logging behavior remains consistent throughout resets.

## Adoring

- The galaxy has been adored on the [Religion](./religion.md) tab.
Expand Down
18 changes: 18 additions & 0 deletions packages/kitten-scientists/source/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ export class Engine {
private async _iterate(): Promise<void> {
const context = { tick: new Date().getTime() };

if (this.settings.filters.disableKGLog.enabled) {
this._maintainKGLogFilters();
}

// The order in which these actions are performed is probably
// semi-intentional and should be preserved or improved.
await this.scienceManager.tick(context);
Expand All @@ -315,6 +319,20 @@ export class Engine {
await this.timeControlManager.tick(context);
}

/**
* Ensures all log filters in KG are unchecked. This means the events will not be logged.
*/
private _maintainKGLogFilters(): void {
for (const filter of Object.values(this._host.game.console.filters)) {
filter.enabled = false;
}

const filterCheckboxes = window.document.querySelectorAll("[id^=filter-]");
for (const checkbox of filterCheckboxes) {
(checkbox as HTMLInputElement).checked = false;
}
}

/**
* Retrieve an internationalized string literal.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type LogFilterSettingsItems = {

export class LogFilterSettings extends Setting {
filters: LogFilterSettingsItems;
disableKGLog: Setting;

constructor(
enabled = false,
Expand All @@ -98,9 +99,11 @@ export class LogFilterSettings extends Setting {
promote: new LogFilterSettingsItem(LogFilterItemVariant.Promote),
misc: new LogFilterSettingsItem(LogFilterItemVariant.Misc),
},
disableKGLog = new Setting(false),
) {
super(enabled);
this.filters = filters;
this.disableKGLog = disableKGLog;
}

load(settings: Maybe<Partial<LogFilterSettings>>) {
Expand All @@ -113,5 +116,6 @@ export class LogFilterSettings extends Setting {
consumeEntriesPedantic(this.filters, settings.filters, (filter, item) => {
filter.enabled = item?.enabled ?? filter.enabled;
});
this.disableKGLog.enabled = settings.disableKGLog?.enabled ?? this.disableKGLog.enabled;
}
}
1 change: 1 addition & 0 deletions packages/kitten-scientists/source/types/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type Game = {
};
compressLZData: (data: string) => string;
console: {
filters: Record<string, { enabled: boolean; title: string; unlocked: boolean }>;
maxMessages: number;
};
craft: (name: string, amount: number) => void;
Expand Down
8 changes: 8 additions & 0 deletions packages/kitten-scientists/source/ui/LogFilterSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export class LogFiltersSettingsUi extends SettingsSectionUi<LogFilterSettings> {
const label = host.engine.i18n("ui.filter");
super(host, label, settings);

this.addChild(
new SettingsList(host, {
children: [new SettingListItem(host, "All KG log entries.", settings.disableKGLog)],
hasDisableAll: false,
hasEnableAll: false,
}),
);

const buttonTemplates = [
{
name: "buildFilter" as const,
Expand Down
13 changes: 12 additions & 1 deletion schemas/working-draft/baseline/engine-state.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,20 @@
"misc"
],
"type": "object"
},
"disableKGLog": {
"additionalProperties": false,
"description": "Filter all of KG's own messages.",
"properties": {
"enabled": {
"description": "Should all of KG's internal messages be filtered from the log?",
"type": "boolean"
}
},
"required": ["enabled"]
}
},
"required": ["enabled", "filters"],
"required": ["enabled", "filters", "disableKGLog"],
"type": "object"
},
"resources": {
Expand Down
11 changes: 11 additions & 0 deletions schemas/working-draft/settings-profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@
},
"minProperties": 1,
"type": "object"
},
"disableKGLog": {
"additionalProperties": false,
"description": "Filter all of KG's own messages.",
"properties": {
"enabled": {
"description": "Should all of KG's internal messages be filtered from the log?",
"type": "boolean"
}
},
"required": ["enabled"]
}
},
"minProperties": 1,
Expand Down

0 comments on commit bd33d7e

Please sign in to comment.