Пример #1
0
 private static void DeserializeXml(string inputPath, string outputPath)
 {
     Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}.numatb...");
     using (var reader = new StringReader(File.ReadAllText(inputPath)))
     {
         var matl = MatlSerialization.DeserializeMatl(reader);
         Ssbh.TrySaveSsbhFile(outputPath, matl);
     }
 }
Пример #2
0
        public void EmptyMatl()
        {
            var source = @"<?xml version=""1.0"" encoding=""utf-16""?>
<MaterialLibrary xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />";

            var reader = new StringReader(source);
            var matl   = MatlSerialization.DeserializeMatl(reader);

            Assert.AreEqual(0, matl.Entries.Length);
        }
Пример #3
0
        public void EmptyMatl()
        {
            var matl   = new Matl();
            var writer = new StringWriter();

            MatlSerialization.SerializeMatl(writer, matl);
            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<MaterialLibrary xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />";

            Assert.AreEqual(expected, writer.ToString());
        }
Пример #4
0
 internal void ExportMatlToXml(string outputPath)
 {
     if (CurrentMaterialCollection != null)
     {
         var matl = rnumdls.SingleOrDefault(r => r.Item1 == CurrentMaterialCollection.Name).Item2.Matl;
         if (matl != null)
         {
             using var writer = new StringWriter();
             MatlSerialization.SerializeMatl(writer, matl);
             File.WriteAllText(outputPath, writer.ToString());
         }
     }
 }
Пример #5
0
        public void SerializeMarioC00()
        {
            var source = TestResources.ReadResourceTextFile("SsbhLib.Test.MatlSerializationTests.marioc00.xml");

            var reader = new StringReader(source);
            var matl   = MatlSerialization.DeserializeMatl(reader);

            var writer = new StringWriter();

            MatlSerialization.SerializeMatl(writer, matl);

            // Test 1:1 deserialize/serialize
            Assert.AreEqual(source, writer.ToString());
        }
Пример #6
0
 private static Matl?LoadPresets()
 {
     // TODO: This may fail to read the file successfully.
     try
     {
         using var reader = new StringReader(File.ReadAllText("MaterialPresets/MaterialPresets.xml"));
         return(MatlSerialization.DeserializeMatl(reader));
     }
     catch (Exception)
     {
         // TODO: Log the error
         return(null);
     }
 }
Пример #7
0
 private static void SerializeMatl(string inputPath, string outputPath)
 {
     Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}...");
     if (Ssbh.TryParseSsbhFile(inputPath, out Matl matlFile))
     {
         using (var writer = new StringWriter())
         {
             MatlSerialization.SerializeMatl(writer, matlFile);
             File.WriteAllText(outputPath, writer.ToString());
         }
     }
     else
     {
         Console.WriteLine("Error reading matl file");
     }
 }
Пример #8
0
        public void DeserializeMarioC00()
        {
            var source = TestResources.ReadResourceTextFile("SsbhLib.Test.MatlSerializationTests.marioc00.xml");

            var reader = new StringReader(source);
            var matl   = MatlSerialization.DeserializeMatl(reader);

            Assert.AreEqual(12, matl.Entries.Length);
            var entry = matl.Entries[5];

            Assert.AreEqual("SFX_PBS_010000001800830d_opaque", entry.ShaderLabel);
            Assert.AreEqual("EyeRD", entry.MaterialLabel);

            Assert.AreEqual(20, entry.Attributes.Length);
            Assert.AreEqual(false, entry.Attributes[3].DataObject);
        }