protected override void ParseStreamInto(LineBufferedReader stream, Beatmap output) { // Clear all hitobjects output.HitObjects.Clear(); var lyricText = stream.ReadToEnd(); var result = new LrcParser().Decode(lyricText); // Convert line for (int i = 0; i < result.Lines.Length; i++) { // Empty line should not be imported var line = result.Lines[i]; if (string.IsNullOrEmpty(line.Text)) { continue; } try { // todo : check list ls sorted by time. var lrcTimeTag = line.TimeTags; var timeTags = line.TimeTags.Where(x => x.Check).ToDictionary(k => { var index = (int)Math.Ceiling((double)(Array.IndexOf(lrcTimeTag, k) - 1) / 2); var state = (Array.IndexOf(lrcTimeTag, k) - 1) % 2 == 0 ? TextIndex.IndexState.Start : TextIndex.IndexState.End; return(new TextIndex(index, state)); }, v => (double)v.Time); var startTime = timeTags.FirstOrDefault(x => x.Value > 0).Value; var duration = timeTags.LastOrDefault(x => x.Value > 0).Value - startTime; var lyric = new Lyric { Order = output.HitObjects.Count + 1, // should create default order. Text = line.Text, // Start time and end time should be re-assigned StartTime = startTime, Duration = duration, TimeTags = TimeTagsUtils.ToTimeTagList(timeTags), RubyTags = result.QueryRubies(line.Text).Select(ruby => new RubyTag { Text = ruby.Ruby.Ruby, StartIndex = ruby.StartIndex, EndIndex = ruby.EndIndex }).ToArray() }; lyric.InitialWorkingTime(); output.HitObjects.Add(lyric); } catch (Exception ex) { var message = $"Parsing lyric '{line.Text}' got error in line:{i}" + "Please check time tag should be ordered and not duplicated." + "Then re-import again."; throw new FormatException(message, ex); } } }
protected override void ParseStreamInto(LineBufferedReader stream, Beatmap output) { stream.ReadToEnd().DeserializeInto(output); foreach (var hitObject in output.HitObjects) { hitObject.ApplyDefaults(output.ControlPointInfo, output.BeatmapInfo.BaseDifficulty); } }
public void TestReadToEndNoPeeks() { const string contents = "first line\r\nsecond line"; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents))) using (var bufferedReader = new LineBufferedReader(stream)) { Assert.AreEqual(contents, bufferedReader.ReadToEnd()); } }
protected override void ParseStreamInto(LineBufferedReader stream, KaraokeSkin output) { var skinText = stream.ReadToEnd(); var result = skinText.Deserialize <KaraokeSkin>(); // Copy property output.Fonts = result.Fonts; output.Layouts = result.Layouts; output.NoteSkins = result.NoteSkins; output.Singers = result.Singers; }
public void TestReadToEndAfterReadsAndPeeks() { const string contents = "this line is gone\rthis one shouldn't be\r\nthese ones\ndefinitely not"; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents))) using (var bufferedReader = new LineBufferedReader(stream)) { Assert.AreEqual("this line is gone", bufferedReader.ReadLine()); Assert.AreEqual("this one shouldn't be", bufferedReader.PeekLine()); string[] endingLines = bufferedReader.ReadToEnd().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(3, endingLines.Length); Assert.AreEqual("this one shouldn't be", endingLines[0]); Assert.AreEqual("these ones", endingLines[1]); Assert.AreEqual("definitely not", endingLines[2]); } }
public void TestReadToEndAfterReadsAndPeeks() { const string contents = @"this line is gone this one shouldn't be these ones definitely not"; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents))) using (var bufferedReader = new LineBufferedReader(stream)) { Assert.AreEqual("this line is gone", bufferedReader.ReadLine()); Assert.AreEqual("this one shouldn't be", bufferedReader.PeekLine()); const string ending = @"this one shouldn't be these ones definitely not"; Assert.AreEqual(ending, bufferedReader.ReadToEnd()); } }
protected override void ParseStreamInto(LineBufferedReader stream, Beatmap output) { var convertor = new List <JsonConverter> { new CultureInfoConverter(), new RomajiTagConverter(), new RubyTagConverter(), new TimeTagConverter(), new ToneConverter(), }; var globalSetting = JsonSerializableExtensions.CreateGlobalSettings(); convertor.AddRange(globalSetting.Converters); globalSetting.Converters = convertor.ToArray(); // create id if object is by reference. globalSetting.PreserveReferencesHandling = PreserveReferencesHandling.Objects; // replace string stream.ReadToEnd().DeserializeInto(output); JsonConvert.PopulateObject(stream.ReadToEnd(), output, globalSetting); base.ParseStreamInto(stream, output); }
protected override void ParseStreamInto(LineBufferedReader stream, KaraokeSkin output) { Project nicoKaraProject; using (TextReader sr = new StringReader(stream.ReadToEnd())) { nicoKaraProject = new Parser().Deserialize(sr); } // Clean-up layout output.Layouts = new List <Skinning.Components.KaraokeLayout>(); foreach (var karaokeLayout in nicoKaraProject.KaraokeLayouts) { Enum.TryParse(karaokeLayout.SmartHorizon.ToString(), out KaraokeTextSmartHorizon smartHorizon); Enum.TryParse(karaokeLayout.RubyAlignment.ToString(), out LyricTextAlignment rubyAlignment); output.Layouts.Add(new Skinning.Components.KaraokeLayout { Name = karaokeLayout.Name, Alignment = convertAnchor(karaokeLayout.HorizontalAlignment, karaokeLayout.VerticalAlignment), HorizontalMargin = karaokeLayout.HorizontalMargin, VerticalMargin = karaokeLayout.VerticalMargin, Continuous = karaokeLayout.Continuous, SmartHorizon = smartHorizon, LyricsInterval = karaokeLayout.LyricsInterval, RubyInterval = karaokeLayout.RubyInterval, RubyAlignment = rubyAlignment, RubyMargin = karaokeLayout.RubyMargin }); } // Clean-up style output.Fonts = new List <KaraokeFont>(); foreach (var nicoKaraFont in nicoKaraProject.KaraokeFonts) { output.Fonts.Add(new KaraokeFont { Name = nicoKaraFont.Name, UseShadow = nicoKaraFont.UseShadow, ShadowOffset = convertShadowSlide(nicoKaraFont.ShadowSlide), FrontTextBrushInfo = new KaraokeFont.TextBrushInfo { TextBrush = convertBrushInfo(nicoKaraFont.BrushInfos[0]), BorderBrush = convertBrushInfo(nicoKaraFont.BrushInfos[1]), ShadowBrush = convertBrushInfo(nicoKaraFont.BrushInfos[2]), }, BackTextBrushInfo = new KaraokeFont.TextBrushInfo { TextBrush = convertBrushInfo(nicoKaraFont.BrushInfos[3]), BorderBrush = convertBrushInfo(nicoKaraFont.BrushInfos[4]), ShadowBrush = convertBrushInfo(nicoKaraFont.BrushInfos[5]), }, LyricTextFontInfo = new KaraokeFont.TextFontInfo { LyricTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[0]), NakaTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[1]), EnTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[2]), }, RubyTextFontInfo = new KaraokeFont.TextFontInfo { LyricTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[3]), NakaTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[4]), EnTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[5]), }, RomajiTextFontInfo = new KaraokeFont.TextFontInfo { // Just copied from ruby setting LyricTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[3]), NakaTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[4]), EnTextFontInfo = convertFontInfo(nicoKaraFont.FontInfos[5]), } }); }