/// <summary> /// Creates a new Properties Loader from a spawned CelestialBody. /// </summary> public PropertiesLoader(CelestialBody body) { // Is this a spawned body? if (body?.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } // Store values Value = body; // We require a science values object if (Value.scienceValues == null) { Value.scienceValues = new CelestialBodyScienceParams(); } scienceValues = new ScienceValuesLoader(Value.scienceValues); // isHomeWorld Check Value.isHomeWorld = Value.transform.name == "Kerbin"; // Biomes biomes = new CallbackList <BiomeLoader>(e => { // Check biome map if (Value.BiomeMap == null) { throw new InvalidOperationException("The Biome Map cannot be null if you want to add biomes."); } // Replace the old biomes list with the new one Value.BiomeMap.Attributes = biomes.Select(b => b.Value).ToArray(); }); }
/// <summary> /// Creates a new Properties Loader from the Injector context. /// </summary> public PropertiesLoader() { // Is this the parser context? if (!Injector.IsInPrefab) { throw new InvalidOperationException("Must be executed in Injector context."); } // Store values Value = generatedBody.celestialBody; // We require a science values object if (Value.scienceValues == null) { Value.scienceValues = new CelestialBodyScienceParams(); } scienceValues = new ScienceValuesLoader(Value.scienceValues); // isHomeWorld Check Value.isHomeWorld = Value.transform.name == "Kerbin"; // Biomes biomes = new CallbackList <BiomeLoader>(e => { // Check biome map if (Value.BiomeMap == null) { throw new InvalidOperationException("The Biome Map cannot be null if you want to add biomes."); } // Replace the old biomes list with the new one Value.BiomeMap.Attributes = biomes.Select(b => b.Value).ToArray(); }); }
// Apply Event void IParserEventSubscriber.Apply(ConfigNode node) { // We require a science values object if (celestialBody.scienceValues == null) { celestialBody.scienceValues = new CelestialBodyScienceParams(); } // Create the science values cache scienceValues = new ScienceValuesLoader(celestialBody.scienceValues); }