Skip to content
Merged
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
12 changes: 9 additions & 3 deletions src/Helldivers-2-Core/Mapping/V1/PlanetMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,19 @@ 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(
Name: planetRegion.Name,
Description: planetRegion.Description,
Id: region.RegionIndex,
Hash: region.SettingsHash,
Name: planetRegion?.Name,
Description: planetRegion?.Description,
Health: status?.Health,
MaxHealth: region.MaxHealth,
Size: (RegionSize)region.RegionSize,
RegenPerSecond: status?.RegerPerSecond,
Expand Down
15 changes: 13 additions & 2 deletions src/Helldivers-2-Models/V1/Planets/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@

/// <summary>
/// A region on a planet.
///
/// The <c>Name</c> and <c>Description</c> 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.
/// </summary>
/// <param name="Id">The identifier of this region.</param>
/// <param name="Hash">The underlying hash identifier of ArrowHead.</param>
/// <param name="Name">The name of the region.</param>
/// <param name="Description">A long-form description of the region.</param>
/// <param name="Health">The current health of the region.</param>
/// <param name="MaxHealth">The maximum health of this region.</param>
/// <param name="Size">The size of this region.</param>
/// <param name="RegenPerSecond">The amount of health this region generates when left alone.</param>
/// <param name="AvailabilityFactor">Unknown purpose.</param>
/// <param name="IsAvailable">Whether the region is currently playable(?).</param>
/// <param name="Players">The amount of helldivers currently active in this region.</param>
public record struct Region(
string Name,
string Description,
int Id,
ulong Hash,
string? Name,
string? Description,
long? Health,
ulong MaxHealth,
RegionSize Size,
double? RegenPerSecond,
Expand Down
2 changes: 1 addition & 1 deletion src/Helldivers-2-Models/json
1 change: 1 addition & 0 deletions src/Helldivers-2-SourceGen/Parsers/BaseJsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Helldivers.SourceGen.Parsers;
public abstract class BaseJsonParser : IJsonParser
{
private const string TEMPLATE = @"// <auto-generated />
#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;
Expand Down
4 changes: 2 additions & 2 deletions src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PlanetRegionsParser : BaseJsonParser
/// <inheritdoc />
protected override (string Type, string Source) Parse(string json)
{
var builder = new StringBuilder("new Dictionary<ulong, (string Name, string Description)>()\n\t{\n");
var builder = new StringBuilder("new Dictionary<ulong, (string Name, string? Description)>()\n\t{\n");
var document = JsonDocument.Parse(json);
foreach (var property in document.RootElement.EnumerateObject())
{
Expand All @@ -28,6 +28,6 @@ protected override (string Type, string Source) Parse(string json)
}

builder.Append("\t}");
return ("IReadOnlyDictionary<ulong, (string Name, string Description)>", builder.ToString());
return ("IReadOnlyDictionary<ulong, (string Name, string? Description)>", builder.ToString());
}
}