Skip to content

Commit

Permalink
Merge pull request #2289 from andy840119/separate-singer-and-singer-s…
Browse files Browse the repository at this point in the history
…tate-into-different-list

Separate singer and singer state into different list
  • Loading branch information
andy840119 authored Sep 25, 2024
2 parents 6b83612 + dec8977 commit b3a6f80
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public void TestSingers()
var singer = singerInfo.AddSinger();
var singerState = singerInfo.AddSingerState(singer);

var allSingers = singerInfo.Singers;
Assert.AreEqual(2, allSingers.Count);
Assert.AreEqual(singer, allSingers[0]);
Assert.AreEqual(singerState, allSingers[1]);
Assert.AreEqual(1, singerInfo.Singers.Count);
Assert.AreEqual(1, singerInfo.SingerState.Count);
Assert.AreEqual(singer, singerInfo.Singers[0]);
Assert.AreEqual(singerState, singerInfo.SingerState[0]);
}

[Test]
Expand Down Expand Up @@ -102,7 +102,8 @@ public void TestAddSingerState()
var singer = singerInfo.AddSinger();
var singerState = singerInfo.AddSingerState(singer);

Assert.AreEqual(2, singerInfo.Singers.Count);
Assert.AreEqual(1, singerInfo.Singers.Count);
Assert.AreEqual(1, singerInfo.SingerState.Count);
Assert.IsNotEmpty(singerState.ID.ToString());
Assert.IsNotEmpty(singerState.MainSingerId.ToString());
}
Expand Down

This file was deleted.

27 changes: 20 additions & 7 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/SingerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ public class SingerInfo
public bool SupportSingerState { get; set; }

// todo: should make the property as readonly.
public BindableList<ISinger> Singers { get; set; } = new();
public BindableList<Singer> Singers { get; set; } = new();

// todo: should make the property as readonly.
public BindableList<SingerState> SingerState { get; set; } = new();

public IEnumerable<Singer> GetAllSingers() =>
Singers.OfType<Singer>().OrderBy(x => x.Order);
Singers.OrderBy(x => x.Order);

public IEnumerable<SingerState> GetAllAvailableSingerStates(Singer singer) =>
Singers.OfType<SingerState>().Where(x => x.MainSingerId == singer.ID).OrderBy(x => x.Order);
SingerState.Where(x => x.MainSingerId == singer.ID).OrderBy(x => x.Order);

public IDictionary<Singer, SingerState[]> GetSingerByIds(ElementId[] singerIds)
{
Expand Down Expand Up @@ -58,7 +61,7 @@ public SingerState AddSingerState(Singer singer, Action<SingerState>? action = n
var singerState = new SingerState(mainSingerId);
action?.Invoke(singerState);

Singers.Add(singerState);
SingerState.Add(singerState);

return singerState;
}
Expand All @@ -76,14 +79,24 @@ public bool RemoveSinger(ISinger singer)
RemoveSinger(singerState);
}

return Singers.Remove(singer);
return Singers.Remove(mainSinger);
}

case SingerState:
return Singers.Remove(singer);
case SingerState singerState:
return SingerState.Remove(singerState);

default:
throw new InvalidCastException();
}
}

public bool HasSinger(ISinger singer)
{
return singer switch
{
Singer mainSinger => Singers.Contains(mainSinger),
SingerState singerState => SingerState.Contains(singerState),
_ => throw new InvalidCastException(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class BeatmapSingersChangeHandler : BeatmapPropertyChangeHandler,

private SingerInfo singerInfo => KaraokeBeatmap.SingerInfo;

public BindableList<ISinger> Singers => singerInfo.Singers;
public BindableList<Singer> Singers => singerInfo.Singers;

public void ChangeOrder(ISinger singer, int newIndex)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ private void performSingerChanged<TSinger>(TSinger singer, Action<TSinger> actio
{
performSingerInfoChanged(singerInfo =>
{
if (!singerInfo.Singers.Contains(singer))
if (!singerInfo.HasSinger(singer))
throw new InvalidOperationException("Singer should be in the beatmap");

action(singer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps;
public interface IBeatmapSingersChangeHandler
{
// todo: should use IBindableList eventually, but cannot do that because it's bind to selection item.
BindableList<ISinger> Singers { get; }
BindableList<Singer> Singers { get; }

void ChangeOrder(ISinger singer, int newIndex);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public static JsonSerializerSettings CreateGlobalSettings()
{
var globalSetting = JsonSerializableExtensions.CreateGlobalSettings();

// karaoke beatmap.
globalSetting.Converters.Add(new SingerConverter());

// hit-object
globalSetting.Converters.Add(new CultureInfoConverter());
globalSetting.Converters.Add(new ElementIdConverter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Singer

public partial class SingerEditSection : LyricPropertySection
{
private readonly IBindableList<ISinger> bindableSingers = new BindableList<ISinger>();
private readonly IBindableList<Singer> bindableSingers = new BindableList<Singer>();
private readonly IBindableList<ElementId> singerIndexes = new BindableList<ElementId>();
protected override LocalisableString Title => "Singer";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas.Types;
using osu.Game.Rulesets.Karaoke.Graphics.Containers;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Singers.Rows;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Singers;

public partial class SingerRearrangeableList : OrderRearrangeableListContainer<ISinger>
public partial class SingerRearrangeableList : OrderRearrangeableListContainer<Singer>
{
protected override Vector2 Spacing => new(0, 5);

Expand All @@ -24,7 +25,7 @@ public SingerRearrangeableList()
};
}

protected override OsuRearrangeableListItem<ISinger> CreateOsuDrawable(ISinger item)
protected override OsuRearrangeableListItem<Singer> CreateOsuDrawable(Singer item)
=> new SingerRearrangeableListItem(item);

protected override Drawable CreateBottomDrawable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Singers;

public partial class SingerRearrangeableListItem : OsuRearrangeableListItem<ISinger>
public partial class SingerRearrangeableListItem : OsuRearrangeableListItem<Singer>
{
private Box dragAlert = null!;

public SingerRearrangeableListItem(ISinger item)
public SingerRearrangeableListItem(Singer item)
: base(item)
{
}

protected override Drawable CreateContent()
{
if (Model is not Singer singer)
throw new InvalidCastException($"Currently we are only able to edit the {nameof(Singer)}.");

return new Container
{
Masking = true,
Expand All @@ -42,7 +39,7 @@ protected override Drawable CreateContent()
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
new SingerLyricPlacementColumn(singer)
new SingerLyricPlacementColumn(Model)
{
RelativeSizeAxes = Axes.Both,
},
Expand Down

0 comments on commit b3a6f80

Please sign in to comment.