Exemplo n.º 1
0
        internal static void Load()
        {
            TomletMain.RegisterMapper(WriteColor, ReadColor);

            FilePath = Path.Combine(Core.FolderPath, "Config.cfg");
            General  = CreateCat <cGeneral>(FilePath, nameof(General));

            bool UseDefault = true;

            if (!string.IsNullOrEmpty(General.Theme) &&
                !General.Theme.Equals("Default") &&
                !General.Theme.Equals("Random"))
            {
                try
                {
                    // To-Do: Sanatize themeName
                    General.Theme = General.Theme
                                    .Replace("\\", "")
                                    .Replace("/", "");

                    ThemePath = Path.Combine(Core.ThemesFolderPath, General.Theme);
                    if (Directory.Exists(ThemePath))
                    {
                        UseDefault = false;
                    }
                    else
                    {
                        throw new DirectoryNotFoundException(ThemePath);
                    }
                }
                catch (Exception ex) { MelonLogger.Error($"Failed to find Start Screen Theme: {ex}"); }
            }

            if (General.Theme.Equals("Random"))
            {
                ThemePath  = UIUtils.RandomFolder(Core.ThemesFolderPath);
                UseDefault = false;
            }

            if (UseDefault)
            {
                General.Theme = "Default";
                ThemePath     = Path.Combine(Core.ThemesFolderPath, General.Theme);
                if (!Directory.Exists(ThemePath))
                {
                    Directory.CreateDirectory(ThemePath);
                }
            }

            MelonLogger.Msg($"Using Start Screen Theme: \"{General.Theme}\"");

            Background   = CreateCat <cBackground>(nameof(Background), true);
            LogoImage    = CreateCat <LogoImageSettings>(nameof(LogoImage), true);
            LoadingImage = CreateCat <LoadingImageSettings>(nameof(LoadingImage), true);
            VersionText  = CreateCat <VersionTextSettings>(nameof(VersionText), true);
            ProgressText = CreateCat <ProgressTextSettings>(nameof(ProgressText), true);
            ProgressBar  = CreateCat <cProgressBar>(nameof(ProgressBar), true);

            MelonPreferences.SaveCategory <cGeneral>(nameof(General), false);
        }
Exemplo n.º 2
0
        public void SimpleCompositeDeserializationWorks()
        {
            var type = TomletMain.To <SimplePrimitiveTestClass>(TestResources.SimplePrimitiveDeserializationTestInput);

            Assert.Equal("Hello, world!", type.MyString);
            Assert.True(Math.Abs(690.42 - type.MyFloat) < 0.01);
            Assert.True(type.MyBool);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 0, 0, DateTimeKind.Utc), type.MyDateTime);
        }
 internal static void RegisterMappers()
 {
     TomletMain.RegisterMapper(WriteColor, ReadColor);
     TomletMain.RegisterMapper(WriteColor32, ReadColor32);
     TomletMain.RegisterMapper(WriteVector2, ReadVector2);
     TomletMain.RegisterMapper(WriteVector3, ReadVector3);
     TomletMain.RegisterMapper(WriteVector4, ReadVector4);
     TomletMain.RegisterMapper(WriteQuaternion, ReadQuaternion);
 }
Exemplo n.º 4
0
        public void DictionaryDeserializationWorks()
        {
            var dict = TomletMain.To <Dictionary <string, string> >(TestResources.SimplePrimitiveDeserializationTestInput);

            Assert.Equal(4, dict.Count);
            Assert.Equal("Hello, world!", dict["MyString"]);
            Assert.Equal("690.42", dict["MyFloat"]);
            Assert.Equal("true", dict["MyBool"]);
            Assert.Equal("1970-01-01T07:00:00", dict["MyDateTime"]);
        }
Exemplo n.º 5
0
        internal static void Load()
        {
            FilePath = Path.Combine(Core.FolderPath, "Config.cfg");
            TomletMain.RegisterMapper(WriteColor, ReadColor);

            General      = CreateCat <cGeneral>(nameof(General));
            Background   = CreateCat <cBackground>(nameof(Background));
            LogoImage    = CreateCat <cLogoImage>(nameof(LogoImage));
            LoadingImage = CreateCat <cLoadingImage>(nameof(LoadingImage));
            VersionText  = CreateCat <cVersionText>(nameof(VersionText));
            ProgressText = CreateCat <cProgressText>(nameof(ProgressText));
            ProgressBar  = CreateCat <cProgressBar>(nameof(ProgressBar));
        }
Exemplo n.º 6
0
        public void SimpleObjectToTomlStringWorks()
        {
            var testObject = new SimplePrimitiveTestClass
            {
                MyBool     = true,
                MyFloat    = 420.69f,
                MyString   = "Hello, world!",
                MyDateTime = new DateTime(1970, 1, 1, 7, 0, 0, DateTimeKind.Utc)
            };

            var serializedForm = TomletMain.TomlStringFrom(testObject);

            Assert.Equal("MyString = \"Hello, world!\"\nMyFloat = 420.69000244140625\nMyBool = true\nMyDateTime = 1970-01-01T07:00:00", serializedForm.Trim());
        }
Exemplo n.º 7
0
        public void SerializingSimpleObjectAndDeserializingAgainGivesEquivalentObject()
        {
            var testObject = new SimplePrimitiveTestClass
            {
                MyBool     = true,
                MyFloat    = 420.69f,
                MyString   = "Hello, world!",
                MyDateTime = new DateTime(1970, 1, 1, 7, 0, 0, DateTimeKind.Utc)
            };

            var serializedForm = TomletMain.TomlStringFrom(testObject);

            var deserializedAgain = TomletMain.To <SimplePrimitiveTestClass>(serializedForm);

            Assert.Equal(testObject, deserializedAgain);
        }
Exemplo n.º 8
0
        public static void SimpleObjectToTomlDocWorks()
        {
            var testObject = new SimplePrimitiveTestClass
            {
                MyBool     = true,
                MyFloat    = 420.69f,
                MyString   = "Hello, world!",
                MyDateTime = new DateTime(1970, 1, 1, 7, 0, 0, DateTimeKind.Utc)
            };

            var tomlDoc = TomletMain.DocumentFrom(testObject);

            Assert.Equal(4, tomlDoc.Entries.Count);
            Assert.True(tomlDoc.GetBoolean("MyBool"));
            Assert.True(Math.Abs(tomlDoc.GetFloat("MyFloat") - 420.69) < 0.01);
            Assert.Equal("Hello, world!", tomlDoc.GetString("MyString"));
            Assert.Equal("1970-01-01T07:00:00", tomlDoc.GetValue("MyDateTime").StringValue);
        }
        public void ComplexSerializationWorks()
        {
            var testClass = new ComplexTestClass
            {
                TestString = "Hello world, how are you?",
                ClassOnes  =
                {
                    new ComplexTestClass.SubClassOne {
                        SubKeyOne = "Hello"
                    },
                    new ComplexTestClass.SubClassOne {
                        SubKeyOne = "World"
                    },
                    new ComplexTestClass.SubClassOne {
                        SubKeyOne = "How"
                    },
                    new ComplexTestClass.SubClassOne {
                        SubKeyOne = "Are"
                    },
                    new ComplexTestClass.SubClassOne {
                        SubKeyOne = "You"
                    },
                },
                SC2 = new ComplexTestClass.SubClassTwo {
                    SubKeyOne   = "Hello world, how are you?",
                    SubKeyTwo   = DateTimeOffset.Now,
                    SubKeyThree = 17,
                    SubKeyFour  = 2.34f,
                }
            };

            var tomlString = TomletMain.TomlStringFrom(testClass);

            _testOutputHelper.WriteLine("Got TOML string:\n" + tomlString);

            var deserializedAgain = TomletMain.To <ComplexTestClass>(tomlString);

            Assert.Equal(testClass, deserializedAgain);
        }
Exemplo n.º 10
0
 public T FromToml <T>(TomlValue value) => TomletMain.To <T>(value);
Exemplo n.º 11
0
 public TomlValue ToToml <T>(T value) => TomletMain.ValueFrom(value);
Exemplo n.º 12
0
 public TomlArray WriteList <T>(List <T> value) => (TomlArray)TomletMain.ValueFrom(value);
Exemplo n.º 13
0
 public List <T> ReadList <T>(TomlValue value) => TomletMain.To <List <T> >(value);
Exemplo n.º 14
0
 public TomlArray WriteArray <T>(T[] value) => (TomlArray)TomletMain.ValueFrom(value);
Exemplo n.º 15
0
 public T[] ReadArray <T>(TomlValue value) => TomletMain.To <T[]>(value);