-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add SpaceStation to ArrowHead API (#120)
* add SpaceStation to ArrowHead API see #118 * add v1 support for space stations
- Loading branch information
Showing
7 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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,34 @@ | ||
using Helldivers.Models; | ||
using Helldivers.Models.V1; | ||
|
||
namespace Helldivers.Core.Mapping.V1; | ||
|
||
/// <summary> | ||
/// Handles mapping for <see cref="SpaceStation" />. | ||
/// </summary> | ||
public sealed class SpaceStationMapper | ||
{ | ||
/// <summary> | ||
/// Maps all space stations in the <see cref="MappingContext" />. | ||
/// </summary> | ||
/// <param name="context">The mapping context containing the invariant war status and other relevant data.</param> | ||
/// <param name="planets">The list of planets to map with.</param> | ||
/// <returns>An enumerable list of space stations mapped to the V1 model.</returns> | ||
public IEnumerable<SpaceStation> MapToV1(MappingContext context, List<Planet> planets) | ||
{ | ||
foreach (var station in context.InvariantWarStatus.SpaceStations) | ||
yield return Map(context, station, planets); | ||
} | ||
|
||
private SpaceStation Map(MappingContext context, Helldivers.Models.ArrowHead.Status.SpaceStation raw, List<Planet> planets) | ||
{ | ||
var planet = planets.First(p => p.Index == raw.PlanetIndex); | ||
|
||
return new SpaceStation( | ||
Id32: raw.Id32, | ||
Planet: planet, | ||
ElectionEnd: context.RelativeGameStart.AddSeconds(raw.CurrentElectionEndWarTime), | ||
Flags: raw.Flags | ||
); | ||
} | ||
} |
This file contains 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,11 @@ | ||
using Helldivers.Core.Contracts.Collections; | ||
using Helldivers.Models.V1; | ||
|
||
namespace Helldivers.Core.Storage.V1; | ||
|
||
/// <inheritdoc cref="IStore{T,TKey}" /> | ||
public sealed class SpaceStationStore : StoreBase<SpaceStation, int> | ||
{ | ||
/// <inheritdoc /> | ||
protected override bool GetAsyncPredicate(SpaceStation station, int index) => station.Id32 == index; | ||
} |
This file contains 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,16 @@ | ||
namespace Helldivers.Models.ArrowHead.Status; | ||
|
||
/// <summary> | ||
/// Represents one of the space stations as passed from the ArrowHead API. | ||
/// </summary> | ||
/// <param name="Id32">The unique identifier of the station.</param> | ||
/// <param name="PlanetIndex">The id of the planet it's currently orbiting</param> | ||
/// <param name="CurrentElectionEndWarTime">When the election for the next planet will end (in seconds relative to game start).</param> | ||
/// <param name="Flags">A set of flags, purpose currently unknown.</param> | ||
public sealed record SpaceStation( | ||
long Id32, | ||
int PlanetIndex, | ||
// TODO PlanetActiveEffects | ||
ulong CurrentElectionEndWarTime, | ||
int Flags | ||
); |
This file contains 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 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,15 @@ | ||
namespace Helldivers.Models.V1; | ||
|
||
/// <summary> | ||
/// Represents a Super Earth Democracy Space Station. | ||
/// </summary> | ||
/// <param name="Id32">The unique identifier of the station.</param> | ||
/// <param name="Planet">The planet it's currently orbiting.</param> | ||
/// <param name="ElectionEnd">When the election for the next planet will end.</param> | ||
/// <param name="Flags">A set of flags, purpose currently unknown.</param> | ||
public sealed record SpaceStation( | ||
long Id32, | ||
Planet Planet, | ||
DateTime ElectionEnd, | ||
int Flags | ||
); |