Skip to content

Commit

Permalink
Merge pull request #1939 from andy840119/move-preempt-time-into-applier
Browse files Browse the repository at this point in the history
Move preempt time into applier
  • Loading branch information
andy840119 authored Apr 16, 2023
2 parents 7a87084 + 663f3e3 commit 691679d
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,6 @@ protected override IStageEffectApplier ConvertToNoteStageAppliers(IEnumerable<St
throw new NotImplementedException();
}

protected override double GetPreemptTime(Lyric lyric)
{
throw new NotImplementedException();
}

protected override double GetPreemptTime(Note note)
{
throw new NotImplementedException();
}

protected override Tuple<double?, double?> GetStartAndEndTime(Lyric lyric)
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Objects.Workings;

public class LyricWorkingPropertyValidatorTest : HitObjectWorkingPropertyValidatorTest<Lyric, LyricWorkingProperty>
{
[Test]
public void TestPreemptTime()
{
var lyric = new Lyric();

// state is valid because assign the property.
Assert.DoesNotThrow(() => lyric.PreemptTime = 300);
AssetIsValid(lyric, LyricWorkingProperty.PreemptTime, true);
}

[Test]
public void TestStartTime()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Objects.Workings;

public class NoteWorkingPropertyValidatorTest : HitObjectWorkingPropertyValidatorTest<Note, NoteWorkingProperty>
{
[Test]
public void TestPreemptTime()
{
var note = new Note();

// page state is valid because assign the property.
Assert.DoesNotThrow(() => note.PreemptTime = 300);
AssetIsValid(note, NoteWorkingProperty.PreemptTime, true);
}

[Test]
public void TestPage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ protected override IStageEffectApplier ConvertToNoteStageAppliers(IEnumerable<St
return new NoteClassicStageEffectApplier(elements, StageDefinition);
}

protected override double GetPreemptTime(Lyric lyric)
{
// todo: should have the time if having loading effect with duration.
return 0;
}

protected override double GetPreemptTime(Note note)
{
// todo: should have the time if having loading effect with duration.
return 0;
}

protected override Tuple<double?, double?> GetStartAndEndTime(Lyric lyric)
{
return LyricTimingInfo.GetStartAndEndTime(lyric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,6 @@ protected override IStageEffectApplier ConvertToNoteStageAppliers(IEnumerable<St
return new NotePreviewStageEffectApplier(elements, StageDefinition);
}

protected override double GetPreemptTime(Lyric lyric)
{
return StageDefinition.FadingTime;
}

protected override double GetPreemptTime(Note note)
{
// todo: should have the time if having loading effect with duration.
return 0;
}

protected override Tuple<double?, double?> GetStartAndEndTime(Lyric lyric)
{
var element = layoutCategory.GetElementByItem(lyric);
Expand Down
12 changes: 0 additions & 12 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Stages/StageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ private IEnumerable<StageElement> getStageElements(KaraokeHitObject hitObject) =
_ => Array.Empty<StageElement>()
};

public double GetPreemptTime(KaraokeHitObject hitObject) =>
hitObject switch
{
Lyric lyric => GetPreemptTime(lyric),
Note note => GetPreemptTime(note),
_ => throw new InvalidOperationException()
};

public Tuple<double?, double?> GetStartAndEndTime(KaraokeHitObject hitObject) =>
hitObject switch
{
Expand All @@ -61,10 +53,6 @@ public double GetPreemptTime(KaraokeHitObject hitObject) =>

protected abstract IStageEffectApplier ConvertToNoteStageAppliers(IEnumerable<StageElement> elements);

protected abstract double GetPreemptTime(Lyric lyric);

protected abstract double GetPreemptTime(Note note);

protected abstract Tuple<double?, double?> GetStartAndEndTime(Lyric lyric);

#endregion
Expand Down
30 changes: 0 additions & 30 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric_Working.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public void ValidateWorkingProperty(KaraokeBeatmap beatmap)
{
switch (flag)
{
case LyricWorkingProperty.PreemptTime:
PreemptTime = getPreemptTime(beatmap, this);
break;

case LyricWorkingProperty.StartTime:
StartTime = getStartTime(beatmap, this);
break;
Expand Down Expand Up @@ -78,16 +74,6 @@ public void ValidateWorkingProperty(KaraokeBeatmap beatmap)
}
}

static double getPreemptTime(KaraokeBeatmap beatmap, KaraokeHitObject lyric)
{
var stageInfo = beatmap.CurrentStageInfo;
if (stageInfo == null)
throw new InvalidCastException();

double preemptTime = stageInfo.GetPreemptTime(lyric);
return preemptTime;
}

static double getStartTime(KaraokeBeatmap beatmap, KaraokeHitObject lyric)
{
var stageInfo = beatmap.CurrentStageInfo;
Expand Down Expand Up @@ -136,22 +122,6 @@ static IStageEffectApplier getStageEffectApplier(KaraokeBeatmap beatmap, Karaoke
[JsonIgnore]
public double LyricDuration => LyricEndTime - LyricStartTime;

private double preemptTime;

/// <summary>
/// Lyric's preempt time is created from <see cref="StageInfo"/> and should not be saved.
/// </summary>
[JsonIgnore]
public double PreemptTime
{
get => preemptTime;
set
{
preemptTime = value;
updateStateByWorkingProperty(LyricWorkingProperty.PreemptTime);
}
}

/// <summary>
/// Lyric's start time is created from <see cref="StageInfo"/> and should not be saved.
/// </summary>
Expand Down
31 changes: 0 additions & 31 deletions osu.Game.Rulesets.Karaoke/Objects/Note_Working.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using osu.Game.Extensions;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages;
using osu.Game.Rulesets.Karaoke.Objects.Stages;
using osu.Game.Rulesets.Karaoke.Objects.Types;
using osu.Game.Rulesets.Karaoke.Objects.Workings;
Expand Down Expand Up @@ -41,10 +40,6 @@ public void ValidateWorkingProperty(KaraokeBeatmap beatmap)
{
switch (flag)
{
case NoteWorkingProperty.PreemptTime:
PreemptTime = getPreemptTime(beatmap, this);
break;

case NoteWorkingProperty.Page:
PageIndex = getPageIndex(beatmap, StartTime);
break;
Expand All @@ -62,16 +57,6 @@ public void ValidateWorkingProperty(KaraokeBeatmap beatmap)
}
}

static double getPreemptTime(KaraokeBeatmap beatmap, KaraokeHitObject lyric)
{
var stageInfo = beatmap.CurrentStageInfo;
if (stageInfo == null)
throw new InvalidCastException();

double preemptTime = stageInfo.GetPreemptTime(lyric);
return preemptTime;
}

static int? getPageIndex(KaraokeBeatmap beatmap, double startTime)
=> beatmap.PageInfo.GetPageIndexAt(startTime);

Expand Down Expand Up @@ -105,22 +90,6 @@ public int? PageIndex
}
}

private double preemptTime;

/// <summary>
/// Note's preempt time is created from <see cref="StageInfo"/> and should not be saved.
/// </summary>
[JsonIgnore]
public double PreemptTime
{
get => preemptTime;
set
{
preemptTime = value;
updateStateByWorkingProperty(NoteWorkingProperty.PreemptTime);
}
}

/// <summary>
/// Start time.
/// There's no need to save the time because it's calculated by the <see cref="TimeTag"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public LyricClassicStageEffectApplier(IEnumerable<StageElement> elements, Classi
{
}

protected override double GetPreemptTime(IEnumerable<StageElement> elements)
{
// todo: implementation needed.
return 0;
}

protected override void UpdateInitialTransforms(TransformSequence<DrawableLyric> transformSequence, StageElement element)
{
throw new System.NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public NoteClassicStageEffectApplier(IEnumerable<StageElement> elements, Classic
{
}

protected override double GetPreemptTime(IEnumerable<StageElement> elements)
{
// todo: implementation needed.
return 0;
}

protected override void UpdateInitialTransforms(TransformSequence<DrawableNote> transformSequence, StageElement element)
{
throw new System.NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public LyricPreviewStageEffectApplier(IEnumerable<StageElement> elements, Previe
{
}

protected override double GetPreemptTime(IEnumerable<StageElement> elements)
{
return Definition.FadingTime;
}

protected override void UpdateInitialTransforms(TransformSequence<DrawableLyric> transformSequence, StageElement element)
{
switch (element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public NotePreviewStageEffectApplier(IEnumerable<StageElement> elements, Preview
{
}

protected override double GetPreemptTime(IEnumerable<StageElement> elements)
{
// todo: implementation needed.
return 0;
}

protected override void UpdateInitialTransforms(TransformSequence<DrawableNote> transformSequence, StageElement element)
{
throw new System.NotImplementedException();
Expand Down
10 changes: 8 additions & 2 deletions osu.Game.Rulesets.Karaoke/Objects/Stages/StageEffectApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
using osu.Game.Rulesets.Karaoke.Beatmaps.Stages;
Expand All @@ -14,14 +15,17 @@ public abstract class StageEffectApplier<TStageDefinition, TDrawableHitObject> :
where TStageDefinition : StageDefinition
where TDrawableHitObject : DrawableHitObject
{
private readonly IEnumerable<StageElement> elements;
private readonly StageElement[] elements;

protected readonly TStageDefinition Definition;
public readonly double PreemptTime;

protected StageEffectApplier(IEnumerable<StageElement> elements, TStageDefinition definition)
{
this.elements = elements;
this.elements = elements.ToArray();
Definition = definition;

PreemptTime = GetPreemptTime(this.elements);
}

/// <summary>
Expand Down Expand Up @@ -88,6 +92,8 @@ public void UpdateHitStateTransforms(DrawableHitObject drawableHitObject, ArmedS
transform.Then().FadeOut();
}

protected abstract double GetPreemptTime(IEnumerable<StageElement> elements);

protected abstract void UpdateInitialTransforms(TransformSequence<TDrawableHitObject> transformSequence, StageElement element);

protected abstract void UpdateStartTimeStateTransforms(TransformSequence<TDrawableHitObject> transformSequence, StageElement element);
Expand Down
2 changes: 0 additions & 2 deletions osu.Game.Rulesets.Karaoke/Objects/Types/IHasEffectApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ namespace osu.Game.Rulesets.Karaoke.Objects.Types;

public interface IHasEffectApplier
{
double PreemptTime { get; }

IStageEffectApplier EffectApplier { get; }
}
19 changes: 7 additions & 12 deletions osu.Game.Rulesets.Karaoke/Objects/Workings/LyricWorkingProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,38 @@ namespace osu.Game.Rulesets.Karaoke.Objects.Workings;
[Flags]
public enum LyricWorkingProperty
{
/// <summary>
/// <see cref="Lyric.PreemptTime"/> is being invalidated.
/// </summary>
PreemptTime = 1,

/// <summary>
/// <see cref="Lyric.StartTime"/> is being invalidated.
/// </summary>
StartTime = 1 << 1,
StartTime = 1,

/// <summary>
/// <see cref="Lyric.Duration"/> is being invalidated.
/// </summary>
Duration = 1 << 2,
Duration = 1 << 1,

/// <summary>
/// <see cref="Lyric.StartTime"/> and <see cref="Lyric.Duration"/> is being invalidated.
/// </summary>
Timing = PreemptTime | StartTime | Duration,
Timing = StartTime | Duration,

/// <summary>
/// <see cref="Lyric.Singers"/> is being invalidated.
/// </summary>
Singers = 1 << 3,
Singers = 1 << 2,

/// <summary>
/// <see cref="Lyric.PageIndex"/> is being invalidated.
/// </summary>
Page = 1 << 4,
Page = 1 << 3,

/// <summary>
/// <see cref="Lyric.ReferenceLyric"/> is being invalidated.
/// </summary>
ReferenceLyric = 1 << 5,
ReferenceLyric = 1 << 4,

/// <summary>
/// <see cref="Lyric.EffectApplier"/> is being invalidated.
/// </summary>
EffectApplier = 1 << 6,
EffectApplier = 1 << 5,
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public LyricWorkingPropertyValidator(Lyric hitObject)
protected override bool CanCheckWorkingPropertySync(Lyric hitObject, LyricWorkingProperty flags) =>
flags switch
{
LyricWorkingProperty.PreemptTime => false,
LyricWorkingProperty.StartTime => false,
LyricWorkingProperty.Duration => false,
LyricWorkingProperty.Timing => false,
Expand All @@ -31,7 +30,6 @@ protected override bool CanCheckWorkingPropertySync(Lyric hitObject, LyricWorkin
protected override bool NeedToSyncWorkingProperty(Lyric hitObject, LyricWorkingProperty flags) =>
flags switch
{
LyricWorkingProperty.PreemptTime => false,
LyricWorkingProperty.StartTime => false,
LyricWorkingProperty.Duration => false,
LyricWorkingProperty.Timing => false,
Expand Down
Loading

0 comments on commit 691679d

Please sign in to comment.