Esempio n. 1
0
 public void Serialize(XElement element)
 {
     SerializableProperty.SerializeProperties(this, element);
 }
Esempio n. 2
0
        private void SerializeAll()
        {
            System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
            {
                Indent = true,
                NewLineOnAttributes = true
            };
            foreach (ContentFile configFile in GameMain.Instance.GetFilesOfType(ContentType.LevelGenerationParameters))
            {
                XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
                if (doc == null)
                {
                    continue;
                }

                foreach (LevelGenerationParams genParams in LevelGenerationParams.LevelParams)
                {
                    foreach (XElement element in doc.Root.Elements())
                    {
                        XElement levelParamElement = element;
                        if (element.IsOverride())
                        {
                            foreach (XElement subElement in element.Elements())
                            {
                                string id = element.GetAttributeString("identifier", null) ?? element.Name.ToString();
                                if (!id.Equals(genParams.Name, StringComparison.OrdinalIgnoreCase))
                                {
                                    continue;
                                }
                                SerializableProperty.SerializeProperties(genParams, element, true);
                            }
                        }
                        else
                        {
                            string id = element.GetAttributeString("identifier", null) ?? element.Name.ToString();
                            if (!id.Equals(genParams.Name, StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }
                            SerializableProperty.SerializeProperties(genParams, element, true);
                        }
                        break;
                    }
                }
                using (var writer = XmlWriter.Create(configFile.Path, settings))
                {
                    doc.WriteTo(writer);
                    writer.Flush();
                }
            }

            settings.NewLineOnAttributes = false;
            foreach (ContentFile configFile in GameMain.Instance.GetFilesOfType(ContentType.LevelObjectPrefabs))
            {
                XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
                if (doc == null)
                {
                    continue;
                }

                foreach (LevelObjectPrefab levelObjPrefab in LevelObjectPrefab.List)
                {
                    foreach (XElement element in doc.Root.Elements())
                    {
                        if (!element.Name.ToString().Equals(levelObjPrefab.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        levelObjPrefab.Save(element);
                        break;
                    }
                }
                using (var writer = XmlWriter.Create(configFile.Path, settings))
                {
                    doc.WriteTo(writer);
                    writer.Flush();
                }
            }

            RuinGenerationParams.SaveAll();
        }
Esempio n. 3
0
        private void SerializeAll()
        {
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent = true,
                NewLineOnAttributes = true
            };

            foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.LevelGenerationParameters))
            {
                XDocument doc = XMLExtensions.TryLoadXml(configFile);
                if (doc == null || doc.Root == null)
                {
                    continue;
                }

                foreach (LevelGenerationParams genParams in LevelGenerationParams.LevelParams)
                {
                    foreach (XElement element in doc.Root.Elements())
                    {
                        if (element.Name.ToString().ToLowerInvariant() != genParams.Name.ToLowerInvariant())
                        {
                            continue;
                        }
                        SerializableProperty.SerializeProperties(genParams, element, true);
                        break;
                    }
                }
                using (var writer = XmlWriter.Create(configFile, settings))
                {
                    doc.WriteTo(writer);
                    writer.Flush();
                }
            }

            settings.NewLineOnAttributes = false;
            foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.LevelObjectPrefabs))
            {
                XDocument doc = XMLExtensions.TryLoadXml(configFile);
                if (doc == null || doc.Root == null)
                {
                    continue;
                }

                foreach (LevelObjectPrefab levelObjPrefab in LevelObjectPrefab.List)
                {
                    foreach (XElement element in doc.Root.Elements())
                    {
                        if (element.Name.ToString().ToLowerInvariant() != levelObjPrefab.Name.ToLowerInvariant())
                        {
                            continue;
                        }
                        levelObjPrefab.Save(element);
                        break;
                    }
                }
                using (var writer = XmlWriter.Create(configFile, settings))
                {
                    doc.WriteTo(writer);
                    writer.Flush();
                }
            }

            RuinGenerationParams.SaveAll();
        }
Esempio n. 4
0
        public void Save(XElement element)
        {
            this.Config = element;

            SerializableProperty.SerializeProperties(this, element);

            foreach (XElement subElement in element.Elements().ToList())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "childobject":
                case "lightsource":
                    subElement.Remove();
                    break;

                case "deformablesprite":
                    subElement.RemoveNodes();
                    foreach (SpriteDeformation deformation in SpriteDeformations)
                    {
                        var deformationElement = new XElement("SpriteDeformation");
                        deformation.Save(deformationElement);
                        subElement.Add(deformationElement);
                    }
                    break;
                }
            }

            foreach (LightSourceParams lightSourceParams in LightSourceParams)
            {
                var lightElement = new XElement("LightSource");
                SerializableProperty.SerializeProperties(lightSourceParams, lightElement);
                element.Add(lightElement);
            }

            foreach (ChildObject childObj in ChildObjects)
            {
                element.Add(new XElement("ChildObject",
                                         new XAttribute("names", string.Join(", ", childObj.AllowedNames)),
                                         new XAttribute("mincount", childObj.MinCount),
                                         new XAttribute("maxcount", childObj.MaxCount)));
            }

            foreach (KeyValuePair <string, float> overrideCommonness in OverrideCommonness)
            {
                bool elementFound = false;
                foreach (XElement subElement in element.Elements())
                {
                    if (subElement.Name.ToString().Equals("overridecommonness", System.StringComparison.OrdinalIgnoreCase) &&
                        subElement.GetAttributeString("leveltype", "") == overrideCommonness.Key)
                    {
                        subElement.Attribute("commonness").Value = overrideCommonness.Value.ToString("G", CultureInfo.InvariantCulture);
                        elementFound = true;
                        break;
                    }
                }
                if (!elementFound)
                {
                    element.Add(new XElement("overridecommonness",
                                             new XAttribute("leveltype", overrideCommonness.Key),
                                             new XAttribute("commonness", overrideCommonness.Value.ToString("G", CultureInfo.InvariantCulture))));
                }
            }
        }