Skip to content

Commit a04b920

Browse files
committed
add v1 support for space stations
1 parent 4a4b3ab commit a04b920

File tree

6 files changed

+79
-5
lines changed

6 files changed

+79
-5
lines changed

src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static IServiceCollection AddV1Stores(this IServiceCollection services)
7171
services.AddSingleton<IStore<Campaign, int>, CampaignStore>();
7272
services.AddSingleton<IStore<Models.V1.Assignment, long>, Storage.V1.AssignmentStore>();
7373
services.AddSingleton<IStore<Dispatch, int>, DispatchStore>();
74+
services.AddSingleton<IStore<SpaceStation, int>, SpaceStationStore>();
7475

7576
// Register mappers
7677
services.AddSingleton<AssignmentMapper>();
@@ -79,6 +80,7 @@ public static IServiceCollection AddV1Stores(this IServiceCollection services)
7980
services.AddSingleton<PlanetMapper>();
8081
services.AddSingleton<StatisticsMapper>();
8182
services.AddSingleton<WarMapper>();
83+
services.AddSingleton<SpaceStationMapper>();
8284

8385
return services;
8486
}

src/Helldivers-2-Core/Facades/V1Facade.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public sealed class V1Facade(
1919
IStore<Assignment, long> assignmentStore,
2020
AssignmentMapper assignmentMapper,
2121
IStore<Dispatch, int> dispatchStore,
22-
DispatchMapper dispatchMapper
22+
DispatchMapper dispatchMapper,
23+
IStore<SpaceStation, int> spaceStationStore,
24+
SpaceStationMapper spaceStationMapper
2325
)
2426
{
2527
/// <see cref="IStore{T,TKey}.SetStore" />
@@ -35,6 +37,7 @@ public async ValueTask UpdateStores(MappingContext context)
3537
await UpdateCampaignStore(context, planets);
3638
await UpdateAssignmentsStore(context);
3739
await UpdateDispatchStore(context);
40+
await UpdateSpaceStationStore(context, planets);
3841
}
3942

4043
private async ValueTask UpdateWarStore(MappingContext context, List<Planet> planets)
@@ -76,4 +79,13 @@ private async ValueTask UpdateDispatchStore(MappingContext context)
7679

7780
await dispatchStore.SetStore(dispatches);
7881
}
82+
83+
private async ValueTask UpdateSpaceStationStore(MappingContext context, List<Planet> planets)
84+
{
85+
var spaceStations = spaceStationMapper
86+
.MapToV1(context, planets)
87+
.ToList();
88+
89+
await spaceStationStore.SetStore(spaceStations);
90+
}
7991
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Helldivers.Models;
2+
using Helldivers.Models.V1;
3+
4+
namespace Helldivers.Core.Mapping.V1;
5+
6+
/// <summary>
7+
/// Handles mapping for <see cref="SpaceStation" />.
8+
/// </summary>
9+
public sealed class SpaceStationMapper
10+
{
11+
/// <summary>
12+
/// Maps all space stations in the <see cref="MappingContext" />.
13+
/// </summary>
14+
/// <param name="context">The mapping context containing the invariant war status and other relevant data.</param>
15+
/// <param name="planets">The list of planets to map with.</param>
16+
/// <returns>An enumerable list of space stations mapped to the V1 model.</returns>
17+
public IEnumerable<SpaceStation> MapToV1(MappingContext context, List<Planet> planets)
18+
{
19+
foreach (var station in context.InvariantWarStatus.SpaceStations)
20+
yield return Map(context, station, planets);
21+
}
22+
23+
private SpaceStation Map(MappingContext context, Helldivers.Models.ArrowHead.Status.SpaceStation raw, List<Planet> planets)
24+
{
25+
var planet = planets.First(p => p.Index == raw.PlanetIndex);
26+
27+
return new SpaceStation(
28+
Id32: raw.Id32,
29+
Planet: planet,
30+
ElectionEnd: context.RelativeGameStart.AddSeconds(raw.CurrentElectionEndWarTime),
31+
Flags: raw.Flags
32+
);
33+
}
34+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Helldivers.Core.Contracts.Collections;
2+
using Helldivers.Models.V1;
3+
4+
namespace Helldivers.Core.Storage.V1;
5+
6+
/// <inheritdoc cref="IStore{T,TKey}" />
7+
public sealed class SpaceStationStore : StoreBase<SpaceStation, int>
8+
{
9+
/// <inheritdoc />
10+
protected override bool GetAsyncPredicate(SpaceStation station, int index) => station.Id32 == index;
11+
}

src/Helldivers-2-Models/ArrowHead/Status/SpaceStation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ namespace Helldivers.Models.ArrowHead.Status;
33
/// <summary>
44
/// Represents one of the space stations as passed from the ArrowHead API.
55
/// </summary>
6-
/// <param name="Id32"></param>
7-
/// <param name="PlanetIndex"></param>
8-
/// <param name="CurrentElectionEndWarTime"></param>
9-
/// <param name="Flags"></param>
6+
/// <param name="Id32">The unique identifier of the station.</param>
7+
/// <param name="PlanetIndex">The id of the planet it's currently orbiting</param>
8+
/// <param name="CurrentElectionEndWarTime">When the election for the next planet will end (in seconds relative to game start).</param>
9+
/// <param name="Flags">A set of flags, purpose currently unknown.</param>
1010
public sealed record SpaceStation(
1111
long Id32,
1212
int PlanetIndex,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Helldivers.Models.V1;
2+
3+
/// <summary>
4+
/// Represents a Super Earth Democracy Space Station.
5+
/// </summary>
6+
/// <param name="Id32">The unique identifier of the station.</param>
7+
/// <param name="Planet">The planet it's currently orbiting.</param>
8+
/// <param name="ElectionEnd">When the election for the next planet will end.</param>
9+
/// <param name="Flags">A set of flags, purpose currently unknown.</param>
10+
public sealed record SpaceStation(
11+
long Id32,
12+
Planet Planet,
13+
DateTime ElectionEnd,
14+
int Flags
15+
);

0 commit comments

Comments
 (0)