Skip to content

Commit

Permalink
Merge pull request #2305 from andy840119/remove-stage-info-from-beatmap
Browse files Browse the repository at this point in the history
Remove stage info from beatmap.
  • Loading branch information
andy840119 authored Nov 30, 2024
2 parents 3a77aed + 2f0203f commit 6ceeb9d
Show file tree
Hide file tree
Showing 22 changed files with 284 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ protected void AssertStatus()
// also, technically should not call the change handler if there's no possible to change the properties.
AssertTransactionOnlyTriggerOnce();

// We should make sure that the stage info is in the latest state.
// Should trigger the beatmap editor to run the beatmap processor if not the latest.
AssertCalculatedPropertyInStageInfoValid();

// We should make sure that if the working property is changed by the change handler.
// Should trigger the beatmap editor to run the beatmap processor to re-fill the working property.
AssertWorkingPropertyInHitObjectValid();
Expand All @@ -209,21 +205,6 @@ protected void AssertTransactionOnlyTriggerOnce()
});
}

protected void AssertCalculatedPropertyInStageInfoValid()
{
AddWaitStep("Waiting for working property being re-filled in the beatmap processor.", 1);
AddAssert("Check if working property in the hit object is valid", () =>
{
var editorBeatmap = Dependencies.Get<EditorBeatmap>();
var karaokeBeatmap = EditorBeatmapUtils.GetPlayableBeatmap(editorBeatmap);
if (karaokeBeatmap.CurrentStageInfo is IHasCalculatedProperty calculatedProperty)
return calculatedProperty.IsUpdated();

// ignore check if current stage info no need to calculate the property.
return true;
});
}

protected void AssertWorkingPropertyInHitObjectValid()
{
AddWaitStep("Waiting for working property being re-filled in the beatmap processor.", 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Stages.Infos;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Stages;

public abstract partial class BaseStageInfoChangeHandlerTest<TChangeHandler> : BaseChangeHandlerTest<TChangeHandler>
where TChangeHandler : Component
{
protected virtual void SetUpStageInfo<TStageInfo>(Action<TStageInfo>? action = null)
=> throw new NotImplementedException();

public void AssertStageInfos(Action<IList<StageInfo>> assert)
=> throw new NotImplementedException();

public void AssertStageInfo<TStageInfo>(Action<TStageInfo> assert) where TStageInfo: StageInfo
=> throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Stages;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Stages.Infos;
using osu.Game.Rulesets.Karaoke.Stages.Infos.Classic;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Stages;

public partial class ClassicStageChangeHandlerTest : BaseChangeHandlerTest<ClassicStageChangeHandler>
[Ignore("Ignore all stage-related change handler test until able to edit the stage info.")]
public partial class ClassicStageChangeHandlerTest : BaseStageInfoChangeHandlerTest<ClassicStageChangeHandler>
{
#region Layout definition

[Test]
public void TestEditLayoutDefinition()
{
SetUpStageInfo<ClassicStageInfo>();

TriggerHandlerChanged(c =>
{
c.EditLayoutDefinition(x =>
Expand All @@ -28,13 +27,12 @@ public void TestEditLayoutDefinition()
});
});

AssertKaraokeBeatmap(karaokeBeatmap =>
AssertStageInfo<ClassicStageInfo>(stageInfo =>
{
var classicStageInfo = getClassicStageInfo(karaokeBeatmap);
Assert.IsNotNull(classicStageInfo);
Assert.IsNotNull(stageInfo);

// assert definition.
var definition = classicStageInfo.StageDefinition;
var definition = stageInfo.StageDefinition;
Assert.AreEqual(12, definition.LineHeight);
});
}
Expand All @@ -46,6 +44,8 @@ public void TestEditLayoutDefinition()
[Test]
public void TestAddTimingPoint()
{
SetUpStageInfo<ClassicStageInfo>();

TriggerHandlerChanged(c =>
{
c.AddTimingPoint(x =>
Expand All @@ -54,9 +54,9 @@ public void TestAddTimingPoint()
});
});

AssertKaraokeBeatmap(karaokeBeatmap =>
AssertStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
Assert.IsNotNull(timingInfo);

// assert timing.
Expand All @@ -71,9 +71,9 @@ public void TestRemoveTimingPoint()
{
ClassicLyricTimingPoint removedTimingPoint = null!;

SetUpKaraokeBeatmap(karaokeBeatmap =>
SetUpStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
timingInfo.Timings.Add(new ClassicLyricTimingPoint
{
Time = 1000,
Expand All @@ -90,9 +90,9 @@ public void TestRemoveTimingPoint()
c.RemoveTimingPoint(removedTimingPoint);
});

AssertKaraokeBeatmap(karaokeBeatmap =>
AssertStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
Assert.IsNotNull(timingInfo);

// assert timing.
Expand All @@ -107,9 +107,9 @@ public void TestRemoveRangeOfTimingPoints()
{
ClassicLyricTimingPoint removedTimingPoint = null!;

SetUpKaraokeBeatmap(karaokeBeatmap =>
SetUpStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
timingInfo.Timings.Add(new ClassicLyricTimingPoint
{
Time = 1000,
Expand All @@ -126,9 +126,9 @@ public void TestRemoveRangeOfTimingPoints()
c.RemoveRangeOfTimingPoints(new[] { removedTimingPoint });
});

AssertKaraokeBeatmap(karaokeBeatmap =>
AssertStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
Assert.IsNotNull(timingInfo);

// assert timing.
Expand All @@ -144,9 +144,9 @@ public void TestShiftingTimingPoints()
ClassicLyricTimingPoint shiftingTimingPoint1 = null!;
ClassicLyricTimingPoint shiftingTimingPoint2 = null!;

SetUpKaraokeBeatmap(karaokeBeatmap =>
SetUpStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
timingInfo.Timings.Add(shiftingTimingPoint1 = new ClassicLyricTimingPoint
{
Time = 1000,
Expand All @@ -163,9 +163,9 @@ public void TestShiftingTimingPoints()
c.ShiftingTimingPoints(new[] { shiftingTimingPoint1, shiftingTimingPoint2 }, 100);
});

AssertKaraokeBeatmap(karaokeBeatmap =>
AssertStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
Assert.IsNotNull(timingInfo);

// assert timing.
Expand All @@ -181,9 +181,9 @@ public void TestAddLyricIntoTimingPoint()
{
ClassicLyricTimingPoint timingPoint = null!;

SetUpKaraokeBeatmap(karaokeBeatmap =>
SetUpStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
timingInfo.Timings.Add(timingPoint = new ClassicLyricTimingPoint
{
Time = 1000,
Expand All @@ -201,9 +201,9 @@ public void TestAddLyricIntoTimingPoint()
c.AddLyricIntoTimingPoint(timingPoint);
});

AssertKaraokeBeatmap(karaokeBeatmap =>
AssertStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
Assert.IsNotNull(timingInfo);

// assert mapping status.
Expand All @@ -223,9 +223,9 @@ public void TestRemoveLyricFromTimingPoint()
PrepareHitObject(() => lyric1 = new Lyric());
PrepareHitObject(() => lyric2 = new Lyric(), false);

SetUpKaraokeBeatmap(karaokeBeatmap =>
SetUpStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
timingInfo.Timings.Add(timingPoint = new ClassicLyricTimingPoint
{
Time = 1000,
Expand All @@ -239,9 +239,9 @@ public void TestRemoveLyricFromTimingPoint()
c.RemoveLyricFromTimingPoint(timingPoint);
});

AssertKaraokeBeatmap(karaokeBeatmap =>
AssertStageInfo<ClassicStageInfo>(stageInfo =>
{
var timingInfo = getLyricTimingInfo(karaokeBeatmap);
var timingInfo = stageInfo.LyricTimingInfo;
Assert.IsNotNull(timingInfo);

// assert mapping status.
Expand All @@ -251,25 +251,4 @@ public void TestRemoveLyricFromTimingPoint()
}

#endregion

protected override void SetUpKaraokeBeatmap(Action<KaraokeBeatmap> action)
{
base.SetUpKaraokeBeatmap(karaokeBeatmap =>
{
var stageInfo = new ClassicStageInfo();
karaokeBeatmap.StageInfos = new List<StageInfo>
{
stageInfo,
};
karaokeBeatmap.CurrentStageInfo = stageInfo;

action(karaokeBeatmap);
});
}

private static ClassicStageInfo getClassicStageInfo(KaraokeBeatmap karaokeBeatmap)
=> karaokeBeatmap.StageInfos.OfType<ClassicStageInfo>().First();

private static ClassicLyricTimingInfo getLyricTimingInfo(KaraokeBeatmap karaokeBeatmap)
=> getClassicStageInfo(karaokeBeatmap).LyricTimingInfo;
}
Loading

0 comments on commit 6ceeb9d

Please sign in to comment.