-
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 #1282 from andy840119/refactor-singing-lyrics
Refactor singing lyrics collect loglc.
- Loading branch information
Showing
15 changed files
with
133 additions
and
136 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
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
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
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
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 |
---|---|---|
@@ -1,17 +1,13 @@ | ||
// 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.Scoring; | ||
using osu.Game.Rulesets.Objects; | ||
using osu.Game.Rulesets.Scoring; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Objects | ||
{ | ||
public class KaraokeHitObject : HitObject | ||
{ | ||
public double TimePreempt = 600; | ||
public double TimeFadeIn = 400; | ||
|
||
protected override HitWindows CreateHitWindows() => new KaraokeHitWindows(); | ||
} | ||
} |
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
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
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
26 changes: 26 additions & 0 deletions
26
osu.Game.Rulesets.Karaoke/Scoring/KaraokeLyricHitWindows.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,26 @@ | ||
// 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.Scoring; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Scoring | ||
{ | ||
public class KaraokeLyricHitWindows : KaraokeHitWindows | ||
{ | ||
public const HitResult DEFAULT_HIT_RESULT = HitResult.Perfect; | ||
|
||
private static readonly DifficultyRange[] lyric_ranges = | ||
{ | ||
new(DEFAULT_HIT_RESULT, 40, 20, 10), | ||
}; | ||
|
||
public override bool IsHitResultAllowed(HitResult result) => | ||
result switch | ||
{ | ||
DEFAULT_HIT_RESULT => true, | ||
_ => false | ||
}; | ||
|
||
protected override DifficultyRange[] GetRanges() => lyric_ranges; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
osu.Game.Rulesets.Karaoke/Scoring/KaraokeNoteHitWindows.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,27 @@ | ||
// 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.Scoring; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Scoring | ||
{ | ||
public class KaraokeNoteHitWindows : KaraokeHitWindows | ||
{ | ||
private static readonly DifficultyRange[] karaoke_ranges = | ||
{ | ||
new(HitResult.Perfect, 80, 50, 20), | ||
new(HitResult.Meh, 80, 50, 20), | ||
new(HitResult.Miss, 2000, 1500, 1000), | ||
}; | ||
|
||
public override bool IsHitResultAllowed(HitResult result) => | ||
result switch | ||
{ | ||
HitResult.Perfect => true, | ||
HitResult.Meh => true, | ||
_ => false | ||
}; | ||
|
||
protected override DifficultyRange[] GetRanges() => karaoke_ranges; | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
using System; | ||
using System.Linq; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Caching; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.Rulesets.Judgements; | ||
using osu.Game.Rulesets.Karaoke.Configuration; | ||
using osu.Game.Rulesets.Karaoke.Judgements; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Objects.Drawables; | ||
using osu.Game.Rulesets.Objects; | ||
|
@@ -20,69 +16,46 @@ namespace osu.Game.Rulesets.Karaoke.UI | |
{ | ||
public class LyricPlayfield : Playfield | ||
{ | ||
[Resolved] | ||
private IBindable<WorkingBeatmap> beatmap { get; set; } | ||
private readonly Bindable<Lyric[]> singingLyrics = new(); | ||
|
||
public new IEnumerable<DrawableLyric> AllHitObjects => base.AllHitObjects.OfType<DrawableLyric>(); | ||
|
||
protected WorkingBeatmap WorkingBeatmap => beatmap.Value; | ||
|
||
private readonly BindableDouble preemptTime = new(); | ||
private readonly Bindable<Lyric> nowLyric = new(); | ||
private readonly Cached seekCache = new(); | ||
|
||
public LyricPlayfield() | ||
protected override void OnNewDrawableHitObject(DrawableHitObject drawableHitObject) | ||
{ | ||
// Switch to target time | ||
nowLyric.BindValueChanged(value => | ||
if (drawableHitObject is DrawableLyric drawableLyric) | ||
{ | ||
if (!seekCache.IsValid || value.NewValue == null) | ||
return; | ||
|
||
double lyricStartTime = value.NewValue.LyricStartTime - preemptTime.Value; | ||
|
||
WorkingBeatmap.Track.Seek(lyricStartTime); | ||
}); | ||
drawableLyric.OnLyricStart += onLyricStart; | ||
drawableLyric.OnLyricEnd += onLyricEnd; | ||
} | ||
|
||
seekCache.Validate(); | ||
base.OnNewDrawableHitObject(drawableHitObject); | ||
} | ||
|
||
protected override void LoadComplete() | ||
private void onLyricStart(DrawableLyric drawableLyric) | ||
{ | ||
base.LoadComplete(); | ||
var lyrics = singingLyrics.Value ?? Array.Empty<Lyric>(); | ||
var lyric = drawableLyric.HitObject; | ||
|
||
NewResult += OnNewResult; | ||
} | ||
|
||
protected override void OnNewDrawableHitObject(DrawableHitObject drawableHitObject) | ||
{ | ||
if (drawableHitObject is DrawableLyric drawableLyric) | ||
{ | ||
// todo : not really sure should cancel binding action in here? | ||
drawableLyric.OnLyricStart += OnNewResult; | ||
} | ||
if (lyrics.Contains(lyric)) | ||
return; | ||
|
||
base.OnNewDrawableHitObject(drawableHitObject); | ||
singingLyrics.Value = lyrics.Concat(new[] { lyric }).ToArray(); | ||
} | ||
|
||
internal void OnNewResult(DrawableHitObject judgedObject, JudgementResult result) | ||
private void onLyricEnd(DrawableLyric drawableLyric) | ||
{ | ||
if (result.Judgement is not KaraokeLyricJudgement karaokeLyricJudgement) | ||
var lyrics = singingLyrics.Value ?? Array.Empty<Lyric>(); | ||
var lyric = drawableLyric.HitObject; | ||
|
||
if (!lyrics.Contains(lyric)) | ||
return; | ||
|
||
// Update now lyric | ||
var targetLyric = karaokeLyricJudgement.Time == LyricTime.Available ? judgedObject.HitObject as Lyric : null; | ||
seekCache.Invalidate(); | ||
nowLyric.Value = targetLyric; | ||
seekCache.Validate(); | ||
singingLyrics.Value = lyrics.Where(x => x != lyric).ToArray(); | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(KaraokeRulesetConfigManager rulesetConfig, KaraokeSessionStatics session) | ||
private void load(KaraokeSessionStatics session) | ||
{ | ||
// Practice | ||
rulesetConfig.BindWith(KaraokeRulesetSetting.PracticePreemptTime, preemptTime); | ||
session.BindWith(KaraokeRulesetSession.NowLyric, nowLyric); | ||
session.BindWith(KaraokeRulesetSession.SingingLyrics, singingLyrics); | ||
|
||
RegisterPool<Lyric, DrawableLyric>(50); | ||
} | ||
|
Oops, something went wrong.