Пример #1
0
        public void TestDecodeKaraokeSkin()
        {
            using (var resStream = TestResources.OpenSkinResource("default"))
                using (var stream = new LineBufferedReader(resStream))
                {
                    var decoder = new KaraokeSkinDecoder();
                    var skin    = decoder.Decode(stream);

                    // Checking font decode result
                    var firstDecodedFont = skin.Fonts.FirstOrDefault();
                    Assert.IsNotNull(firstDecodedFont);
                    Assert.AreEqual(firstDecodedFont.Name, "標準配色");

                    // Test back text brush
                    var backTextBrushInfo = firstDecodedFont.BackTextBrushInfo.TextBrush;
                    Assert.AreEqual(backTextBrushInfo.BrushGradients.Count, 3);
                    Assert.AreEqual(backTextBrushInfo.SolidColor, new Color4(255, 255, 255, 255));
                    Assert.AreEqual(backTextBrushInfo.Type, BrushType.Solid);

                    // Test font info
                    var lyricTextFontInfo = firstDecodedFont.LyricTextFontInfo.LyricTextFontInfo;
                    Assert.AreEqual(lyricTextFontInfo.FontName, "游明朝 Demibold");
                    Assert.AreEqual(lyricTextFontInfo.Bold, true);
                    Assert.AreEqual(lyricTextFontInfo.CharSize, 40);
                    Assert.AreEqual(lyricTextFontInfo.EdgeSize, 10);

                    // Checking layout decode result
                    var firstDecodedLayout = skin.Layouts.FirstOrDefault();
                    Assert.NotNull(firstDecodedLayout);
                    Assert.AreEqual(firstDecodedLayout.Name, "下-1");
                    Assert.AreEqual(firstDecodedLayout.Alignment, Anchor.BottomRight);
                    Assert.AreEqual(firstDecodedLayout.HorizontalMargin, 30);
                    Assert.AreEqual(firstDecodedLayout.VerticalMargin, 45);
                    Assert.AreEqual(firstDecodedLayout.Continuous, false);
                    Assert.AreEqual(firstDecodedLayout.SmartHorizon, KaraokeTextSmartHorizon.Multi);
                    Assert.AreEqual(firstDecodedLayout.LyricsInterval, 4);
                    Assert.AreEqual(firstDecodedLayout.RubyInterval, 2);
                    Assert.AreEqual(firstDecodedLayout.RubyAlignment, LyricTextAlignment.Auto);
                    Assert.AreEqual(firstDecodedLayout.RomajiAlignment, LyricTextAlignment.Auto);
                    Assert.AreEqual(firstDecodedLayout.RubyMargin, 4);
                    Assert.AreEqual(firstDecodedLayout.RomajiMargin, 0);

                    // Checking note decode result
                    var firstDecodedNoteSkin = skin.NoteSkins.FirstOrDefault();
                    Assert.NotNull(firstDecodedNoteSkin);
                    Assert.AreEqual(firstDecodedNoteSkin.Name, "Note-1");
                    Assert.AreEqual(firstDecodedNoteSkin.NoteColor, new Color4(68, 170, 221, 255));
                    Assert.AreEqual(firstDecodedNoteSkin.BlinkColor, new Color4(255, 102, 170, 255));
                    Assert.AreEqual(firstDecodedNoteSkin.TextColor, new Color4(255, 255, 255, 255));
                    Assert.AreEqual(firstDecodedNoteSkin.BoldText, true);

                    // Checking singer decode result
                    var firstDecodedSinger = skin.Singers.FirstOrDefault();
                    Assert.NotNull(firstDecodedSinger);
                    Assert.AreEqual(firstDecodedSinger.Name, "Singer-1");
                    Assert.AreEqual(firstDecodedSinger.Romaji, "Singer-1");
                    Assert.AreEqual(firstDecodedSinger.EnglishName, "Singer-1");
                    Assert.AreEqual(firstDecodedSinger.Color, new Color4(255, 128, 128, 255));
                }
        }
Пример #2
0
        private static KaraokeSkin decode(string filename, out KaraokeSkin encoded)
        {
            using (var stream = TestResources.OpenSkinResource(filename))
                using (var sr = new LineBufferedReader(stream))
                {
                    // Read file and decode to file
                    var legacyDecoded = new KaraokeSkinDecoder().Decode(sr);

                    using (var ms = new MemoryStream())
                        using (var sw = new StreamWriter(ms))
                            using (var sr2 = new LineBufferedReader(ms))
                            {
                                // Then encode file to stream
                                var encodeResult = new KaraokeSkinEncoder().Encode(legacyDecoded);
                                sw.WriteLine(encodeResult);
                                sw.Flush();

                                ms.Position = 0;

                                // Decode result from stream
                                encoded = new KaraokeSkinDecoder().Decode(sr2);
                                return(legacyDecoded);
                            }
                }
        }