Skip to content

Commit c97fcfb

Browse files
authored
Planet region fixes (#143)
* map the current health for planet regions if available see #142 * map planet region ID * handle case of a region not existing in JSON files * correctly annotate nullable in generated sources * name `Name` for planet regions nullable * map settinghash * fix nullable in generated sources * update JSON submodule
1 parent e37be8e commit c97fcfb

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,19 @@ private Planet MapToV1(MappingContext context, PlanetInfo info, PlanetStatus sta
9494
private Region MapToV1(Models.ArrowHead.Info.PlanetRegion region, Models.ArrowHead.Status.PlanetRegionStatus? status, MappingContext context)
9595
{
9696
string? owner = null;
97+
(string Name, string? Description)? planetRegion = null;
9798
if (status is { Owner: var faction })
9899
Static.Factions.TryGetValue(faction, out owner);
99100

100-
Static.PlanetRegion.TryGetValue(region.SettingsHash, out var planetRegion);
101+
if (Static.PlanetRegion.ContainsKey(region.SettingsHash))
102+
planetRegion = Static.PlanetRegion[region.SettingsHash];
103+
101104
return new Region(
102-
Name: planetRegion.Name,
103-
Description: planetRegion.Description,
105+
Id: region.RegionIndex,
106+
Hash: region.SettingsHash,
107+
Name: planetRegion?.Name,
108+
Description: planetRegion?.Description,
109+
Health: status?.Health,
104110
MaxHealth: region.MaxHealth,
105111
Size: (RegionSize)region.RegionSize,
106112
RegenPerSecond: status?.RegerPerSecond,

src/Helldivers-2-Models/V1/Planets/Region.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22

33
/// <summary>
44
/// A region on a planet.
5+
///
6+
/// The <c>Name</c> and <c>Description</c> fields may be empty when the underlying data store doesn't contain information on them.
7+
/// This is typically when ArrowHead adds new regions that aren't updated in the data store (helldivers-2/json) yet.
8+
///
9+
/// Note that some properties may be unavailable when the region is inactive.
510
/// </summary>
11+
/// <param name="Id">The identifier of this region.</param>
12+
/// <param name="Hash">The underlying hash identifier of ArrowHead.</param>
613
/// <param name="Name">The name of the region.</param>
714
/// <param name="Description">A long-form description of the region.</param>
15+
/// <param name="Health">The current health of the region.</param>
816
/// <param name="MaxHealth">The maximum health of this region.</param>
917
/// <param name="Size">The size of this region.</param>
1018
/// <param name="RegenPerSecond">The amount of health this region generates when left alone.</param>
1119
/// <param name="AvailabilityFactor">Unknown purpose.</param>
1220
/// <param name="IsAvailable">Whether the region is currently playable(?).</param>
1321
/// <param name="Players">The amount of helldivers currently active in this region.</param>
1422
public record struct Region(
15-
string Name,
16-
string Description,
23+
int Id,
24+
ulong Hash,
25+
string? Name,
26+
string? Description,
27+
long? Health,
1728
ulong MaxHealth,
1829
RegionSize Size,
1930
double? RegenPerSecond,

src/Helldivers-2-Models/json

src/Helldivers-2-SourceGen/Parsers/BaseJsonParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Helldivers.SourceGen.Parsers;
1111
public abstract class BaseJsonParser : IJsonParser
1212
{
1313
private const string TEMPLATE = @"// <auto-generated />
14+
#nullable enable
1415
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1516
using global::System.Collections.Generic;
1617
using global::Helldivers.Models.Domain.Localization;

src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class PlanetRegionsParser : BaseJsonParser
1212
/// <inheritdoc />
1313
protected override (string Type, string Source) Parse(string json)
1414
{
15-
var builder = new StringBuilder("new Dictionary<ulong, (string Name, string Description)>()\n\t{\n");
15+
var builder = new StringBuilder("new Dictionary<ulong, (string Name, string? Description)>()\n\t{\n");
1616
var document = JsonDocument.Parse(json);
1717
foreach (var property in document.RootElement.EnumerateObject())
1818
{
@@ -28,6 +28,6 @@ protected override (string Type, string Source) Parse(string json)
2828
}
2929

3030
builder.Append("\t}");
31-
return ("IReadOnlyDictionary<ulong, (string Name, string Description)>", builder.ToString());
31+
return ("IReadOnlyDictionary<ulong, (string Name, string? Description)>", builder.ToString());
3232
}
3333
}

0 commit comments

Comments
 (0)