-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move converter's cultural pillars to configurables and prevent them f…
…rom overwriting the Fallen Eagle ones (#1680) #minor
- Loading branch information
1 parent
38fc37a
commit 75b52fb
Showing
27 changed files
with
352 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
ImperatorToCK3.UnitTests/CK3/Cultures/PillarCollectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using commonItems.Mods; | ||
using ImperatorToCK3.CK3.Cultures; | ||
using System; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace ImperatorToCK3.UnitTests.CK3.Cultures; | ||
|
||
[Collection("Sequential")] | ||
[CollectionDefinition("Sequential", DisableParallelization = true)] | ||
public class PillarCollectionTests { | ||
[Fact] | ||
public void WarningIsLoggedWhenPillarDataIsMissingType() { | ||
Directory.CreateDirectory("pillars_test"); | ||
Directory.CreateDirectory("pillars_test/common"); | ||
Directory.CreateDirectory("pillars_test/common/culture"); | ||
Directory.CreateDirectory("pillars_test/common/culture/pillars"); | ||
var pillarsFile = File.CreateText("pillars_test/common/culture/pillars/test_pillars.txt"); | ||
pillarsFile.WriteLine("pillar_without_type = {}"); | ||
pillarsFile.Close(); | ||
|
||
var modFS = new ModFilesystem("pillars_test", Array.Empty<Mod>()); | ||
var collection = new PillarCollection(new commonItems.Colors.ColorFactory()); | ||
|
||
var consoleOut = new StringWriter(); | ||
Console.SetOut(consoleOut); | ||
collection.LoadPillars(modFS); | ||
Assert.Contains("[WARN] Pillar pillar_without_type has no type defined! Skipping.", consoleOut.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,48 @@ | ||
using commonItems; | ||
using commonItems.Collections; | ||
using ImperatorToCK3.Exceptions; | ||
using commonItems.Colors; | ||
using commonItems.Serialization; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ImperatorToCK3.CK3.Cultures; | ||
|
||
public class Pillar : IIdentifiable<string> { | ||
public class Pillar : IIdentifiable<string>, IPDXSerializable { | ||
public string Id { get; } | ||
public string Type { get; private set; } | ||
public string Type { get; } | ||
public Color? Color { get; } | ||
private readonly List<KeyValuePair<string, StringOfItem>> attributes; | ||
public IReadOnlyCollection<KeyValuePair<string, StringOfItem>> Attributes => attributes; | ||
|
||
public Pillar(string id, BufferedReader pillarReader) { | ||
public Pillar(string id, PillarData pillarData) { | ||
Id = id; | ||
|
||
var parser = new Parser(); | ||
parser.RegisterKeyword("type", reader => { | ||
Type = reader.GetString(); | ||
}); | ||
parser.IgnoreUnregisteredItems(); | ||
parser.ParseStream(pillarReader); | ||
Type = pillarData.Type!; | ||
Color = pillarData.Color; | ||
attributes = new List<KeyValuePair<string, StringOfItem>>(pillarData.Attributes); | ||
} | ||
|
||
public string Serialize(string indent, bool withBraces) { | ||
var contentIndent = indent; | ||
if (withBraces) { | ||
contentIndent += '\t'; | ||
} | ||
|
||
var sb = new StringBuilder(); | ||
if (withBraces) { | ||
sb.AppendLine("{"); | ||
} | ||
|
||
if (string.IsNullOrEmpty(Type)) { | ||
throw new ConverterException($"Cultural pillar {id} has no type defined!"); | ||
sb.Append(contentIndent).AppendLine($"type={Type}"); | ||
if (Color is not null) { | ||
sb.Append(contentIndent).AppendLine($"color={Color}"); | ||
} | ||
sb.AppendLine(PDXSerializer.Serialize(Attributes, indent: contentIndent, withBraces: false)); | ||
|
||
if (withBraces) { | ||
sb.Append(indent).Append('}'); | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using commonItems; | ||
using commonItems.Colors; | ||
using System.Collections.Generic; | ||
|
||
namespace ImperatorToCK3.CK3.Cultures; | ||
|
||
public record PillarData { | ||
public IEnumerable<string> InvalidatingPillarIds { get; set; } = new List<string>(); | ||
public string? Type { get; set; } | ||
public Color? Color { get; set; } | ||
|
||
public IList<KeyValuePair<string, StringOfItem>> Attributes { get; } = new List<KeyValuePair<string, StringOfItem>>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
ImperatorToCK3/Data_Files/blankMod/output/common/culture/pillars/01_heritage.txt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
ImperatorToCK3/Data_Files/blankMod/output/common/culture/pillars/01_language.txt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.