예제 #1
0
                // Post Apply Event
                void IParserEventSubscriber.PostApply(ConfigNode node)
                {
                    // Get the SimplexLoaders etc.
                    mod.altitudeSimplex  = altitudeSimplex.simplex;
                    mod.latitudeSimplex  = latitudeSimplex.simplex;
                    mod.longitudeSimplex = longitudeSimplex.simplex;

                    // Load the LandClasses manually, to support patching
                    if (mod.landClasses != null)
                    {
                        mod.landClasses.ToList().ForEach(c => landClasses.Add(new LandClassLoader(c)));
                    }
                    if (node.HasNode("landClasses"))
                    {
                        // Already patched classes
                        List <PQSLandControl.LandClass> patchedClasses = new List <PQSLandControl.LandClass>();

                        // Go through the nodes
                        foreach (ConfigNode lcNode in node.GetNode("landClasses").nodes)
                        {
                            // The Loader
                            LandClassLoader loader = null;

                            // Are there existing LandClasses?
                            if (landClasses.Count > 0)
                            {
                                // Attempt to find a LandClass we can edit that we have not edited before
                                loader = landClasses.Where(m => !patchedClasses.Contains(m.landClass) && (lcNode.HasValue("name") ? m.landClass.landClassName == lcNode.GetValue("name") : false))
                                         .FirstOrDefault();

                                // Load the Loader (lol)
                                if (loader != null)
                                {
                                    Parser.LoadObjectFromConfigurationNode(loader, lcNode, "Kopernicus");
                                    landClasses.Remove(loader);
                                    patchedClasses.Add(loader.landClass);
                                }
                            }

                            // If we can't patch a LandClass, create a new one
                            if (loader == null)
                            {
                                loader = Parser.CreateObjectFromConfigNode <LandClassLoader>(lcNode, "Kopernicus");
                            }

                            // Add the Loader to the List
                            if (!loader.delete.value)
                            {
                                landClasses.Add(loader);
                            }
                        }
                    }

                    // Load the Scatters manually, to support patching
                    if (mod.scatters != null)
                    {
                        mod.scatters.ToList().ForEach(s => scatters.Add(new LandClassScatterLoader(s)));
                    }
                    if (node.HasNode("scatters"))
                    {
                        // Already patched scatters
                        List <PQSLandControl.LandClassScatter> patchedScatters = new List <PQSLandControl.LandClassScatter>();

                        // Go through the nodes
                        foreach (ConfigNode scatterNode in node.GetNode("scatters").nodes)
                        {
                            // The Loader
                            LandClassScatterLoader loader = null;

                            // Are there existing Scatters?
                            if (scatters.Count > 0)
                            {
                                // Attempt to find a Scatter we can edit that we have not edited before
                                loader = scatters.Where(m => !patchedScatters.Contains(m.scatter) && (scatterNode.HasValue("name") ? m.scatter.scatterName == scatterNode.GetValue("name") : false))
                                         .FirstOrDefault();


                                // Load the Loader (lol)
                                if (loader != null)
                                {
                                    Parser.LoadObjectFromConfigurationNode(loader, scatterNode, "Kopernicus");
                                    scatters.Remove(loader);
                                    patchedScatters.Add(loader.scatter);
                                }
                            }

                            // If we can't patch a Scatter, create a new one
                            if (loader == null)
                            {
                                loader = Parser.CreateObjectFromConfigNode <LandClassScatterLoader>(scatterNode, "Kopernicus");
                            }

                            // Add the Loader to the List
                            if (!loader.delete.value)
                            {
                                scatters.Add(loader);
                            }
                        }
                    }

                    if (scatters.Count > 0)
                    {
                        mod.scatters = scatters.Select(s => s.scatter).ToArray();
                    }
                    else
                    {
                        mod.scatters = new PQSLandControl.LandClassScatter[0];
                    }
                    if (landClasses.Count > 0)
                    {
                        mod.landClasses = landClasses.Select(c => c.landClass).ToArray();
                    }
                    else
                    {
                        mod.landClasses = new PQSLandControl.LandClass[0];
                    }

                    // Assign each scatter amount with their corresponding scatter
                    foreach (PQSLandControl.LandClass landClass in mod.landClasses)
                    {
                        foreach (PQSLandControl.LandClassScatterAmount amount in landClass.scatter)
                        {
                            int i = 0;
                            while (i < mod.scatters.Length)
                            {
                                if (mod.scatters[i].scatterName.Equals(amount.scatterName))
                                {
                                    break;
                                }
                                i++;
                            }

                            if (i < mod.scatters.Length)
                            {
                                amount.scatterIndex = i;
                                amount.scatter      = mod.scatters[i];
                            }
                        }
                    }

                    // Add Colliders to the scatters
                    foreach (PQSLandControl.LandClassScatter scatter in mod.scatters)
                    {
                        // If nothing's there, abort
                        if (!scatters.Any(s => s.scatter.scatterName == scatter.scatterName))
                        {
                            continue;
                        }

                        // Get the Loader
                        LandClassScatterLoader loader = scatters.First(s => s.scatter.scatterName == scatter.scatterName);

                        // Create the Scatter-Parent
                        GameObject scatterParent = new GameObject("Scatter " + scatter.scatterName);
                        scatterParent.transform.parent        = mod.sphere.transform;
                        scatterParent.transform.localPosition = Vector3.zero;
                        scatterParent.transform.localRotation = Quaternion.identity;
                        scatterParent.transform.localScale    = Vector3.one;

                        // Add the ScatterExtension
                        Scatter.CreateInstance(scatterParent, loader.science, loader.collide, loader.experiment);
                    }
                }