Exemple #1
0
 public static void Register(TerrainGenerator t)
 {
     if (!Terrains.Contains(t) && t != null)
     {
         Terrains.Add(t);
     }
 }
Exemple #2
0
        public TerrainEditorDataContext()
        {
            Terrains.Add(new Terrain(new[]
            {
                new VertexInfo(-5, 5),
                new VertexInfo(5, 5),
                new VertexInfo(5, -5),
                new VertexInfo(-5, -5)
            })
            {
                UvMapping    = UvMapping.Mossy,
                FillMode     = FillMode.Fill,
                IsClosed     = true,
                SmoothFactor = 5
            });


            Urho.Application.Started += () =>
            {
                m_terrainNodes = ServiceLocator.Get <IUrho3DService>().Scene.CreateChild("TerrainNodes");

                var resource = ServiceLocator.Get <IResourceProviderService>().LoadResource(new FileInfo("Mossy.uvmapping"));
                SelectedTerrain.UvMapping = (UvMapping)resource;

                m_terrainNodes.AddChild(SelectedTerrain.MeshNode);

                new RecursivePropertyChangeListener(Terrains, nameof(Terrains)).PropertyChanged += (sender, args) =>
                {
                    m_terrainNodes.RemoveChildren(true, true, false);
                    m_terrainNodes.AddChild(SelectedTerrain.MeshNode);
                };
            };
            SelectedTerrain = Terrains[0];
        }
Exemple #3
0
        public TerrainEditorDataContext()
        {
            new PropertyChangeListener(Terrains).PropertyChanged += (sender, args) => OnPropertyChanged(nameof(TerrainsMeshes));

            Terrains.Add(new DynamicMesh(new[]
            {
                new VertexInfo(-5, 5),
                new VertexInfo(5, 5),
                new VertexInfo(5, -4),
                new VertexInfo(-5, -4)
            })
            {
                UvMapping             = UvMapping.Mossy,
                FillMode              = FillMode.Fill,
                IsClosed              = true,
                SplitCornersThreshold = 90,
                SmoothFactor          = 5
            });

            SelectedTerrain = Terrains[0];
        }
Exemple #4
0
 public void Add(TerrainGraphic g)
 {
     Terrains.Add(g.GraphicTag, g);
 }
 public void Add(Terrain.Terrain terrain)
 {
     ScreenObjects.Add(terrain);
     Terrains.Add(terrain);
 }
Exemple #6
0
 // Méthode pour ajouter un terrain
 public void AjouterTerrain(Terrain C)
 {
     Terrains.Add(C);
 }
Exemple #7
0
        private void ReadXML(string dataPath, bool strictParamParse = false, bool inferFromProto = false, string defaultTo = "Default to merge")//path is root folder, either of game or of mod
        {
            //set paths for current dir (StreamingAssets, or @mod
            string TerrainsPath = Path.Combine(dataPath, "Terrain Sources"); //for some reason,terrains
            string ModulesPath  = Path.Combine(dataPath, "");                //and DB are listed as filenames
            string DBPath       = Path.Combine(dataPath, "DataBase");        //but modules as full paths.

            if (TerrainsXML == null && ModulesXML == null && DBXML == null)
            {
                /*LOAD DEFAULT ARRAYS*/
                try
                {
                    TerrainsXML = XDocument.Load($"{Path.Combine(dataPath, "terrains.xml")}");
                    ModulesXML  = XDocument.Load($"{Path.Combine(dataPath, "eventModules.xml")}");
                    DBXML       = XDocument.Load($"{Path.Combine(dataPath, "database.xml")}");
                }
                catch (FileNotFoundException e)
                {   //if files not found, notify user, and abort
                    MessageBox.Show(e.Message);
                    return;
                }

                /*LOAD DEFAULT FILES*/
                foreach (XElement x in TerrainsXML.Element("TERRAINS").Elements())
                {
                    try
                    {
                        string name = x.Attribute("name").Value;
                        Terrains.Add(new XMLStore(name, XDocument.Load($"{Path.Combine(TerrainsPath, name)}")));
                        debugLog.Add("load " + name);
                    }
                    catch (FileNotFoundException e)
                    {
                        debugLog.Add("##error: " + e.Message);
                    }
                    catch
                    {
                        debugLog.Add(TerrainsPath);
                        debugLog.Add("##error in terrains.xml : element read error");
                    }
                }
                foreach (XElement x in ModulesXML.Element("ROOT").Elements())
                {
                    try
                    {
                        string name = x.Attribute("path").Value;
                        if (!name.Contains("DEBUG"))
                        {
                            Modules.Add(new XMLStore(name, XDocument.Load($"{Path.Combine(ModulesPath, name)}")));
                            debugLog.Add("load " + name);
                        }
                        else
                        {
                            debugLog.Add("skip " + name);
                        }
                    }
                    catch (FileNotFoundException e)
                    {
                        debugLog.Add("##error: " + e.Message);
                    }
                    catch
                    {
                        debugLog.Add(TerrainsPath);
                        debugLog.Add("##error in eventModules.xml : element read error");
                    }
                }
                foreach (XElement x in DBXML.Element("DATA_BASE").Elements())
                {
                    try
                    {
                        string name = x.Attribute("name").Value;
                        if (!name.Contains("Prototype"))
                        {
                            DB.Add(new XMLStore(name, XDocument.Load($"{Path.Combine(DBPath, name)}")));
                            debugLog.Add("load " + name);
                        }
                        else
                        {
                            //crawl through /DataBase/Proto for potential arrays
                            XDocument newFile = XDocument.Load($"{Path.Combine(DBPath, name)}");
                            foreach (XElement y in newFile.Root.Elements())
                            {
                                getArrays(y);
                            }
                        }
                    }
                    catch (FileNotFoundException e)
                    {
                        debugLog.Add("##error: " + e.Message);
                    }
                    catch
                    {
                        debugLog.Add(DBPath);
                        debugLog.Add("##error in database.xml : name = null");
                    }
                }

                //back up files before altering
                Backup(dataPath);
                return;
            }
            else
            {
                /*LOAD MOD DATA*/

                /*First load the index files from the mod folders, (if they're missing, log and continue).
                 * Then read the indexes, then start reading new files, merging or adding to XMLStore
                 * and main index as you go.
                 */
                XDocument newTerrainsXML = null;
                XDocument newModulesXML  = null;
                XDocument newDBXML       = null;
                debugLog.Add("Loading " + dataPath);
                try
                {
                    newTerrainsXML = XDocument.Load($"{Path.Combine(dataPath, "terrains.xml")}");
                    debugLog.Add("terrains.xml loaded");
                    foreach (XElement x in newTerrainsXML.Root.Elements())
                    {
                        string    fileName;
                        XDocument newFile;
                        try
                        {//get file, if it exists, else log and skip
                            fileName = x.Attribute("name").Value;
                            newFile  = XDocument.Load($"{Path.Combine(TerrainsPath, fileName)}");
                            debugLog.Add("load " + fileName);
                        }
                        catch (FileNotFoundException e)
                        {
                            debugLog.Add("##error: " + e.Message + ", skipping");
                            continue;
                        }
                        catch
                        {
                            debugLog.Add(TerrainsPath);
                            debugLog.Add("##error in terrains.xml : element read error");
                            continue;
                        }

                        if (!TerrainsXML.Root.Elements().Any(p => p.Attribute("name").Value != fileName))
                        {//if data files are not already listed, add them to the index and load file to file list
                            XElement newEntry = new XElement("DEFINITION");
                            newEntry.SetAttributeValue("name", x.Attribute("name").Value);
                            TerrainsXML.Root.Add(newEntry);
                            Terrains.Add(new XMLStore(fileName, newFile));
                        }
                        else
                        {//else, update existing
                            XMLStore oldFile = Terrains.Where(p => p.fileName == fileName).FirstOrDefault();
                            //note, oldfile and newfile are disparate object types
                            List <string> output = oldFile.Update(newFile, strictParamParse, inferFromProto, defaultTo, ProtoDB);
                            debugLog.AddRange(output);
                        }
                    }
                }
                catch (FileNotFoundException)
                {//not an error, per se, just not used
                    debugLog.Add("terrains.xml not found");
                }
                try
                {
                    newModulesXML = XDocument.Load($"{Path.Combine(dataPath, "eventModules.xml")}");
                    debugLog.Add("eventModules.xml loaded");
                    foreach (XElement x in newModulesXML.Root.Elements())
                    {
                        string    fileName;
                        XDocument newFile;
                        try
                        {//get file, if it exists, else log and skip
                            fileName = x.Attribute("path").Value;
                            newFile  = XDocument.Load($"{Path.Combine(ModulesPath, fileName)}");
                            debugLog.Add("load " + fileName);
                        }
                        catch (FileNotFoundException e)
                        {
                            debugLog.Add("##error: " + e.Message + ", skipping");
                            continue;
                        }
                        catch
                        {
                            debugLog.Add(ModulesPath);
                            debugLog.Add("##error in eventModules.xml : element read error");
                            continue;
                        }

                        if (!ModulesXML.Root.Elements().Any(p => p.Attribute("path").Value == fileName))
                        {//if data files are not already listed, add them to the index and load file to file list
                            XElement newEntry = new XElement("FILE");
                            newEntry.SetAttributeValue("path", x.Attribute("path").Value);
                            ModulesXML.Root.Add(newEntry);
                            Modules.Add(new XMLStore(fileName, newFile));
                        }
                        else
                        {//else, update existing
                            XMLStore oldFile = Modules.Where(p => p.fileName == fileName).FirstOrDefault();
                            //note, oldfile and newfile are disparate object types
                            List <string> output = oldFile.Update(newFile, strictParamParse, inferFromProto, defaultTo, ProtoDB);
                            debugLog.AddRange(output);
                        }
                    }
                }
                catch (FileNotFoundException)
                {//not an error, per se, just not used
                    debugLog.Add("eventModules.xml not found");
                }
                try
                {
                    newDBXML = XDocument.Load($"{Path.Combine(dataPath, "database.xml")}");
                    debugLog.Add("database.xml loaded");
                    foreach (XElement x in newDBXML.Root.Elements())
                    {
                        string    fileName;
                        XDocument newFile;
                        try
                        {//get file, if it exists, else log and skip
                            fileName = x.Attribute("name").Value;
                            newFile  = XDocument.Load($"{Path.Combine(DBPath, fileName)}");
                            debugLog.Add("load " + fileName);
                        }
                        catch (FileNotFoundException e)
                        {
                            debugLog.Add("##error: " + e.Message + ", skipping");
                            continue;
                        }
                        catch
                        {
                            debugLog.Add(ModulesPath);
                            debugLog.Add("##error in database.xml : element read error");
                            continue;
                        }

                        if (!DBXML.Root.Elements().Any(p => p.Attribute("name").Value != fileName))
                        {//if data files are not already listed, add them to the index and load file to file list
                            XElement newEntry = new XElement("DATA");
                            newEntry.SetAttributeValue("name", x.Attribute("name").Value);
                            ModulesXML.Root.Add(newEntry);
                            Modules.Add(new XMLStore(fileName, newFile));
                        }
                        else
                        {//else, update existing
                            XMLStore oldFile = DB.Where(p => p.fileName == fileName).FirstOrDefault();
                            //note, oldfile and newfile are disparate object types
                            List <string> output = oldFile.Update(newFile, strictParamParse, inferFromProto, defaultTo, ProtoDB);
                            debugLog.AddRange(output);
                        }
                    }
                }
                catch (FileNotFoundException)
                {//not an error, per se, just not used
                    debugLog.Add("database.xml not found");
                }
            }
        }