-
-
Notifications
You must be signed in to change notification settings - Fork 23
Maintenance #114
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
Merged
Merged
Maintenance #114
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e7883ec
Update package dependencies across multiple projects
dealloc 83a4ff0
update helldivers-2/json
dealloc ab55704
Refactor source generator to handle incremental processing
dealloc 9ee18da
Add support for multiple rewards in assignments
dealloc 7c0a8ae
Add header validation to RateLimitMiddleware
dealloc f15a228
fix formatting using `dotnet format`
dealloc 6b2c72d
Remove commented-out package reference
dealloc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Submodule json
updated
10 files
+111 −1 | items/armor/armor.json | |
+4 −0 | items/armor/passive.json | |
+5 −1 | items/boosters.json | |
+99 −7 | items/item_names.json | |
+4 −1 | items/weapons/fire_modes.json | |
+5 −5 | items/weapons/grenades.json | |
+67 −16 | items/weapons/primary.json | |
+23 −6 | items/weapons/secondary.json | |
+5 −0 | warbonds.json | |
+97 −0 | warbonds/truth_enforcers.json |
This file contains hidden or 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,18 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Helldivers.SourceGen.Contracts; | ||
|
||
/// <summary> | ||
/// Interface for parsing JSON strings and generating corresponding C# source code. | ||
/// </summary> | ||
public interface IJsonParser | ||
{ | ||
/// <summary> | ||
/// Parses the given source text and generates corresponding C# source code. | ||
/// </summary> | ||
/// <param name="file">The source file to be parsed.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken" /> for cancelling the parse process.</param> | ||
/// <returns>A <see cref="SourceText"/> object representing the generated C# source code.</returns> | ||
SourceText Parse(AdditionalText file, CancellationToken cancellationToken = default); | ||
} |
This file contains hidden or 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 hidden or 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,50 @@ | ||
using Helldivers.SourceGen.Contracts; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Text; | ||
using System.Text; | ||
|
||
namespace Helldivers.SourceGen.Parsers; | ||
|
||
/// <summary> | ||
/// An abstract base class for parsing JSON data and generating corresponding C# source code. | ||
/// </summary> | ||
public abstract class BaseJsonParser : IJsonParser | ||
{ | ||
private const string TEMPLATE = @"// <auto-generated /> | ||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
using global::System.Collections.Generic; | ||
using global::Helldivers.Models.Domain.Localization; | ||
|
||
namespace Helldivers.Models; | ||
|
||
public static partial class Static | ||
{{ | ||
/// <summary>Public list of {0} entries from {1}</summary> | ||
public static {2} {0} = {3}; | ||
}}"; | ||
|
||
/// <inheritdoc /> | ||
public SourceText Parse(AdditionalText file, CancellationToken cancellationToken = default) | ||
{ | ||
var filename = Path.GetFileName(file.Path); | ||
var json = file.GetText(cancellationToken)?.ToString(); | ||
|
||
var name = Path.GetFileNameWithoutExtension(file.Path); | ||
name = $"{char.ToUpper(name[0])}{name.Substring(1)}"; | ||
|
||
if (string.IsNullOrWhiteSpace(json) is false) | ||
{ | ||
var (type, csharp) = Parse(json!); | ||
|
||
var output = string.Format(TEMPLATE, name, filename, type, csharp); | ||
return SourceText.From(output, Encoding.UTF8); | ||
} | ||
|
||
return SourceText.From("// Could not read JSON file"); | ||
} | ||
|
||
/// <summary> | ||
/// Convert the JSON string into C# code that can be injected. | ||
/// </summary> | ||
protected abstract (string Type, string Source) Parse(string json); | ||
} |
This file contains hidden or 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,22 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
|
||
namespace Helldivers.SourceGen.Parsers; | ||
|
||
/// <summary> | ||
/// BiomesParser is responsible for parsing a JSON string representation of biomes. | ||
/// </summary> | ||
public class BiomesParser : BaseJsonParser | ||
{ | ||
/// <inheritdoc /> | ||
protected override (string Type, string Source) Parse(string json) | ||
{ | ||
var builder = new StringBuilder("new Dictionary<string, Helldivers.Models.V1.Planets.Biome>()\n\t{\n"); | ||
var entries = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(json)!; | ||
foreach (var pair in entries) | ||
builder.AppendLine($@"{'\t'}{'\t'}{{ ""{pair.Key}"", new Helldivers.Models.V1.Planets.Biome(""{pair.Value["name"]}"", ""{pair.Value["description"]}"") }},"); | ||
|
||
builder.Append("\t}"); | ||
return ("IReadOnlyDictionary<string, Helldivers.Models.V1.Planets.Biome>", builder.ToString()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Helldivers-2-SourceGen/Parsers/EnvironmentalsParser.cs
This file contains hidden or 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,23 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
|
||
namespace Helldivers.SourceGen.Parsers; | ||
|
||
/// <summary> | ||
/// The EnvironmentalsParser class is responsible for parsing JSON strings | ||
/// representing environmental hazards and converting them into C# source code. | ||
/// </summary> | ||
public class EnvironmentalsParser : BaseJsonParser | ||
{ | ||
/// <inheritdoc /> | ||
protected override (string Type, string Source) Parse(string json) | ||
{ | ||
var builder = new StringBuilder("new Dictionary<string, Helldivers.Models.V1.Planets.Hazard>()\n\t{\n"); | ||
var entries = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(json)!; | ||
foreach (var pair in entries) | ||
builder.AppendLine($@"{'\t'}{'\t'}{{ ""{pair.Key}"", new Helldivers.Models.V1.Planets.Hazard(""{pair.Value["name"]}"", ""{pair.Value["description"]}"") }},"); | ||
|
||
builder.Append("\t}"); | ||
return ("IReadOnlyDictionary<string, Helldivers.Models.V1.Planets.Hazard>", builder.ToString()); | ||
} | ||
} |
This file contains hidden or 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,22 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
|
||
namespace Helldivers.SourceGen.Parsers; | ||
|
||
/// <summary> | ||
/// Parses JSON data of factions and generates the corresponding C# source code representation. | ||
/// </summary> | ||
public class FactionsParser : BaseJsonParser | ||
{ | ||
/// <inheritdoc /> | ||
protected override (string Type, string Source) Parse(string json) | ||
{ | ||
var builder = new StringBuilder("new Dictionary<int, string>()\n\t{\n"); | ||
var entries = JsonSerializer.Deserialize<Dictionary<string, string>>(json)!; | ||
foreach (var pair in entries) | ||
builder.AppendLine($@"{'\t'}{'\t'}{{ {pair.Key}, ""{pair.Value}"" }},"); | ||
|
||
builder.Append("\t}"); | ||
return ("IReadOnlyDictionary<int, string>", builder.ToString()); | ||
} | ||
} |
This file contains hidden or 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,40 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
|
||
namespace Helldivers.SourceGen.Parsers; | ||
|
||
/// <summary> | ||
/// Handles parsing the planets.json and generating the resulting planet data. | ||
/// </summary> | ||
public class PlanetsParser : BaseJsonParser | ||
{ | ||
/// <inheritdoc /> | ||
protected override (string Type, string Source) Parse(string json) | ||
{ | ||
var builder = new StringBuilder("new Dictionary<int, (LocalizedMessage Name, string Sector, string Biome, List<string> Environmentals)>()\n\t{\n"); | ||
var document = JsonDocument.Parse(json); | ||
foreach (var property in document.RootElement.EnumerateObject()) | ||
{ | ||
var index = property.Name; | ||
var name = property.Value.GetProperty("name").GetString(); | ||
var names = property | ||
.Value | ||
.GetProperty("names") | ||
.EnumerateObject() | ||
.ToDictionary(prop => prop.Name, prop => prop.Value.GetString()!); | ||
var sector = property.Value.GetProperty("sector").GetString(); | ||
var biome = property.Value.GetProperty("biome").GetString(); | ||
var environmentals = property | ||
.Value | ||
.GetProperty("environmentals") | ||
.EnumerateArray() | ||
.Select(prop => $@"""{prop.GetString()!}""") | ||
.ToList(); | ||
|
||
builder.AppendLine($@"{'\t'}{'\t'}{{ {index}, (LocalizedMessage.FromStrings([{string.Join(", ", names.Select(pair => $@"new KeyValuePair<string, string>(""{pair.Key}"", ""{pair.Value}"")"))}]), ""{sector}"", ""{biome}"", [{string.Join(", ", environmentals)}]) }},"); | ||
} | ||
|
||
builder.Append("\t}"); | ||
return ("IReadOnlyDictionary<int, (LocalizedMessage Name, string Sector, string Biome, List<string> Environmentals)>", builder.ToString()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.