11using Helldivers . Models ;
22using Helldivers . Models . V1 ;
3+ using Helldivers . Models . V1 . SpaceStations ;
34
45namespace Helldivers . Core . Mapping . V1 ;
56
@@ -16,19 +17,43 @@ public sealed class SpaceStationMapper
1617 /// <returns>An enumerable list of space stations mapped to the V1 model.</returns>
1718 public IEnumerable < SpaceStation > MapToV1 ( MappingContext context , List < Planet > planets )
1819 {
19- foreach ( var station in context . InvariantWarStatus . SpaceStations )
20- yield return Map ( context , station , planets ) ;
20+ // Get a list of all assignments across all translations.
21+ var invariants = context . SpaceStations
22+ . SelectMany ( pair => pair . Value )
23+ . DistinctBy ( spaceStation => spaceStation . Id32 ) ;
24+
25+ foreach ( var spaceStation in invariants )
26+ {
27+ // Build a dictionary of all translations for this assignment
28+ var translations = context . SpaceStations . Select ( pair =>
29+ new KeyValuePair < string , Models . ArrowHead . SpaceStation ? > (
30+ pair . Key ,
31+ pair . Value . FirstOrDefault ( a => a . Id32 == spaceStation . Id32 )
32+ )
33+ ) . Where ( pair => pair . Value is not null )
34+ . ToDictionary ( pair => pair . Key , pair => pair . Value ! ) ;
35+
36+ yield return Map ( translations , context , planets ) ;
37+ }
2138 }
2239
23- private SpaceStation Map ( MappingContext context , Helldivers . Models . ArrowHead . SpaceStation raw , List < Planet > planets )
40+ private SpaceStation Map ( Dictionary < string , Models . ArrowHead . SpaceStation > translations , MappingContext context , List < Planet > planets )
2441 {
25- var planet = planets . First ( p => p . Index == raw . PlanetIndex ) ;
42+ var invariant = translations . First ( ) . Value ;
43+ var planet = planets . First ( p => p . Index == invariant . PlanetIndex ) ;
2644
2745 return new SpaceStation (
28- Id32 : raw . Id32 ,
46+ Id32 : invariant . Id32 ,
2947 Planet : planet ,
30- ElectionEnd : context . RelativeGameStart . AddSeconds ( raw . CurrentElectionEndWarTime ) ,
31- Flags : raw . Flags
48+ ElectionEnd : context . RelativeGameStart . AddSeconds ( invariant . CurrentElectionEndWarTime ) ,
49+ Flags : invariant . Flags ,
50+ TacticalActions : invariant . TacticalActions . Select ( rawAction => MapTacticalAction ( context , rawAction ) ) . ToList ( )
3251 ) ;
3352 }
53+
54+ private TacticalAction MapTacticalAction ( MappingContext context , Helldivers . Models . ArrowHead . SpaceStations . TacticalAction raw )
55+ {
56+ // TODO: map actions.
57+ return new TacticalAction ( ) ;
58+ }
3459}
0 commit comments