Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't log same unresolved script values multiple times #525

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading