public ComboColourStudioView() { InitializeComponent(); DataContext = new ComboColourStudioVm(); Width = MainWindow.AppWindow.content_views.Width; Height = MainWindow.AppWindow.content_views.Height; ProjectManager.LoadProject(this, message: false); }
private static string Export_ComboColours(ComboColourStudioVm arg, BackgroundWorker worker, DoWorkEventArgs _) { var paths = arg.ExportPath.Split('|'); var mapsDone = 0; var orderedColourPoints = arg.Project.ColourPoints.OrderBy(o => o.Time).ToList(); var orderedComboColours = arg.Project.ComboColours.OrderBy(o => o.Name).ToList(); var editorRead = EditorReaderStuff.TryGetFullEditorReader(out var reader); foreach (var path in paths) { var editor = EditorReaderStuff.GetBeatmapEditor(path, reader, editorRead); var beatmap = editor.Beatmap; // Setting the combo colours beatmap.ComboColours = new List <ComboColour>(arg.Project.ComboColours); // Setting the combo skips if (beatmap.HitObjects.Count > 0 && orderedColourPoints.Count > 0) { int lastColourPointColourIndex = -1; var lastColourPoint = orderedColourPoints[0]; int lastColourIndex = 0; var exceptions = new List <ColourPoint>(); foreach (var newCombo in beatmap.HitObjects.Where(o => o.ActualNewCombo && !o.IsSpinner)) { int comboLength = GetComboLength(newCombo, beatmap.HitObjects); //Console.WriteLine(comboLength); // Get the colour point for this new combo var colourPoint = GetColourPoint(orderedColourPoints, newCombo.Time, exceptions, comboLength <= arg.Project.MaxBurstLength); var colourSequence = colourPoint.ColourSequence.ToList(); // Add the colour point to the exceptions so it doesnt get used again if (colourPoint.Mode == ColourPointMode.Burst) { exceptions.Add(colourPoint); } // Get the last colour index on the sequence of this colour point lastColourPointColourIndex = lastColourPointColourIndex == -1 || lastColourPoint.Equals(colourPoint) ? lastColourPointColourIndex : colourSequence.FindIndex(o => o.Name == orderedComboColours[lastColourIndex].Name); // Get the next colour index on this colour point // Check if colourSequence count is 0 to prevent division by 0 var colourPointColourIndex = lastColourPointColourIndex == -1 || colourSequence.Count == 0 ? 0 : lastColourPoint.Equals(colourPoint) ? MathHelper.Mod(lastColourPointColourIndex + 1, colourSequence.Count) : // If the colour point changed try going back to index 0 lastColourPointColourIndex == 0 && colourSequence.Count > 1 ? 1 : 0; //Console.WriteLine("colourPointColourIndex: " + colourPointColourIndex); //Console.WriteLine("colourPointColour: " + colourPoint.ColourSequence[colourPointColourIndex].Name); // Find the combo index of the chosen colour in the sequence // Check if the colourSequence count is 0 to prevent an out-of-range exception var colourIndex = colourSequence.Count == 0 ? MathHelper.Mod(lastColourIndex + 1, orderedComboColours.Count) : orderedComboColours.FindIndex(o => o.Name == colourSequence[colourPointColourIndex].Name); if (colourIndex == -1) { throw new ArgumentException($"Can not use colour {colourSequence[colourPointColourIndex].Name} of colour point at offset {colourPoint.Time} because it does not exist in the combo colours."); } //Console.WriteLine("colourIndex: " + colourIndex); var comboIncrease = MathHelper.Mod(colourIndex - lastColourIndex, arg.Project.ComboColours.Count); // Do -1 combo skip since it always does +1 combo colour for each new combo which is not on a spinner newCombo.ComboSkip = MathHelper.Mod(comboIncrease - 1, arg.Project.ComboColours.Count); // Set new combo to true for the case this is the first object and new combo is false if (!newCombo.NewCombo && newCombo.ComboSkip != 0) { newCombo.NewCombo = true; } //Console.WriteLine("comboSkip: " + newCombo.ComboSkip); lastColourPointColourIndex = colourPointColourIndex; lastColourPoint = colourPoint; lastColourIndex = colourIndex; } } // Save the file editor.SaveFile(); // Update progressbar if (worker != null && worker.WorkerReportsProgress) { worker.ReportProgress(++mapsDone * 100 / paths.Length); } } // Make an accurate message var message = $"Successfully exported metadata to {mapsDone} {(mapsDone == 1 ? "beatmap" : "beatmaps")}!"; return(message); }