Example #1
0
 public static void SetAdditionalData <T>(string key, T obj)
 {
     if (AdditionalSettings.ContainsKey(key))
     {
         AdditionalSettings.Remove(key);
     }
     AdditionalSettings.Add(key, GenericStructure.Serialise(obj));
 }
Example #2
0
        public void TestObjectSerialisation()
        {
            var thing0 = new SerialisationThing(0);
            var thing1 = new SerialisationThing(1);
            var thing3 = new SerialisationThing(3);

            Assert.AreEqual(GenericStructure.Serialise(thing0).ToString(), GenericStructure.Serialise(GenericStructure.Deserialise <SerialisationThing>(GenericStructure.Serialise(thing0))).ToString());
            Assert.AreEqual(GenericStructure.Serialise(thing1).ToString(), GenericStructure.Serialise(GenericStructure.Deserialise <SerialisationThing>(GenericStructure.Serialise(thing1))).ToString());
            Assert.AreEqual(GenericStructure.Serialise(thing3).ToString(), GenericStructure.Serialise(GenericStructure.Deserialise <SerialisationThing>(GenericStructure.Serialise(thing3))).ToString());
        }
Example #3
0
        public void TestMapObjectSerialisation()
        {
            // compare the *'s:
            // brush -> GS -> string* -> GS -> brush -> GS -> string*

            var brush        = new BlockBrush();
            var b            = brush.Create(new IDGenerator(), new Box(Coordinate.Zero, Coordinate.One * 100), null, 0);
            var serialised   = GenericStructure.Serialise(b);
            var toString     = serialised.ToString();
            var parsed       = GenericStructure.Parse(new StringReader(toString));
            var deserialised = GenericStructure.Deserialise <List <MapObject> >(parsed.First());
            var reserialised = GenericStructure.Serialise(deserialised);

            Assert.AreEqual(serialised.ToString(), reserialised.ToString());
        }
Example #4
0
        public void TestPrimitiveSerialisation()
        {
            Assert.AreEqual(null, GenericStructure.Deserialise <object>(GenericStructure.Serialise(null)));
            Assert.AreEqual(new DateTime(2014, 01, 01), GenericStructure.Deserialise <DateTime>(GenericStructure.Serialise(new DateTime(2014, 01, 01))));
            Assert.AreEqual(10, GenericStructure.Deserialise <int>(GenericStructure.Serialise(10)));
            Assert.AreEqual(10m, GenericStructure.Deserialise <decimal>(GenericStructure.Serialise(10m)));
            Assert.AreEqual(false, GenericStructure.Deserialise <bool>(GenericStructure.Serialise(false)));
            Assert.AreEqual("12345", GenericStructure.Deserialise <string>(GenericStructure.Serialise("12345")));
            Assert.AreEqual(new Coordinate(123, 456, 789.0005m), GenericStructure.Deserialise <Coordinate>(GenericStructure.Serialise(new Coordinate(123, 456, 789.0005m))));
            var dsBox = GenericStructure.Deserialise <Box>(GenericStructure.Serialise(new Box(Coordinate.Zero, Coordinate.One)));

            Assert.AreEqual(Coordinate.Zero, dsBox.Start);
            Assert.AreEqual(Coordinate.One, dsBox.End);
            Assert.AreEqual(Color.FromArgb(255, 255, 0, 0), GenericStructure.Deserialise <Color>(GenericStructure.Serialise(Color.FromArgb(255, 255, 0, 0))));
            Assert.AreEqual(new Plane(Coordinate.UnitZ, 1), GenericStructure.Deserialise <Plane>(GenericStructure.Serialise(new Plane(Coordinate.UnitZ, 1))));
        }
Example #5
0
        public static void Write()
        {
            var newSettings = Serialise.SerialiseSettings().Select(s => new Setting {
                Key = s.Key, Value = s.Value
            });

            Settings.Clear();
            Settings.AddRange(newSettings);

            var root = new GenericStructure("Sledge");

            // Settings
            var settings = new GenericStructure("Settings");

            foreach (var setting in Settings)
            {
                settings.AddProperty(setting.Key, setting.Value);
            }
            root.Children.Add(settings);

            // Recent Files
            var recents = new GenericStructure("RecentFiles");
            var i       = 1;

            foreach (var file in RecentFiles.OrderBy(x => x.Order).Select(x => x.Location).Where(File.Exists))
            {
                recents.AddProperty(i.ToString(CultureInfo.InvariantCulture), file);
                i++;
            }
            root.Children.Add(recents);

            // Games > Fgds/Wads
            foreach (var game in Games)
            {
                var g = new GenericStructure("Game");
                game.Write(g);
                root.Children.Add(g);
            }

            // Builds
            foreach (var build in Builds)
            {
                var b = new GenericStructure("Build");
                build.Write(b);
                root.Children.Add(b);
            }

            // Hotkeys
            Hotkeys = Sledge.Settings.Hotkeys.GetHotkeys().ToList();
            var hotkeys = new GenericStructure("Hotkeys");

            foreach (var g in Hotkeys.GroupBy(x => x.ID))
            {
                var count = 0;
                foreach (var hotkey in g)
                {
                    hotkeys.AddProperty(hotkey.ID + ":" + count, hotkey.HotkeyString);
                    count++;
                }
            }
            root.Children.Add(hotkeys);

            // Additional
            var additional = new GenericStructure("AdditionalSettings");

            foreach (var kv in AdditionalSettings)
            {
                var child = new GenericStructure(kv.Key);
                child.Children.Add(kv.Value);
                additional.Children.Add(child);
            }
            root.Children.Add(additional);

            // Favourite textures
            var favTextures = new GenericStructure("FavouriteTextures");

            favTextures.Children.Add(GenericStructure.Serialise(FavouriteTextureFolders));
            root.Children.Add(favTextures);

            File.WriteAllText(SettingsFile, root.ToString());
        }