From b7f2fb927ea4452036596d4e82827fcb62007afb Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Sun, 15 Jun 2025 15:48:40 +0200 Subject: [PATCH 1/8] map the current health for planet regions if available see #142 --- src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs | 1 + src/Helldivers-2-Models/V1/Planets/Region.cs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs index bea89bc..a3e19cc 100644 --- a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs +++ b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs @@ -101,6 +101,7 @@ private Region MapToV1(Models.ArrowHead.Info.PlanetRegion region, Models.ArrowHe return new Region( Name: planetRegion.Name, Description: planetRegion.Description, + Health: status?.Health, MaxHealth: region.MaxHealth, Size: (RegionSize)region.RegionSize, RegenPerSecond: status?.RegerPerSecond, diff --git a/src/Helldivers-2-Models/V1/Planets/Region.cs b/src/Helldivers-2-Models/V1/Planets/Region.cs index ab0cd51..386787a 100644 --- a/src/Helldivers-2-Models/V1/Planets/Region.cs +++ b/src/Helldivers-2-Models/V1/Planets/Region.cs @@ -2,9 +2,12 @@ /// /// A region on a planet. +/// +/// Note that some properties may be unavailable when the region is inactive. /// /// The name of the region. /// A long-form description of the region. +/// The current health of the region. /// The maximum health of this region. /// The size of this region. /// The amount of health this region generates when left alone. @@ -14,6 +17,7 @@ public record struct Region( string Name, string Description, + long? Health, ulong MaxHealth, RegionSize Size, double? RegenPerSecond, From 98c8660ce9e1694658ec4db8f196a49aa3297c22 Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Sun, 15 Jun 2025 15:50:21 +0200 Subject: [PATCH 2/8] map planet region ID --- src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs | 1 + src/Helldivers-2-Models/V1/Planets/Region.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs index a3e19cc..c5d5104 100644 --- a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs +++ b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs @@ -99,6 +99,7 @@ private Region MapToV1(Models.ArrowHead.Info.PlanetRegion region, Models.ArrowHe Static.PlanetRegion.TryGetValue(region.SettingsHash, out var planetRegion); return new Region( + Id: region.RegionIndex, Name: planetRegion.Name, Description: planetRegion.Description, Health: status?.Health, diff --git a/src/Helldivers-2-Models/V1/Planets/Region.cs b/src/Helldivers-2-Models/V1/Planets/Region.cs index 386787a..27855be 100644 --- a/src/Helldivers-2-Models/V1/Planets/Region.cs +++ b/src/Helldivers-2-Models/V1/Planets/Region.cs @@ -5,6 +5,7 @@ /// /// Note that some properties may be unavailable when the region is inactive. /// +/// The identifier of this region. /// The name of the region. /// A long-form description of the region. /// The current health of the region. @@ -15,6 +16,7 @@ /// Whether the region is currently playable(?). /// The amount of helldivers currently active in this region. public record struct Region( + int Id, string Name, string Description, long? Health, From 67f1fc1194db8d17c039bc27a7953e75d16dfffd Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Sun, 15 Jun 2025 15:56:25 +0200 Subject: [PATCH 3/8] handle case of a region not existing in JSON files --- src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs | 9 ++++++--- src/Helldivers-2-Models/V1/Planets/Region.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs index c5d5104..446547a 100644 --- a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs +++ b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs @@ -94,14 +94,17 @@ private Planet MapToV1(MappingContext context, PlanetInfo info, PlanetStatus sta private Region MapToV1(Models.ArrowHead.Info.PlanetRegion region, Models.ArrowHead.Status.PlanetRegionStatus? status, MappingContext context) { string? owner = null; + (string Name, string Description)? planetRegion = null; if (status is { Owner: var faction }) Static.Factions.TryGetValue(faction, out owner); - Static.PlanetRegion.TryGetValue(region.SettingsHash, out var planetRegion); + if (Static.PlanetRegion.ContainsKey(region.SettingsHash)) + planetRegion = Static.PlanetRegion[region.SettingsHash]; + return new Region( Id: region.RegionIndex, - Name: planetRegion.Name, - Description: planetRegion.Description, + Name: planetRegion?.Name ?? string.Empty, + Description: planetRegion?.Description, Health: status?.Health, MaxHealth: region.MaxHealth, Size: (RegionSize)region.RegionSize, diff --git a/src/Helldivers-2-Models/V1/Planets/Region.cs b/src/Helldivers-2-Models/V1/Planets/Region.cs index 27855be..308f08a 100644 --- a/src/Helldivers-2-Models/V1/Planets/Region.cs +++ b/src/Helldivers-2-Models/V1/Planets/Region.cs @@ -18,7 +18,7 @@ public record struct Region( int Id, string Name, - string Description, + string? Description, long? Health, ulong MaxHealth, RegionSize Size, From a56aeae10504ebd1c5dfd1a80053c4c6295deb55 Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Sun, 15 Jun 2025 15:58:09 +0200 Subject: [PATCH 4/8] correctly annotate nullable in generated sources --- src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs b/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs index 3a2e09a..bb5eaf6 100644 --- a/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs +++ b/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs @@ -12,7 +12,7 @@ public class PlanetRegionsParser : BaseJsonParser /// protected override (string Type, string Source) Parse(string json) { - var builder = new StringBuilder("new Dictionary()\n\t{\n"); + var builder = new StringBuilder("new Dictionary()\n\t{\n"); var document = JsonDocument.Parse(json); foreach (var property in document.RootElement.EnumerateObject()) { @@ -28,6 +28,6 @@ protected override (string Type, string Source) Parse(string json) } builder.Append("\t}"); - return ("IReadOnlyDictionary", builder.ToString()); + return ("IReadOnlyDictionary", builder.ToString()); } } From c2b7b3eb03e1654111fec3f42bcadc7847808f1e Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Sun, 15 Jun 2025 15:59:59 +0200 Subject: [PATCH 5/8] name `Name` for planet regions nullable --- src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs | 2 +- src/Helldivers-2-Models/V1/Planets/Region.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs index 446547a..db53cd1 100644 --- a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs +++ b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs @@ -103,7 +103,7 @@ private Region MapToV1(Models.ArrowHead.Info.PlanetRegion region, Models.ArrowHe return new Region( Id: region.RegionIndex, - Name: planetRegion?.Name ?? string.Empty, + Name: planetRegion?.Name, Description: planetRegion?.Description, Health: status?.Health, MaxHealth: region.MaxHealth, diff --git a/src/Helldivers-2-Models/V1/Planets/Region.cs b/src/Helldivers-2-Models/V1/Planets/Region.cs index 308f08a..00ce2b8 100644 --- a/src/Helldivers-2-Models/V1/Planets/Region.cs +++ b/src/Helldivers-2-Models/V1/Planets/Region.cs @@ -3,6 +3,9 @@ /// /// A region on a planet. /// +/// The Name and Description fields may be empty when the underlying data store doesn't contain information on them. +/// This is typically when ArrowHead adds new regions that aren't updated in the data store (helldivers-2/json) yet. +/// /// Note that some properties may be unavailable when the region is inactive. /// /// The identifier of this region. @@ -17,7 +20,7 @@ /// The amount of helldivers currently active in this region. public record struct Region( int Id, - string Name, + string? Name, string? Description, long? Health, ulong MaxHealth, From 6cc23f61b6ac4b2575fc58eb46094bb98207b9d0 Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Sun, 15 Jun 2025 16:02:23 +0200 Subject: [PATCH 6/8] map settinghash --- src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs | 1 + src/Helldivers-2-Models/V1/Planets/Region.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs index db53cd1..7f9d337 100644 --- a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs +++ b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs @@ -103,6 +103,7 @@ private Region MapToV1(Models.ArrowHead.Info.PlanetRegion region, Models.ArrowHe return new Region( Id: region.RegionIndex, + Hash: region.SettingsHash, Name: planetRegion?.Name, Description: planetRegion?.Description, Health: status?.Health, diff --git a/src/Helldivers-2-Models/V1/Planets/Region.cs b/src/Helldivers-2-Models/V1/Planets/Region.cs index 00ce2b8..3c0b6d6 100644 --- a/src/Helldivers-2-Models/V1/Planets/Region.cs +++ b/src/Helldivers-2-Models/V1/Planets/Region.cs @@ -9,6 +9,7 @@ /// Note that some properties may be unavailable when the region is inactive. /// /// The identifier of this region. +/// The underlying hash identifier of ArrowHead. /// The name of the region. /// A long-form description of the region. /// The current health of the region. @@ -20,6 +21,7 @@ /// The amount of helldivers currently active in this region. public record struct Region( int Id, + ulong Hash, string? Name, string? Description, long? Health, From 011f9756ccf84e6f08a7c35ab10835fdd838808c Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Sun, 15 Jun 2025 16:05:14 +0200 Subject: [PATCH 7/8] fix nullable in generated sources --- src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs | 2 +- src/Helldivers-2-SourceGen/Parsers/BaseJsonParser.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs index 7f9d337..c6343b3 100644 --- a/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs +++ b/src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs @@ -94,7 +94,7 @@ private Planet MapToV1(MappingContext context, PlanetInfo info, PlanetStatus sta private Region MapToV1(Models.ArrowHead.Info.PlanetRegion region, Models.ArrowHead.Status.PlanetRegionStatus? status, MappingContext context) { string? owner = null; - (string Name, string Description)? planetRegion = null; + (string Name, string? Description)? planetRegion = null; if (status is { Owner: var faction }) Static.Factions.TryGetValue(faction, out owner); diff --git a/src/Helldivers-2-SourceGen/Parsers/BaseJsonParser.cs b/src/Helldivers-2-SourceGen/Parsers/BaseJsonParser.cs index a4ad984..6ff839a 100644 --- a/src/Helldivers-2-SourceGen/Parsers/BaseJsonParser.cs +++ b/src/Helldivers-2-SourceGen/Parsers/BaseJsonParser.cs @@ -11,6 +11,7 @@ namespace Helldivers.SourceGen.Parsers; public abstract class BaseJsonParser : IJsonParser { private const string TEMPLATE = @"// +#nullable enable #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member using global::System.Collections.Generic; using global::Helldivers.Models.Domain.Localization; From 78c0062b4c1fc24832e0c0158ee2fea53f3e84f5 Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Tue, 17 Jun 2025 16:58:30 +0200 Subject: [PATCH 8/8] update JSON submodule --- src/Helldivers-2-Models/json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helldivers-2-Models/json b/src/Helldivers-2-Models/json index 5d08918..ca7a5d2 160000 --- a/src/Helldivers-2-Models/json +++ b/src/Helldivers-2-Models/json @@ -1 +1 @@ -Subproject commit 5d08918c6ada366f755dacdb0644308fcf88b1be +Subproject commit ca7a5d2d34d6ac124b6952409ce28da91597a1e6