Skip to content

Commit

Permalink
Don't log same unresolved script values multiple times (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Oct 15, 2024
1 parent 5f9ab59 commit 2848171
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions commonItems/ScriptValueCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using commonItems.Mods;
using commonItems.Collections;
using commonItems.Mods;
using Microsoft.VisualBasic;
using System;
using System.Collections;
Expand All @@ -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<string> 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;
Expand All @@ -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<string> unresolvedScriptValues) {
var valueStringOfItem = reader.GetStringOfItem();
if (valueStringOfItem.IsArrayOrObject()) {
return null;
Expand All @@ -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;
}

Expand Down Expand Up @@ -100,7 +112,6 @@ IEnumerator IEnumerable.GetEnumerator() {
// ignored
}

Logger.Warn($"No script value found for \"{valueStr}\"!");
return null;
}
}
2 changes: 1 addition & 1 deletion commonItems/commonItems.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<PackageId>PGCG.$(AssemblyName)</PackageId>
<Version>14.1.2</Version>
<Version>14.1.3</Version>
<Authors>PGCG</Authors>
<PackageProjectUrl>https://github.com/ParadoxGameConverters/commonItems.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/ParadoxGameConverters/commonItems.NET</RepositoryUrl>
Expand Down

0 comments on commit 2848171

Please sign in to comment.