Skip to content

Commit

Permalink
Merge pull request #240 from andy840119/andy840119/id-to-list-singer-…
Browse files Browse the repository at this point in the history
…in-lyric

Save list of singer index instead of font index in lyric.
  • Loading branch information
andy840119 authored Nov 8, 2020
2 parents 912ac6e + fa89d41 commit c9d4682
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void TestDecodeStyle()

// Check layout and font index
Assert.AreEqual(lyric.LayoutIndex, 2);
Assert.AreEqual(lyric.FontIndex, 3);
Assert.AreEqual(lyric.Singers, new[] { 1, 2 });
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public TestDrawableLyricLine(TestSceneLyricLineStyle testCase, Lyric hitObject)
protected override void ApplySkin(ISkinSource skin, bool allowFallback)
{
// Get layout
Font = skin?.GetConfig<KaraokeSkinLookup, KaraokeFont>(new KaraokeSkinLookup(KaraokeSkinConfiguration.LyricStyle, HitObject.FontIndex))?.Value;
Font = skin?.GetConfig<KaraokeSkinLookup, KaraokeFont>(new KaraokeSkinLookup(KaraokeSkinConfiguration.LyricStyle, HitObject.Singers))?.Value;
base.ApplySkin(skin, allowFallback);
}

Expand Down
31 changes: 31 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/SingerUtilsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Tests.Utils
{
[TestFixture]
public class SingerUtilsTest
{
[TestCase(null, 0)]
[TestCase(new[] { 1 }, 1)]
[TestCase(new[] { 1, 2, 3 }, 7)]
[TestCase(new[] { 1, 4, 5 }, 25)]
public void TestGetShiftingStyleIndex(int[] singerIndexs, int styleIndex)
{
Assert.AreEqual(SingerUtils.GetShiftingStyleIndex(singerIndexs), styleIndex);
}

[TestCase(-1, new int[] { })]
[TestCase(0, new int[] { })]
[TestCase(1, new[] { 1 })]
[TestCase(7, new[] { 1, 2, 3 })]
[TestCase(25, new[] { 1, 4, 5 })]
public void TestGetSingersIndex(int styleIndex, int[] singerIndexs)
{
Assert.AreEqual(SingerUtils.GetSingersIndex(styleIndex), singerIndexs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Beatmaps.Formats
{
Expand Down Expand Up @@ -234,13 +235,13 @@ private void processStyle(Beatmap beatmap, IList<string> styleLines)
return;

var layoutIndexStr = line.Split(',').FirstOrDefault();
var fontIndexStr = line.Split(',').ElementAtOrDefault(1);
var styleIndexStr = line.Split(',').ElementAtOrDefault(1);

if (int.TryParse(layoutIndexStr, out int layoutIndex))
lyric.LayoutIndex = layoutIndex;

if (int.TryParse(fontIndexStr, out int fontIndex))
lyric.FontIndex = fontIndex;
if (int.TryParse(styleIndexStr, out int styleIndex))
lyric.Singers = SingerUtils.GetSingersIndex(styleIndex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Beatmaps.Formats
{
Expand Down Expand Up @@ -66,7 +67,9 @@ private IEnumerable<string> encodeStyle(Beatmap output)
for (var i = 0; i < lyrics.Count; i++)
{
var lyric = lyrics[i];
yield return $"@style{i}={lyric.LayoutIndex},{lyric.FontIndex}";
var layoutIndex = lyric.LayoutIndex;
var styleIndex = SingerUtils.GetShiftingStyleIndex(lyric.Singers);
yield return $"@style{i}={layoutIndex},{styleIndex}";
}
}

Expand Down
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.Karaoke/Edit/KaraokeSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using osu.Game.Rulesets.Karaoke.UI;
using osu.Game.Rulesets.Karaoke.UI.Components;
using osu.Game.Rulesets.Karaoke.UI.Position;
using osu.Game.Rulesets.Karaoke.Utils;
using osu.Game.Screens.Edit.Compose;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Skinning;
Expand Down Expand Up @@ -124,8 +125,9 @@ private MenuItem createFontMenuItem()
{
ChangeHandler.BeginChange();

// todo : SingerUtils not using in here, and this logic should be combined into siger manager.
if (state == TernaryState.True)
EditorBeatmap.SelectedHitObjects.Cast<Lyric>().ForEach(l => l.FontIndex = x.Key);
EditorBeatmap.SelectedHitObjects.Cast<Lyric>().ForEach(l => l.Singers = SingerUtils.GetSingersIndex(x.Key));

ChangeHandler.EndChange();
})).ToArray()
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Karaoke/Edit/Layout/LayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class LayoutManager : Component

public readonly Bindable<DisplayRatio> PreviewScreenRatio = new Bindable<DisplayRatio>();

public readonly Bindable<int> PreviewSkinIndex = new Bindable<int>();
public readonly Bindable<int[]> PreviewSingers = new Bindable<int[]>();

[Resolved]
private ISkinSource source { get; set; }
Expand Down Expand Up @@ -69,10 +69,10 @@ public void ChangeCurrenyLayout(KaraokeLayout layout)
EditLayout.Value = layout;
}

public void ChangePrviewStyle(int styleIndex)
public void ChangePrviewSinger(int[] singers)
{
if (styleIndex > 0)
PreviewSkinIndex.Value = styleIndex;
if (singers != null)
PreviewSingers.Value = singers;
}
}

Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Edit/Layout/LayoutPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ private void load(LayoutManager manager)
Child = new PreviewDrawableLyric(e.NewValue);
}, true);

manager.PreviewSkinIndex.BindValueChanged(v =>
manager.PreviewSingers.BindValueChanged(v =>
{
if (Child is PreviewDrawableLyric lyric)
lyric.HitObject.FontIndex = v.NewValue;
lyric.HitObject.Singers = v.NewValue;
}, true);

manager.EditLayout.BindValueChanged(v =>
Expand Down
5 changes: 4 additions & 1 deletion osu.Game.Rulesets.Karaoke/Edit/Layout/PreviewSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -80,7 +81,9 @@ private void load(LayoutManager manager)

previewStyleDropdown.Current.BindValueChanged(e =>
{
manager.ChangePrviewStyle(e.NewValue.Key);
// todo : might use dropdown to assign singer, not style.
var singer = SingerUtils.GetSingersIndex(e.NewValue.Key);
manager.ChangePrviewSinger(singer);
}, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class StyleInfoBadge : Badge
public StyleInfoBadge(Lyric lyric)
: base(lyric)
{
lyric.FontIndexBindable.BindValueChanged(value =>
lyric.SingersBindable.BindValueChanged(value =>
{
var newStyleIndex = value.NewValue;
BadgeText = $"Singer : {newStyleIndex}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Edit.Compose.Components.Timeline;
using osuTK.Graphics;
using System.Linq;

namespace osu.Game.Rulesets.Karaoke.Edit.Singers.Components.Timeline
{
Expand Down Expand Up @@ -54,10 +55,10 @@ public LyricTimelineHitObjectBlueprint(HitObject hitObject, Singer singer)

if (hitObject is Lyric lyric)
{
lyric.FontIndexBindable.BindValueChanged(e =>
lyric.SingersBindable.BindValueChanged(e =>
{
// todo : should use better way to check is singer sing this lyric
var isSingerMatch = e.NewValue == singer.ID;
// Check is lyric contains this singer, or default singer
var isSingerMatch = e.NewValue?.Contains(singer.ID) ?? singer.ID == 0;
if (isSingerMatch)
{
Show();
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public DrawableLyric(Lyric hitObject)

hitObject.RomajiTagsBindable.BindValueChanged(romajiTags => { ApplyRomaji(); }, true);

hitObject.FontIndexBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true);
hitObject.SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true);

hitObject.LayoutIndexBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true);

Expand Down Expand Up @@ -83,7 +83,7 @@ protected override void ApplySkin(ISkinSource skin, bool allowFallback)
if (CurrentSkin == null)
return;

skin.GetConfig<KaraokeSkinLookup, KaraokeFont>(new KaraokeSkinLookup(KaraokeSkinConfiguration.LyricStyle, HitObject.FontIndex))?.BindValueChanged(karaokeFont =>
skin.GetConfig<KaraokeSkinLookup, KaraokeFont>(new KaraokeSkinLookup(KaraokeSkinConfiguration.LyricStyle, HitObject.Singers))?.BindValueChanged(karaokeFont =>
{
if (karaokeFont.NewValue != null)
ApplyFont(karaokeFont.NewValue);
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class DrawableNote : DrawableKaraokeScrollingHitObject<Note>, IKeyBinding

public IBindable<bool> Display => HitObject.DisplayBindable;

public IBindable<int> StyleIndex => HitObject.StyleIndexBindable;
public IBindable<int[]> Singers => HitObject.SingersBindable;

public DrawableNote(Note note)
: base(note)
Expand All @@ -62,7 +62,7 @@ public DrawableNote(Note note)

note.AlternativeTextBindable.BindValueChanged(_ => { changeText(note); }, true);

note.StyleIndexBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true);
note.SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true);
}

protected override void ApplySkin(ISkinSource skin, bool allowFallback)
Expand All @@ -72,7 +72,7 @@ protected override void ApplySkin(ISkinSource skin, bool allowFallback)
if (CurrentSkin == null)
return;

var noteSkin = skin.GetConfig<KaraokeSkinLookup, NoteSkin>(new KaraokeSkinLookup(KaraokeSkinConfiguration.NoteStyle, HitObject.StyleIndex))?.Value;
var noteSkin = skin.GetConfig<KaraokeSkinLookup, NoteSkin>(new KaraokeSkinLookup(KaraokeSkinConfiguration.NoteStyle, HitObject.Singers))?.Value;
if (noteSkin == null)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DefaultBodyPiece : Container
private readonly LayoutValue subtractionCache = new LayoutValue(Invalidation.DrawSize);
private readonly IBindable<bool> isHitting = new Bindable<bool>();
private readonly IBindable<bool> display = new Bindable<bool>();
private readonly IBindable<int> styleIndex = new Bindable<int>();
private readonly IBindable<int[]> singer = new Bindable<int[]>();

protected Drawable Background { get; private set; }
protected Drawable Foreground { get; private set; }
Expand Down Expand Up @@ -61,19 +61,19 @@ private void load([CanBeNull] DrawableHitObject drawableObject, ISkinSource skin

isHitting.BindTo(holdNote.IsHitting);
display.BindTo(holdNote.Display);
styleIndex.BindTo(holdNote.StyleIndex);
singer.BindTo(holdNote.Singers);
}

AccentColour.BindValueChanged(onAccentChanged);
HitColour.BindValueChanged(onAccentChanged);
isHitting.BindValueChanged(_ => onAccentChanged(), true);
display.BindValueChanged(_ => onAccentChanged(), true);
styleIndex.BindValueChanged(value => applySkin(skin, value.NewValue), true);
singer.BindValueChanged(value => applySingerStyle(skin, value.NewValue), true);
}

private void applySkin(ISkinSource skin, int styleIndex)
private void applySingerStyle(ISkinSource skin, int[] singers)
{
var noteSkin = skin?.GetConfig<KaraokeSkinLookup, NoteSkin>(new KaraokeSkinLookup(KaraokeSkinConfiguration.NoteStyle, styleIndex))?.Value;
var noteSkin = skin?.GetConfig<KaraokeSkinLookup, NoteSkin>(new KaraokeSkinLookup(KaraokeSkinConfiguration.NoteStyle, singers))?.Value;
if (noteSkin == null)
return;

Expand Down
13 changes: 7 additions & 6 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Judgements;
using osu.Game.Rulesets.Karaoke.Objects.Types;
using osu.Game.Rulesets.Objects.Types;

namespace osu.Game.Rulesets.Karaoke.Objects
{
public class Lyric : KaraokeHitObject, IHasDuration
public class Lyric : KaraokeHitObject, IHasDuration, IHasSingers
{
public readonly Bindable<string> TextBindable = new Bindable<string>();

Expand Down Expand Up @@ -91,15 +92,15 @@ public override double StartTime
public double EndTime => StartTime + Duration;

[JsonIgnore]
public readonly Bindable<int> FontIndexBindable = new Bindable<int>();
public readonly Bindable<int[]> SingersBindable = new Bindable<int[]>();

/// <summary>
/// Font index
/// Singers
/// </summary>
public int FontIndex
public int[] Singers
{
get => FontIndexBindable.Value;
set => FontIndexBindable.Value = value;
get => SingersBindable.Value;
set => SingersBindable.Value = value;
}

[JsonIgnore]
Expand Down
16 changes: 10 additions & 6 deletions osu.Game.Rulesets.Karaoke/Objects/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace osu.Game.Rulesets.Karaoke.Objects
{
public class Note : KaraokeHitObject, IHasDuration, IHasText
public class Note : KaraokeHitObject, IHasDuration, IHasText, IHasSingers
{
public readonly Bindable<string> TextBindable = new Bindable<string>();

Expand All @@ -36,12 +36,16 @@ public string AlternativeText
set => AlternativeTextBindable.Value = value;
}

public readonly Bindable<int> StyleIndexBindable = new Bindable<int>();
[JsonIgnore]
public readonly Bindable<int[]> SingersBindable = new Bindable<int[]>();

public int StyleIndex
/// <summary>
/// Singers
/// </summary>
public int[] Singers
{
get => StyleIndexBindable.Value;
set => StyleIndexBindable.Value = value;
get => SingersBindable.Value;
set => SingersBindable.Value = value;
}

public readonly Bindable<bool> DisplayBindable = new Bindable<bool>();
Expand Down Expand Up @@ -107,7 +111,7 @@ public Note CopyByTime(double startTime, double duration)
StartIndex = StartIndex,
EndIndex = EndIndex,
Text = Text,
StyleIndex = StyleIndex,
Singers = Singers,
Display = Display,
Tone = Tone,
ParentLyric = ParentLyric
Expand Down
10 changes: 10 additions & 0 deletions osu.Game.Rulesets.Karaoke/Objects/Types/IHasSingers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Game.Rulesets.Karaoke.Objects.Types
{
public interface IHasSingers
{
int[] Singers { get; }
}
}
15 changes: 15 additions & 0 deletions osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkinLookup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Rulesets.Karaoke.Utils;
using System.IO;

namespace osu.Game.Rulesets.Karaoke.Skinning
{
public readonly struct KaraokeSkinLookup
{
/// <summary>
/// Ctor for <see cref="KaraokeSkinConfiguration.LyricStyle"/> and <see cref="KaraokeSkinConfiguration.NoteStyle"/>
/// </summary>
/// <param name="config"></param>
/// <param name="singers"></param>
public KaraokeSkinLookup(KaraokeSkinConfiguration config, int[] singers)
: this(config, SingerUtils.GetShiftingStyleIndex(singers))
{
if (config != KaraokeSkinConfiguration.LyricStyle && config != KaraokeSkinConfiguration.NoteStyle)
throw new InvalidDataException($"Only {KaraokeSkinConfiguration.LyricStyle} and {KaraokeSkinConfiguration.NoteStyle} can call this ctor.");
}

public KaraokeSkinLookup(KaraokeSkinConfiguration config, int lookup)
{
Config = config;
Expand Down
Loading

0 comments on commit c9d4682

Please sign in to comment.