From 2848171721646292f2bbbb820a141416edee14c4 Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Tue, 15 Oct 2024 18:33:29 +0100 Subject: [PATCH] Don't log same unresolved script values multiple times (#525) --- commonItems/ScriptValueCollection.cs | 19 +++++++++++++++---- commonItems/commonItems.csproj | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/commonItems/ScriptValueCollection.cs b/commonItems/ScriptValueCollection.cs index b6fb0416..c1c29a0a 100644 --- a/commonItems/ScriptValueCollection.cs +++ b/commonItems/ScriptValueCollection.cs @@ -1,4 +1,5 @@ -using commonItems.Mods; +using commonItems.Collections; +using commonItems.Mods; using Microsoft.VisualBasic; using System; using System.Collections; @@ -21,13 +22,14 @@ public void LoadScriptValues(ModFilesystem modFilesystem) { // scheme_agent_general_bonuses_contribution_score_bonus_max_value = agent_max_skill_value // agent_max_skill_value = 10 // To handle this, we read the script values multiple times until no new values are added. + OrderedSet unresolvedScriptValues = []; int addedValuesCount; do { addedValuesCount = 0; var parser = new Parser(); parser.RegisterRegex(CommonRegexes.String, (reader, name) => { - var value = ParseValue(reader); + var value = ParseValue(reader, unresolvedScriptValues); if (value is not null) { if (!dict.ContainsKey(name)) { ++addedValuesCount; @@ -38,9 +40,14 @@ public void LoadScriptValues(ModFilesystem modFilesystem) { parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreAndLogItem); parser.ParseGameFolder("common/script_values", modFilesystem, "txt", recursive: true); } while (addedValuesCount > 0); + + if (unresolvedScriptValues.Count > 0) { + // Log unresolvable values (excluding complex ones). + Logger.Warn($"The following script values were not loaded: {unresolvedScriptValues}"); + } } - private double? ParseValue(BufferedReader reader) { + private double? ParseValue(BufferedReader reader, OrderedSet unresolvedScriptValues) { var valueStringOfItem = reader.GetStringOfItem(); if (valueStringOfItem.IsArrayOrObject()) { return null; @@ -62,6 +69,11 @@ public void LoadScriptValues(ModFilesystem modFilesystem) { } var value = GetValueForString(valueStr); + if (value is null) { + unresolvedScriptValues.Add(valueStr); + } else { + unresolvedScriptValues.Remove(valueStr); + } return value; } @@ -100,7 +112,6 @@ IEnumerator IEnumerable.GetEnumerator() { // ignored } - Logger.Warn($"No script value found for \"{valueStr}\"!"); return null; } } \ No newline at end of file diff --git a/commonItems/commonItems.csproj b/commonItems/commonItems.csproj index 75addb4a..b5f6712d 100644 --- a/commonItems/commonItems.csproj +++ b/commonItems/commonItems.csproj @@ -6,7 +6,7 @@ False PGCG.$(AssemblyName) - 14.1.2 + 14.1.3 PGCG https://github.com/ParadoxGameConverters/commonItems.NET https://github.com/ParadoxGameConverters/commonItems.NET