diff --git a/src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs b/src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs index 884ace8..00d5c88 100644 --- a/src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs +++ b/src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs @@ -71,6 +71,7 @@ public static IServiceCollection AddV1Stores(this IServiceCollection services) services.AddSingleton, CampaignStore>(); services.AddSingleton, Storage.V1.AssignmentStore>(); services.AddSingleton, DispatchStore>(); + services.AddSingleton, SpaceStationStore>(); // Register mappers services.AddSingleton(); @@ -79,6 +80,7 @@ public static IServiceCollection AddV1Stores(this IServiceCollection services) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); return services; } diff --git a/src/Helldivers-2-Core/Facades/V1Facade.cs b/src/Helldivers-2-Core/Facades/V1Facade.cs index c619b5c..5b91e62 100644 --- a/src/Helldivers-2-Core/Facades/V1Facade.cs +++ b/src/Helldivers-2-Core/Facades/V1Facade.cs @@ -19,7 +19,9 @@ public sealed class V1Facade( IStore assignmentStore, AssignmentMapper assignmentMapper, IStore dispatchStore, - DispatchMapper dispatchMapper + DispatchMapper dispatchMapper, + IStore spaceStationStore, + SpaceStationMapper spaceStationMapper ) { /// @@ -35,6 +37,7 @@ public async ValueTask UpdateStores(MappingContext context) await UpdateCampaignStore(context, planets); await UpdateAssignmentsStore(context); await UpdateDispatchStore(context); + await UpdateSpaceStationStore(context, planets); } private async ValueTask UpdateWarStore(MappingContext context, List planets) @@ -76,4 +79,13 @@ private async ValueTask UpdateDispatchStore(MappingContext context) await dispatchStore.SetStore(dispatches); } + + private async ValueTask UpdateSpaceStationStore(MappingContext context, List planets) + { + var spaceStations = spaceStationMapper + .MapToV1(context, planets) + .ToList(); + + await spaceStationStore.SetStore(spaceStations); + } } diff --git a/src/Helldivers-2-Core/Mapping/V1/SpaceStationMapper.cs b/src/Helldivers-2-Core/Mapping/V1/SpaceStationMapper.cs new file mode 100644 index 0000000..bdb2a90 --- /dev/null +++ b/src/Helldivers-2-Core/Mapping/V1/SpaceStationMapper.cs @@ -0,0 +1,34 @@ +using Helldivers.Models; +using Helldivers.Models.V1; + +namespace Helldivers.Core.Mapping.V1; + +/// +/// Handles mapping for . +/// +public sealed class SpaceStationMapper +{ + /// + /// Maps all space stations in the . + /// + /// The mapping context containing the invariant war status and other relevant data. + /// The list of planets to map with. + /// An enumerable list of space stations mapped to the V1 model. + public IEnumerable MapToV1(MappingContext context, List 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 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 + ); + } +} diff --git a/src/Helldivers-2-Core/Storage/V1/SpaceStationStore.cs b/src/Helldivers-2-Core/Storage/V1/SpaceStationStore.cs new file mode 100644 index 0000000..0277031 --- /dev/null +++ b/src/Helldivers-2-Core/Storage/V1/SpaceStationStore.cs @@ -0,0 +1,11 @@ +using Helldivers.Core.Contracts.Collections; +using Helldivers.Models.V1; + +namespace Helldivers.Core.Storage.V1; + +/// +public sealed class SpaceStationStore : StoreBase +{ + /// + protected override bool GetAsyncPredicate(SpaceStation station, int index) => station.Id32 == index; +} diff --git a/src/Helldivers-2-Models/ArrowHead/Status/SpaceStation.cs b/src/Helldivers-2-Models/ArrowHead/Status/SpaceStation.cs new file mode 100644 index 0000000..d1384b3 --- /dev/null +++ b/src/Helldivers-2-Models/ArrowHead/Status/SpaceStation.cs @@ -0,0 +1,16 @@ +namespace Helldivers.Models.ArrowHead.Status; + +/// +/// Represents one of the space stations as passed from the ArrowHead API. +/// +/// The unique identifier of the station. +/// The id of the planet it's currently orbiting +/// When the election for the next planet will end (in seconds relative to game start). +/// A set of flags, purpose currently unknown. +public sealed record SpaceStation( + long Id32, + int PlanetIndex, + // TODO PlanetActiveEffects + ulong CurrentElectionEndWarTime, + int Flags +); diff --git a/src/Helldivers-2-Models/ArrowHead/WarStatus.cs b/src/Helldivers-2-Models/ArrowHead/WarStatus.cs index e88f300..b3db1b3 100644 --- a/src/Helldivers-2-Models/ArrowHead/WarStatus.cs +++ b/src/Helldivers-2-Models/ArrowHead/WarStatus.cs @@ -14,6 +14,7 @@ namespace Helldivers.Models.ArrowHead; /// A list of ongoing campaigns in the galactic war. /// A list of s. /// A list of ongoing s. +/// A list of s. public sealed record WarStatus( int WarId, long Time, @@ -24,9 +25,10 @@ public sealed record WarStatus( List Campaigns, // TODO CommunityTargets List JointOperations, - List PlanetEvents + List PlanetEvents, // TODO PlanetActiveEffects // TODO activeElectionPolicyEffects // TODO globalEvents // TODO superEarthWarResults + List SpaceStations ); diff --git a/src/Helldivers-2-Models/V1/SpaceStation.cs b/src/Helldivers-2-Models/V1/SpaceStation.cs new file mode 100644 index 0000000..72e9daf --- /dev/null +++ b/src/Helldivers-2-Models/V1/SpaceStation.cs @@ -0,0 +1,15 @@ +namespace Helldivers.Models.V1; + +/// +/// Represents a Super Earth Democracy Space Station. +/// +/// The unique identifier of the station. +/// The planet it's currently orbiting. +/// When the election for the next planet will end. +/// A set of flags, purpose currently unknown. +public sealed record SpaceStation( + long Id32, + Planet Planet, + DateTime ElectionEnd, + int Flags +);