public StarSystems(WorldContext worldContext, StarSystemsData data) { WorldContext = worldContext; _starSystemsDictionary = new Dictionary <Guid, StarSystem>(); VoidID = Guid.Empty; }
public static WorldContext GenerateWorld(ShipData playerShipData) { const Int32 starSystemsCount = 16; var positions = GenerateStarSystemsPositions(starSystemsCount, 10); var starSystemsData = new StarSystemsData { StarSystems = new StarSystemData[starSystemsCount] }; var spaceObjects = new List <SpaceObjectData>(); for (Int32 i = 0; i < starSystemsCount; i++) { var starSystem = new StarSystemData { ID = Guid.NewGuid(), UniverseMapPosition = positions[i] }; starSystemsData.StarSystems[i] = starSystem; var star = GenerateStar(starSystem); spaceObjects.Add(star); spaceObjects.AddRange(GeneratePlanetsSystem(star)); } spaceObjects.Add(playerShipData); playerShipData.LocationID = starSystemsData.StarSystems.First().ID; var captainsData = new CaptainsData { PlayerData = new CaptainData { CurrentShipID = playerShipData.ID } }; var worldContext = new WorldContext(new WorldContextData { WorldCtlData = new WorldCtlData { Date = new DateTime(3042, 1, 1) }, StarSystemsData = starSystemsData, SpaceObjectsData = new SpaceObjectsData { SpaceObjects = spaceObjects.ToArray() }, CaptainsData = captainsData }); return(worldContext); }
/// <summary> /// Called immediately after constructor. Separated because initialization of WorldContext fields is required. /// </summary> internal void InitializeFromData(StarSystemsData data) { if (Void != null) { throw new InvalidOperationException("Already initialized."); } Void = new StarSystem(WorldContext, new StarSystemData { ID = VoidID, UniverseMapPosition = Vector2.zero }); foreach (var starSystemData in data.StarSystems) { starSystemData.GetInstanceFromData(WorldContext); } }