-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1825 from andy840119/implement-classic-stage-chan…
…ger-handler Implement classic stage changer handler
- Loading branch information
Showing
10 changed files
with
521 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...sets.Karaoke.Tests/Editor/ChangeHandlers/Beatmaps/BeatmapClassicStageChangeHandlerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages.Classic; | ||
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Beatmaps; | ||
|
||
public partial class BeatmapClassicStageChangeHandlerTest : BaseChangeHandlerTest<BeatmapClassicStageChangeHandler> | ||
{ | ||
[Test] | ||
public void TestEditLayoutDefinition() | ||
{ | ||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
karaokeBeatmap.StageInfos.Add(new ClassicStageInfo()); | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.EditLayoutDefinition(x => | ||
{ | ||
x.LineHeight = 12; | ||
}); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var classicStageInfo = karaokeBeatmap.StageInfos.OfType<ClassicStageInfo>().First(); | ||
Assert.IsNotNull(classicStageInfo); | ||
var definition = classicStageInfo.LyricLayoutDefinition; | ||
Assert.AreEqual(12, definition.LineHeight); | ||
}); | ||
} | ||
} |
205 changes: 205 additions & 0 deletions
205
...aoke.Tests/Editor/ChangeHandlers/Beatmaps/BeatmapStageElementCategoryChangeHandlerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
// Copyright (c) andy840119 <andy840119@gmail.com>. 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.Beatmaps.Stages; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages.Classic; | ||
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Beatmaps; | ||
|
||
public partial class BeatmapStageElementCategoryChangeHandlerTest : BaseChangeHandlerTest<BeatmapStageElementCategoryChangeHandlerTest.TestBeatmapStageElementCategoryChangeHandler> | ||
{ | ||
protected override TestBeatmapStageElementCategoryChangeHandler CreateChangeHandler() | ||
=> new(x => x.OfType<ClassicStageInfo>().First().LyricLayoutCategory); | ||
|
||
[Test] | ||
public void TestAddElement() | ||
{ | ||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
karaokeBeatmap.StageInfos.Add(new ClassicStageInfo()); | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.AddElement(x => | ||
{ | ||
x.Name = "Element 1"; | ||
}); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var category = getStageCategory(karaokeBeatmap); | ||
var firstElement = category.AvailableElements.First(); | ||
Assert.AreEqual("Element 1", firstElement.Name); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestEditElement() | ||
{ | ||
ClassicLyricLayout lyricLayout = null!; | ||
|
||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var stageInfo = new ClassicStageInfo(); | ||
stageInfo.LyricLayoutCategory.AddElement(); | ||
karaokeBeatmap.StageInfos.Add(stageInfo); | ||
lyricLayout = stageInfo.LyricLayoutCategory.AvailableElements.First(); | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.EditElement(lyricLayout.ID, x => | ||
{ | ||
x.Name = "Edit Element 1"; | ||
}); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var category = getStageCategory(karaokeBeatmap); | ||
var firstElement = category.AvailableElements.First(); | ||
Assert.AreEqual("Edit Element 1", firstElement.Name); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestRemoveElement() | ||
{ | ||
ClassicLyricLayout lyricLayout = null!; | ||
|
||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var stageInfo = new ClassicStageInfo(); | ||
stageInfo.LyricLayoutCategory.AddElement(); | ||
karaokeBeatmap.StageInfos.Add(stageInfo); | ||
lyricLayout = stageInfo.LyricLayoutCategory.AvailableElements.First(); | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.RemoveElement(lyricLayout); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var category = getStageCategory(karaokeBeatmap); | ||
Assert.IsEmpty(category.AvailableElements); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestAddToMapping() | ||
{ | ||
ClassicLyricLayout lyricLayout = null!; | ||
Lyric lyric = null!; | ||
|
||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var stageInfo = new ClassicStageInfo(); | ||
stageInfo.LyricLayoutCategory.AddElement(); | ||
karaokeBeatmap.StageInfos.Add(stageInfo); | ||
lyricLayout = stageInfo.LyricLayoutCategory.AvailableElements.First(); | ||
}); | ||
|
||
PrepareHitObject(lyric = new Lyric()); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.AddToMapping(lyricLayout, lyric); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var category = getStageCategory(karaokeBeatmap); | ||
Assert.IsNotEmpty(category.Mappings); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestRemoveFromMapping() | ||
{ | ||
Lyric lyric = null!; | ||
|
||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var stageInfo = new ClassicStageInfo(); | ||
stageInfo.LyricLayoutCategory.AddElement(); | ||
karaokeBeatmap.StageInfos.Add(stageInfo); | ||
karaokeBeatmap.HitObjects.Add(lyric = new Lyric()); | ||
var lyricLayout = stageInfo.LyricLayoutCategory.AvailableElements.First(); | ||
// Add to Mapping | ||
stageInfo.LyricLayoutCategory.AddToMapping(lyricLayout, lyric); | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.RemoveFromMapping(lyric); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var category = getStageCategory(karaokeBeatmap); | ||
Assert.IsEmpty(category.Mappings); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestClearUnusedMapping() | ||
{ | ||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var stageInfo = new ClassicStageInfo(); | ||
stageInfo.LyricLayoutCategory.AddElement(); | ||
karaokeBeatmap.StageInfos.Add(stageInfo); | ||
var lyricLayout = stageInfo.LyricLayoutCategory.AvailableElements.First(); | ||
// Add to Mapping | ||
stageInfo.LyricLayoutCategory.AddToMapping(lyricLayout, new Lyric()); | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.ClearUnusedMapping(); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var category = getStageCategory(karaokeBeatmap); | ||
Assert.IsEmpty(category.Mappings); | ||
}); | ||
} | ||
|
||
private static ClassicLyricLayoutCategory getStageCategory(KaraokeBeatmap beatmap) | ||
{ | ||
return beatmap.StageInfos.OfType<ClassicStageInfo>().First().LyricLayoutCategory; | ||
} | ||
|
||
public partial class TestBeatmapStageElementCategoryChangeHandler : BeatmapStageElementCategoryChangeHandler<ClassicLyricLayout, Lyric> | ||
{ | ||
public TestBeatmapStageElementCategoryChangeHandler(Func<IEnumerable<StageInfo>, StageElementCategory<ClassicLyricLayout, Lyric>> action) | ||
: base(action) | ||
{ | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...e.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Beatmaps/BeatmapStagesChangeHandlerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages.Classic; | ||
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Beatmaps; | ||
|
||
public partial class BeatmapStagesChangeHandlerTest : BaseChangeHandlerTest<BeatmapStagesChangeHandler> | ||
{ | ||
[Test] | ||
public void TestAddStageInfoToBeatmap() | ||
{ | ||
TriggerHandlerChanged(c => | ||
{ | ||
c.AddStageInfoToBeatmap<ClassicStageInfo>(); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var stageInfos = karaokeBeatmap.StageInfos; | ||
Assert.AreEqual(1, stageInfos.Count); | ||
Assert.AreEqual(typeof(ClassicStageInfo), stageInfos[0].GetType()); | ||
}); | ||
|
||
// Should not add the same stage again. | ||
TriggerHandlerChangedWithException<InvalidOperationException>(c => | ||
{ | ||
c.AddStageInfoToBeatmap<ClassicStageInfo>(); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestRemoveStageInfoFromBeatmap() | ||
{ | ||
SetUpKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
karaokeBeatmap.StageInfos = new List<StageInfo> | ||
{ | ||
new ClassicStageInfo() | ||
}; | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
c.RemoveStageInfoFromBeatmap<ClassicStageInfo>(); | ||
}); | ||
|
||
AssertKaraokeBeatmap(karaokeBeatmap => | ||
{ | ||
var stageInfos = karaokeBeatmap.StageInfos; | ||
Assert.AreEqual(0, stageInfos.Count); | ||
}); | ||
|
||
// Should not remove if there's no matched stage info type. | ||
TriggerHandlerChangedWithException<InvalidOperationException>(c => | ||
{ | ||
c.RemoveStageInfoFromBeatmap<ClassicStageInfo>(); | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/BeatmapClassicStageChangeHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Linq; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages.Classic; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; | ||
|
||
public partial class BeatmapClassicStageChangeHandler : BeatmapPropertyChangeHandler, IBeatmapClassicStageChangeHandler | ||
{ | ||
public void EditLayoutDefinition(Action<ClassicLyricLayoutDefinition> action) | ||
{ | ||
performStageInfoChanged(x => | ||
{ | ||
action(x.LyricLayoutDefinition); | ||
}); | ||
} | ||
|
||
private void performStageInfoChanged(Action<ClassicStageInfo> action) | ||
{ | ||
PerformBeatmapChanged(beatmap => | ||
{ | ||
var stage = getStageInfo(beatmap); | ||
action(stage); | ||
}); | ||
|
||
ClassicStageInfo getStageInfo(KaraokeBeatmap beatmap) | ||
=> beatmap.StageInfos.OfType<ClassicStageInfo>().First(); | ||
} | ||
} |
Oops, something went wrong.