Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate singer and singer state into different list #2289

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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