Exemple #1
0
            // Parser Post Apply Event
            void IParserEventSubscriber.PostApply(ConfigNode node)
            {
                // If Debug Mode is null, create default values
                if (debug == null) debug = new DebugLoader();
                if (scaledVersion == null) scaledVersion = new ScaledVersionLoader();

                // PQS
                if (generatedBody.pqsVersion)
                {
                    // Adjust the radius of the PQSs appropriately
                    foreach (PQS p in generatedBody.pqsVersion.GetComponentsInChildren<PQS>(true))
                        p.radius = generatedBody.celestialBody.Radius;
                }

                // Create a barycenter
                if (barycenter.value)
                {
                    // Register the body for post-spawn patching
                    generatedBody.Set("barycenter", true);

                    // Nuke the PQS
                    if (generatedBody.pqsVersion != null)
                    {
                        generatedBody.pqsVersion.transform.parent = null;
                        UnityEngine.Object.Destroy(generatedBody.pqsVersion);
                        generatedBody.pqsVersion = null;
                    }

                    // Stop ScaledSpace Cache
                    scaledVersion.deferMesh = true;
                }

                // We need to generate new scaled space meshes if
                //   a) we are using a template and we've change either the radius or type of body
                //   b) we aren't using a template
                //   c) debug mode is active
                if (!scaledVersion.deferMesh &&
                    (((template != null) && (Math.Abs(template.radius - generatedBody.celestialBody.Radius) > 1.0 || template.type != scaledVersion.type.value))
                    || template == null || debug.update))
                {

                    Utility.UpdateScaledMesh(generatedBody.scaledVersion,
                                                generatedBody.pqsVersion,
                                                generatedBody.celestialBody,
                                                ScaledSpaceCacheDirectory,
                                                cacheFile,
                                                debug.exportMesh,
                                                scaledVersion.sphericalModel);
                }

                // Visualize the SOI
                if (debug.showSOI)
                    generatedBody.celestialBody.gameObject.AddComponent<Wiresphere>();

                // Loads external parser targets
                Parser.LoadExternalParserTargets(node, "Kopernicus");

                // Post gen celestial body
                Utility.DumpObjectFields(generatedBody.celestialBody, " Celestial Body ");
            }
            /// <summary>
            /// Saves the celestial body into a Kopernicus formatted ConfigNode.
            /// </summary>
            public static void SaveCelestial(CelestialBody planet)
            {
                // Create the main node
                ConfigNode root = new ConfigNode("@Kopernicus:NEEDS[!Kopernicus]");
                ConfigNode body = root.AddNode("Body");

                // Create the body
                body.AddValue("name", planet.name);

                // Properties
                ConfigNode properties = WriteObjectToConfigNode("Properties", ref body, new PropertiesLoader(planet));

                // Properties.Biomes
                if (planet.BiomeMap != null)
                {
                    ConfigNode biomes = properties.AddNode("Biomes");
                    foreach (CBAttributeMapSO.MapAttribute biome in planet.BiomeMap.Attributes)
                    {
                        WriteObjectToConfigNode("Biome", ref biomes, new BiomeLoader(biome));
                    }
                }

                // Properties.ScienceValues
                if (planet.scienceValues != null)
                {
                    WriteObjectToConfigNode("ScienceValues", ref properties, new ScienceValuesLoader(planet.scienceValues));
                }

                // Orbit
                if (planet.orbitDriver)
                {
                    WriteObjectToConfigNode("Orbit", ref body, new OrbitLoader(planet));
                }

                // Atmosphere
                if (planet.atmosphere)
                {
                    ConfigNode atmo = WriteObjectToConfigNode("Atmosphere", ref body, new AtmosphereLoader(planet));

                    // Atmosphere.AtmosphereFromGround
                    if (planet.afg != null)
                    {
                        WriteObjectToConfigNode("AtmosphereFromGround", ref atmo, new AtmosphereFromGroundLoader(planet));
                    }
                }

                // ScaledVersion
                ScaledVersionLoader scaledLoader = new ScaledVersionLoader(planet);
                ConfigNode          scaled       = WriteObjectToConfigNode("ScaledVersion", ref body, scaledLoader);

                // ScaledVersion.Material
                Material material = planet.scaledBody.GetComponent <Renderer>().sharedMaterial;

                if (scaledLoader.type == BodyType.Star)
                {
                    WriteObjectToConfigNode("Material", ref scaled, new EmissiveMultiRampSunspotsLoader(material));

                    // ScaledVersion.Light
                    WriteObjectToConfigNode("Light", ref scaled, new LightShifterLoader(planet));

                    // ScaledVersion.Coronas
                    if (planet.scaledBody.GetComponentsInChildren <SunCoronas>().Length != 0)
                    {
                        ConfigNode coronas = scaled.AddNode("Coronas");
                        foreach (SunCoronas corona in planet.scaledBody.GetComponentsInChildren <SunCoronas>(true))
                        {
                            WriteObjectToConfigNode("Corona", ref coronas, new CoronaLoader(corona));
                        }
                    }
                }
                else if (scaledLoader.type == BodyType.Atmospheric)
                {
                    WriteObjectToConfigNode("Material", ref scaled, new ScaledPlanetRimAerialLoader());
                }
                else
                {
                    WriteObjectToConfigNode("Material", ref scaled, new ScaledPlanetSimpleLoader(material));
                }

                // Particles
                ConfigNode particles = body.AddNode("Particles");

                foreach (PlanetParticleEmitter e in planet.scaledBody.GetComponentsInChildren <PlanetParticleEmitter>(true))
                {
                    ParticleLoader loader = new ParticleLoader(e);
                    WriteObjectToConfigNode("Particle", ref particles, loader);
                }

                // Rings
                if (planet.scaledBody.GetComponentsInChildren <Ring>(true).Length != 0)
                {
                    ConfigNode rings = body.AddNode("Rings");
                    foreach (Ring ring in planet.scaledBody.GetComponentsInChildren <Ring>(true))
                    {
                        WriteObjectToConfigNode("Ring", ref rings, new RingLoader(ring));
                    }
                }

                // PQS
                if (planet.pqsController)
                {
                    WritePQSToConfigNode(planet.pqsController, ref body, false);
                }

                // Ocean
                if (planet.ocean)
                {
                    WritePQSToConfigNode(planet.pqsController.ChildSpheres[0], ref body, true);
                }

                // Save the node
                Directory.CreateDirectory(KSPUtil.ApplicationRootPath + "/GameData/KittopiaTech/Config/");
                ConfigNode save = new ConfigNode();

                save.AddNode(root);
                save.Save("GameData/KittopiaTech/Config/" + planet.name + ".cfg", "KittopiaTech - a Kopernicus Visual Editor");
            }