Skip to content

Commit

Permalink
Prompt for missing hold ends instead of exploding
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymonf committed Nov 14, 2023
1 parent 866b444 commit b464f01
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
31 changes: 29 additions & 2 deletions BAKKA_Editor/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,21 @@ public bool ParseFile(Stream? stream)
noteTemp.Position = Convert.ToInt32(parsed[5], _defaultParsingCulture);
noteTemp.Size = Convert.ToInt32(parsed[6], _defaultParsingCulture);
noteTemp.HoldChange = Convert.ToBoolean(Convert.ToInt32(parsed[7], _defaultParsingCulture));
if (noteTemp.NoteType == NoteType.MaskAdd || noteTemp.NoteType == NoteType.MaskRemove)
if (noteTemp.NoteType is NoteType.MaskAdd or NoteType.MaskRemove)
{
noteTemp.MaskFill = (MaskType) Convert.ToInt32(parsed[8], _defaultParsingCulture);
}
else if (noteTemp.NoteType == NoteType.HoldStartNoBonus ||
noteTemp.NoteType == NoteType.HoldJoint ||
noteTemp.NoteType == NoteType.HoldStartBonusFlair)
refByLine[lineNum] = Convert.ToInt32(parsed[8], _defaultParsingCulture);
{
// If someone saves without the hold end, we won't have index 8 (next note ref ID)
if (parsed.Length >= 9)
{
refByLine[lineNum] = Convert.ToInt32(parsed[8], _defaultParsingCulture);
}
}

Notes.Add(noteTemp);
notesByLine[lineNum] = Notes.Last();
break;
Expand Down Expand Up @@ -519,4 +528,22 @@ public void FixInvalidPositionNotes()
}
}
}

/// <summary>
/// Get the measures where the chart has missing hold end notes
/// </summary>
public List<float> GetMissingHoldEndMeasures()
{
var missingHoldEndMeasures = new List<float>();

foreach (var note in Notes)
{
if (note is {NoteType: NoteType.HoldJoint, NextReferencedNote: null})
{
missingHoldEndMeasures.Add(note.BeatInfo.MeasureDecimal);
}
}

return missingHoldEndMeasures;
}
}
81 changes: 80 additions & 1 deletion BAKKA_Editor/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public async Task NewMenuItem_OnClick()
if (!await PromptSave())
return;

// reset to default note type UI state
ResetToDefaultNoteTypeUi();

chart = new Chart();
isNewFile = true;
isRecoveredFile = false;
Expand All @@ -192,6 +195,14 @@ public async Task NewMenuItem_OnClick()
}
}

private void ResetToDefaultNoteTypeUi()
{
noBonusRadio.IsChecked = true;
SetNonHoldButtonState(true);
_vm.EndHoldChecked = false;
tapButton_Click(this, new RoutedEventArgs());
}

public async Task OpenChartSettings_OnClick()
{
await ShowInitialSettings();
Expand Down Expand Up @@ -832,7 +843,7 @@ private async Task<bool> OpenFile()
isNewFile = false;
SetText();
skCircleView.RenderEngine.UpdateHiSpeed(chart, userSettings.ViewSettings.HispeedSetting); // initialize hispeed on song load

// early hold baking algorithm can cause negative position notes
// they render fine in the editor, but cause distorted polygons to render in the game
if (chart.HasInvalidPositionNotes())
Expand All @@ -852,6 +863,22 @@ private async Task<bool> OpenFile()
}
});
}

var missingHoldEndMeasures = chart.GetMissingHoldEndMeasures();
if (missingHoldEndMeasures.Count > 0)
{
Dispatcher.UIThread.Post(
async () =>
{
var notice = "The following hold joints are missing hold ends:\n\n";
notice += GetMissingHoldEndMeasureText(missingHoldEndMeasures);
notice += "\nHold ends are required for hold joints to function properly. " +
"""To fix a broken joint, scroll to the hold joint without an end note and click "Jump To Nearest Note" to select the joint.""";
await ShowBlockingMessageBox("Missing Hold Ends", notice);
});
}

Dispatcher.UIThread.Post(() => ResetToDefaultNoteTypeUi());
}

if (IsDesktop)
Expand Down Expand Up @@ -2050,6 +2077,28 @@ public async Task ShowInitialSettings()

private async Task<bool> SaveFile(bool prompt = true)
{
// check if we are inserting a hold
if (CurrentlyInsertingHold())
{
var shouldSave = await ShowBlockingMessageBox("Save Warning",
"You are currently inserting a hold. Do you wish to save anyway?\n\nPlease note that this chart will cause the game to crash in its current state, and you will need to manually fix the hold upon loading the chart.", MessageBoxType.YesNo);
if (shouldSave == ContentDialogResult.None)
return false;
}

// check for missing hold ends
var missingHoldEndMeasures = chart.GetMissingHoldEndMeasures();
if (missingHoldEndMeasures.Count > 0)
{
var notice = "The following hold joints are missing hold ends:\n\n";
notice += GetMissingHoldEndMeasureText(missingHoldEndMeasures);
notice += "\nHold ends are required for hold joints to function properly. Do you wish to save anyway?\n\n" +
"""Please note that this chart will cause the game to crash in its current state. To fix a broken joint, scroll to the hold joint without an end note and click "Jump To Nearest Note" to select the joint.""";
var shouldSave = await ShowBlockingMessageBox("Save Warning", notice, MessageBoxType.YesNo);
if (shouldSave == ContentDialogResult.None)
return false;
}

// check if we have an end of chart note
var hasEndOfChart = chart.Notes.Any(x => x.NoteType == NoteType.EndOfChart);
if (!hasEndOfChart)
Expand Down Expand Up @@ -2367,6 +2416,18 @@ private void NoteJumpToCurrTimeButton_Click(object? sender, RoutedEventArgs e)
if (note != null) selectedNoteIndex = chart.Notes.IndexOf(note);
}

// temporary feature to edit holds without an end
if (note != null)
{
if (currentNoteType != NoteType.HoldJoint &&
note is {IsHold: true, NoteType: NoteType.HoldJoint, NextReferencedNote: null})
{
SetSelectedObject(NoteType.HoldJoint);
lastNote = note; // ?
SetNonHoldButtonState(false);
}
}

UpdateNoteLabels();
}

Expand Down Expand Up @@ -3416,4 +3477,22 @@ public async Task OpenSettings_OnClick()
appSettingsVm.Dialog = null;
});
}

bool CurrentlyInsertingHold()
{
return currentNoteType is NoteType.HoldJoint or NoteType.HoldEnd;
}

private string GetMissingHoldEndMeasureText(List<float> missingHoldEndMeasures)
{
var result = "";
foreach (var measure in missingHoldEndMeasures)
{
var beatInfo = new BeatInfo(measure);
var quant = Utils.GetQuantization(beatInfo.Beat, 16);
result += $"* Measure {beatInfo.Measure} Beat {quant.Item1} / {quant.Item2}\n";
}

return result;
}
}

0 comments on commit b464f01

Please sign in to comment.