SaveDifferences() public static method

public static SaveDifferences ( object o, object from, bool includePrivateByDefault = false ) : MiniYaml
o object
from object
includePrivateByDefault bool
return MiniYaml
Example #1
0
File: Map.cs Project: test71/OpenRA
        public void Save(string toPath)
        {
            MapFormat = 5;

            var root   = new List <MiniYamlNode>();
            var fields = new []
            {
                "Selectable",
                "MapFormat",
                "RequiresMod",
                "Title",
                "Description",
                "Author",
                "Tileset",
                "MapSize",
                "Bounds",
                "UseAsShellmap",
                "Type",
            };

            foreach (var field in fields)
            {
                var f = this.GetType().GetField(field);
                if (f.GetValue(this) == null)
                {
                    continue;
                }
                root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
            }

            root.Add(new MiniYamlNode("Players", null,
                                      Players.Select(p => new MiniYamlNode(
                                                         "PlayerReference@{0}".F(p.Key),
                                                         FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList()));

            root.Add(new MiniYamlNode("Actors", null,
                                      Actors.Value.Select(x => new MiniYamlNode(
                                                              x.Key,
                                                              x.Value.Save())).ToList()));

            root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList <SmudgeReference>(Smudges.Value)));
            root.Add(new MiniYamlNode("Rules", null, Rules));
            root.Add(new MiniYamlNode("Sequences", null, Sequences));
            root.Add(new MiniYamlNode("Weapons", null, Weapons));
            root.Add(new MiniYamlNode("Voices", null, Voices));

            var entries = new Dictionary <string, byte[]>();

            entries.Add("map.bin", SaveBinaryData());
            var s = root.WriteToString();

            entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));

            // Saving the map to a new location
            if (toPath != Path)
            {
                Path = toPath;

                // Create a new map package
                // TODO: Add other files (custom assets) to the entries list
                Container = FileSystem.CreatePackage(Path, int.MaxValue, entries);
            }

            // Update existing package
            Container.Write(entries);
        }
Example #2
0
        public void Save(string toPath)
        {
            MapFormat = 6;

            var root   = new List <MiniYamlNode>();
            var fields = new[]
            {
                "Selectable",
                "MapFormat",
                "RequiresMod",
                "Title",
                "Description",
                "Author",
                "PreviewVideo",
                "Tileset",
                "MapSize",
                "Bounds",
                "UseAsShellmap",
                "Type",
            };

            foreach (var field in fields)
            {
                var f = this.GetType().GetField(field);
                if (f.GetValue(this) == null)
                {
                    continue;
                }
                root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
            }

            root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions())));

            root.Add(new MiniYamlNode("Players", null,
                                      Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key), FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList())
                     );

            root.Add(new MiniYamlNode("Actors", null,
                                      Actors.Value.Select(x => new MiniYamlNode(x.Key, x.Value.Save())).ToList())
                     );

            root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList <SmudgeReference>(Smudges.Value)));
            root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
            root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
            root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
            root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions));
            root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions));
            root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions));
            root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions));

            var entries = new Dictionary <string, byte[]>();

            entries.Add("map.bin", SaveBinaryData());
            var s = root.WriteToString();

            entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));

            // Add any custom assets
            if (Container != null)
            {
                foreach (var file in Container.AllFileNames())
                {
                    if (file == "map.bin" || file == "map.yaml")
                    {
                        continue;
                    }

                    entries.Add(file, Container.GetContent(file).ReadAllBytes());
                }
            }

            // Saving the map to a new location
            if (toPath != Path)
            {
                Path = toPath;

                // Create a new map package
                Container = GlobalFileSystem.CreatePackage(Path, int.MaxValue, entries);
            }

            // Update existing package
            Container.Write(entries);
        }
Example #3
0
 public MiniYaml Save()
 {
     return(FieldSaver.SaveDifferences(this, Default));
 }
Example #4
0
 public List <MiniYamlNode> ToMiniYaml()
 {
     return(Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key),
                                                 FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList());
 }
Example #5
0
        public void Save(string toPath)
        {
            MapFormat = 7;

            var root   = new List <MiniYamlNode>();
            var fields = new[]
            {
                "MapFormat",
                "RequiresMod",
                "Title",
                "Description",
                "Author",
                "Tileset",
                "MapSize",
                "Bounds",
                "Visibility",
                "Type",
            };

            foreach (var field in fields)
            {
                var f = this.GetType().GetField(field);
                if (f.GetValue(this) == null)
                {
                    continue;
                }
                root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
            }

            root.Add(new MiniYamlNode("Videos", FieldSaver.SaveDifferences(Videos, new MapVideos())));

            root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions())));

            root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));

            root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
            root.Add(new MiniYamlNode("Smudges", null, SmudgeDefinitions));
            root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
            root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
            root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
            root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions));
            root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions));
            root.Add(new MiniYamlNode("Music", null, MusicDefinitions));
            root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions));
            root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions));

            var entries = new Dictionary <string, byte[]>();

            entries.Add("map.bin", SaveBinaryData());
            var s = root.WriteToString();

            entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));

            // Add any custom assets
            if (Container != null)
            {
                foreach (var file in Container.AllFileNames())
                {
                    if (file == "map.bin" || file == "map.yaml")
                    {
                        continue;
                    }

                    entries.Add(file, Container.GetContent(file).ReadAllBytes());
                }
            }

            // Saving the map to a new location
            if (toPath != Path || Container == null)
            {
                Path = toPath;

                // Create a new map package
                Container = GlobalFileSystem.CreatePackage(Path, int.MaxValue, entries);
            }

            // Update existing package
            Container.Write(entries);

            // Update UID to match the newly saved data
            Uid = ComputeHash();
        }