Skip to content
Open
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
15 changes: 14 additions & 1 deletion OpenPolytopia.Common/EmbeddedResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public static class EmbeddedResources {
// serialization conventions shared by all the json resources
private static readonly JsonSerializerOptions _jsonOptions = new() {
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(UnicodeRanges.All),
TypeInfoResolver = JsonTypeInfoResolver.Combine(TribeGenerationContext.Default, TroopGenerationContext.Default),
TypeInfoResolver = JsonTypeInfoResolver.Combine(TribeGenerationContext.Default, TroopGenerationContext.Default,
TechTreeGenerationContext.Default),
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
};

Expand All @@ -23,6 +24,11 @@ public static class EmbeddedResources {
/// </summary>
public static string TribesData => GetResource("OpenPolytopia.Common.resources.tribes.json");

/// <summary>
/// Get the tech tree data from the json file
/// </summary>
public static string TechTreeData => GetResource("OpenPolytopia.Common.resources.tech_tree.json");

/// <summary>
/// Deserializes the troops from the embedded json file
/// </summary>
Expand All @@ -37,6 +43,13 @@ public static class EmbeddedResources {
public static TribesSerializedData? LoadTribes() =>
JsonSerializer.Deserialize<TribesSerializedData>(TribesData, _jsonOptions);

/// <summary>
/// Deserializes the tech tree from the embedded json file
/// </summary>
/// <returns>the tech tree data, or null if the json is empty</returns>
public static TechTreeSerializedData? LoadTechTree() =>
JsonSerializer.Deserialize<TechTreeSerializedData>(TechTreeData, _jsonOptions);

/// <summary>
/// Returns the content of an embedded resource
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions OpenPolytopia.Common/OpenPolytopia.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<EmbeddedResource Include="resources\tribes.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="resources\tech_tree.json"/>
<EmbeddedResource Include="resources\tech_tree.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

</Project>
Loading
Loading