/// <summary> /// Doesn't run in the main thread /// </summary> public void ExportToOsb(bool exportOsb = true) { if (IsDisposed) { throw new ObjectDisposedException(nameof(Project)); } string osuPath = null, osbPath = null; List <EditorStoryboardLayer> localLayers = null; Program.RunMainThread(() => { osuPath = MainBeatmap.Path; osbPath = OsbPath; if (!OwnsOsb && File.Exists(osbPath)) { File.Copy(osbPath, $"{osbPath}.bak"); } OwnsOsb = true; localLayers = new List <EditorStoryboardLayer>(LayerManager.FindLayers(l => l.Visible)); }); var exportSettings = new ExportSettings(); var usesOverlayLayer = localLayers.Any(l => l.OsbLayer == OsbLayer.Overlay); if (!string.IsNullOrEmpty(osuPath)) { Debug.Print($"Exporting diff specific events to {osuPath}"); using (var stream = new SafeWriteStream(osuPath)) using (var writer = new StreamWriter(stream, Encoding.UTF8)) using (var fileStream = new FileStream(osuPath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new StreamReader(fileStream, Encoding.UTF8)) { string line; var inEvents = false; var inStoryboard = false; while ((line = reader.ReadLine()) != null) { var trimmedLine = line.Trim(); if (!inEvents && trimmedLine == "[Events]") { inEvents = true; } else if (trimmedLine.Length == 0) { inEvents = false; } if (inEvents) { if (trimmedLine.StartsWith("//Storyboard Layer")) { if (!inStoryboard) { foreach (var osbLayer in OsbLayers) { if (osbLayer == OsbLayer.Overlay && !usesOverlayLayer) { continue; } writer.WriteLine($"//Storyboard Layer {(int)osbLayer} ({osbLayer})"); foreach (var layer in localLayers) { if (layer.OsbLayer == osbLayer && layer.DiffSpecific) { layer.WriteOsbSprites(writer, exportSettings); } } } inStoryboard = true; } } else if (inStoryboard && trimmedLine.StartsWith("//")) { inStoryboard = false; } if (inStoryboard) { continue; } } writer.WriteLine(line); } stream.Commit(); } } if (exportOsb) { Debug.Print($"Exporting osb to {osbPath}"); using (var stream = new SafeWriteStream(osbPath)) using (var writer = new StreamWriter(stream, Encoding.UTF8)) { writer.WriteLine("[Events]"); writer.WriteLine("//Background and Video events"); foreach (var osbLayer in OsbLayers) { if (osbLayer == OsbLayer.Overlay && !usesOverlayLayer) { continue; } writer.WriteLine($"//Storyboard Layer {(int)osbLayer} ({osbLayer})"); foreach (var layer in localLayers) { if (layer.OsbLayer == osbLayer && !layer.DiffSpecific) { layer.WriteOsbSprites(writer, exportSettings); } } } writer.WriteLine("//Storyboard Sound Samples"); stream.Commit(); } } }
public void TriggerEvents(double startTime, double endTime) { LayerManager.TriggerEvents(startTime, endTime); }