Skip to content

Commit

Permalink
Bump PGCG.commonItems from 14.1.4 to 15.0.0 in /ImperatorToCK3 (#2284)
Browse files Browse the repository at this point in the history
Bumps
[PGCG.commonItems](https://github.com/ParadoxGameConverters/commonItems.NET)
from 14.1.4 to 15.0.0.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/ParadoxGameConverters/PGCG.commonItems/commit/6c8af20d9684317f0c0dfbc572f446d9124d5def"><code>6c8af20</code></a>
Use defines when loading script values (<a
href="https://redirect.github.com/ParadoxGameConverters/commonItems.NET/issues/531">#531</a>)</li>
<li>See full diff in <a
href="https://github.com/ParadoxGameConverters/commonItems.NET/compare/14.1.4...15.0.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=PGCG.commonItems&package-manager=nuget&previous-version=14.1.4&new-version=15.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: iht <[email protected]>
  • Loading branch information
dependabot[bot] and IhateTrains authored Oct 20, 2024
1 parent b72e3d5 commit 5071582
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void UnitsCanBeLoaded() {
var unitCollection = new UnitCollection();

var reader = new BufferedReader(@"1={} 2={} 3=none 1040187400={}");
unitCollection.LoadUnits(reader, new LocDB("english"), new Defines());
unitCollection.LoadUnits(reader, new LocDB("english"), new ImperatorDefines());

unitCollection
.Select(unit => unit.Id)
Expand Down
9 changes: 4 additions & 5 deletions ImperatorToCK3.UnitTests/Imperator/Armies/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,26 @@ public void LocalizedNameIsCorrectlyGenerated() {
}
}
}");
var unit = new Unit(1, unitReader, units, locDB, new Defines());
var unit = new Unit(1, unitReader, units, locDB, new ImperatorDefines());

Assert.NotNull(unit.LocalizedName);
Assert.Equal("Cohors V Legio Italia", unit.LocalizedName["english"]);
}

[Fact]
public void UnitStrengthIsCorrectlyCalculated() {
var defines = new Defines();
Assert.Equal(500, defines.CohortSize);

var subunitsReader = new BufferedReader(@"
1 = { strength = 0.5 type=""archers"" } # 250 men
2 = { strength = 1 type=""archers"" } # 500 men
");

var unitCollection = new UnitCollection();
unitCollection.LoadSubunits(subunitsReader);

// Default cohort size is 500.

var unitReader = new BufferedReader("cohort=1 cohort=2");
var unit = new Unit(1, unitReader, unitCollection, new LocDB("english"), defines);
var unit = new Unit(1, unitReader, unitCollection, new LocDB("english"), new ImperatorDefines());

Assert.Equal(750, unit.MenPerUnitType["archers"]); // 250 + 500
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace ImperatorToCK3.UnitTests.Imperator;

public class DefinesTests {
public class ImperatorDefinesTests {
private const string ImperatorRoot = "TestFiles/Imperator/game";
private readonly ModFilesystem imperatorModFS = new(ImperatorRoot, System.Array.Empty<Mod>());

[Fact]
public void CohortSizeCanBeRead() {
var defines = new Defines();
var defines = new ImperatorDefines();
defines.LoadDefines(imperatorModFS);
Assert.Equal(601, defines.CohortSize);
}
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3.UnitTests/Imperator/Religions/DeityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void ConstructedDeityHasCorrectId() {
[Fact]
public void ModifiersAreRead() {
var scriptValues = new ScriptValueCollection();
scriptValues.LoadScriptValues(imperatorModFS);
scriptValues.LoadScriptValues(imperatorModFS, new Defines());

var deityReader = new BufferedReader(@"
passive_modifier = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ReligionCollectionTests {
[Fact]
public void ReligionsAreLoadedFromGameAndMods() {
var scriptValues = new ScriptValueCollection();
scriptValues.LoadScriptValues(imperatorModFS);
scriptValues.LoadScriptValues(imperatorModFS, new Defines());

var religions = new ReligionCollection(scriptValues);
religions.LoadReligions(imperatorModFS);
Expand Down Expand Up @@ -47,7 +47,7 @@ public void ReligionsAreLoadedFromGameAndMods() {
[Fact]
public void DeitiesAreLoadedFromGameAndMods() {
var scriptValues = new ScriptValueCollection();
scriptValues.LoadScriptValues(imperatorModFS);
scriptValues.LoadScriptValues(imperatorModFS, new Defines());

var religions = new ReligionCollection(scriptValues);
religions.LoadDeities(imperatorModFS);
Expand All @@ -70,7 +70,7 @@ public void DeitiesAreLoadedFromGameAndMods() {
[Fact]
public void GetDeityForHolySiteIdReturnsCorrectDeityOrNullWhenIdIsNotFoundOrWhenDeityIsNotFound() {
var scriptValues = new ScriptValueCollection();
scriptValues.LoadScriptValues(imperatorModFS);
scriptValues.LoadScriptValues(imperatorModFS, new Defines());

var religions = new ReligionCollection(scriptValues);
religions.LoadDeities(imperatorModFS);
Expand Down
5 changes: 4 additions & 1 deletion ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
// Include a fake mod pointing to blankMod in the output folder.
LoadedMods.Add(new Mod("blankMod", outputModPath));
ModFS = new ModFilesystem(Path.Combine(config.CK3Path, "game"), LoadedMods);

var ck3Defines = new Defines();
ck3Defines.LoadDefines(ModFS);

ColorFactory ck3ColorFactory = new();
// Now that we have the mod filesystem, we can initialize the localization database.
Expand All @@ -120,7 +123,7 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
LocDB.LoadLocFromModFS(ModFS, config.GetActiveCK3ModFlags());
Logger.IncrementProgress();
},
() => ScriptValues.LoadScriptValues(ModFS),
() => ScriptValues.LoadScriptValues(ModFS, ck3Defines),
() => {
NamedColors.LoadNamedColors("common/named_colors", ModFS);
ck3ColorFactory.AddNamedColorDict(NamedColors);
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/Imperator/Armies/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class Unit : IIdentifiable<ulong> {
public LocBlock? LocalizedName { get; private set; }
public IDictionary<string, int> MenPerUnitType { get; }

public Unit(ulong id, BufferedReader legionReader, UnitCollection unitCollection, LocDB irLocDB, Defines defines) {
public Unit(ulong id, BufferedReader legionReader, UnitCollection unitCollection, LocDB irLocDB, ImperatorDefines defines) {
Id = id;

var parser = new Parser();
Expand Down Expand Up @@ -83,7 +83,7 @@ public Unit(ulong id, BufferedReader legionReader, UnitCollection unitCollection
return nameLocBlock;
}

private Dictionary<string, int> GetMenPerUnitType(UnitCollection unitCollection, Defines defines) {
private Dictionary<string, int> GetMenPerUnitType(UnitCollection unitCollection, ImperatorDefines defines) {
var cohortSize = defines.CohortSize;

return unitCollection.Subunits.Where(s => CohortIds.Contains(s.Id))
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Armies/UnitCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void LoadSubunits(BufferedReader subunitsReader) {
}
Logger.IncrementProgress();
}
public void LoadUnits(BufferedReader unitsReader, LocDB irLocDB, Defines defines) {
public void LoadUnits(BufferedReader unitsReader, LocDB irLocDB, ImperatorDefines defines) {
Logger.Info("Loading units...");

var parser = new Parser();
Expand Down
29 changes: 8 additions & 21 deletions ImperatorToCK3/Imperator/Defines.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
using commonItems;
using commonItems.Mods;
using ImperatorToCK3.Helpers;
using System;
using System.Text.Json;

namespace ImperatorToCK3.Imperator;

public sealed class Defines {
public sealed class ImperatorDefines : Defines {
public int CohortSize { get; private set; } = 500;

public void LoadDefines(ModFilesystem imperatorModFs) {
public new void LoadDefines(ModFilesystem modFS) {
Logger.Info("Loading Imperator defines...");

var definesFiles = imperatorModFs.GetAllFilesInFolderRecursive("common/defines");
foreach (var fileInfo in definesFiles) {
string jsonString = string.Empty;
try {
jsonString = RakalyCaller.GetJson(fileInfo.AbsolutePath);
var jsonRoot = JsonDocument.Parse(jsonString).RootElement;

if (jsonRoot.TryGetProperty("NUnit", out var unitProp) && unitProp.TryGetProperty("COHORT_SIZE", out var cohortSizeProp)) {
CohortSize = cohortSizeProp.GetInt32();
}
} catch (Exception e) {
Logger.Warn($"Failed to read defines from {fileInfo.AbsolutePath}:\n\tJSON string: {jsonString}\n\texception: {e}");
}
base.LoadDefines(modFS);

var cohortSizeStr = GetValue("NUnit", "COHORT_SIZE");
if (cohortSizeStr is not null) {
CohortSize = int.Parse(cohortSizeStr);
}

Logger.IncrementProgress();
}
}
6 changes: 3 additions & 3 deletions ImperatorToCK3/Imperator/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public partial class World {
private readonly SortedSet<string> dlcs = [];
public IReadOnlySet<string> GlobalFlags { get; private set; } = ImmutableHashSet<string>.Empty;
private readonly ScriptValueCollection scriptValues = new();
public Defines Defines { get; } = new();
public ImperatorDefines Defines { get; } = new();
public LocDB LocDB { get; } = new(ConverterGlobals.PrimaryLanguage, ConverterGlobals.SecondaryLanguages);

public NamedColorCollection NamedColors { get; } = [];
Expand Down Expand Up @@ -629,12 +629,12 @@ private void LoadModFilesystemDependentData() {
Areas.LoadAreas(ModFS, Provinces);
ImperatorRegionMapper = new ImperatorRegionMapper(Areas, MapData);
},
() => Defines.LoadDefines(ModFS),
() => InventionsDB.LoadInventions(ModFS),
() => Country.LoadGovernments(ModFS),
ParseGenes,
() => {
scriptValues.LoadScriptValues(ModFS);
Defines.LoadDefines(ModFS);
scriptValues.LoadScriptValues(ModFS, Defines);
Logger.IncrementProgress();
},
() => {
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/ImperatorToCK3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PGCG.commonItems" Version="14.1.4" />
<PackageReference Include="PGCG.commonItems" Version="15.0.0" />
<PackageReference Include="PGCG.commonItems.SourceGenerators" Version="1.0.7"/>
<PackageReference Include="Polly" Version="8.4.2" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.8">
Expand Down

0 comments on commit 5071582

Please sign in to comment.