// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using System; using JetBrains.Annotations; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Utils; namespace osu.Game.Rulesets.Catch.Objects.Drawables { public abstract class DrawableCatchHitObject : DrawableHitObject { public readonly Bindable OriginalXBindable = new Bindable(); public readonly Bindable XOffsetBindable = new Bindable(); protected override double InitialLifetimeOffset => HitObject.TimePreempt; protected override float SamplePlaybackPosition => HitObject.EffectiveX / CatchPlayfield.WIDTH; public int RandomSeed => HitObject?.RandomSeed ?? 0; protected DrawableCatchHitObject([CanBeNull] CatchHitObject hitObject) : base(hitObject) { Anchor = Anchor.BottomLeft; } /// /// Get a random number in range [0,1) based on seed . /// public float RandomSingle(int series) => StatelessRNG.NextSingle(RandomSeed, series); protected override void OnApply() { base.OnApply(); OriginalXBindable.BindTo(HitObject.OriginalXBindable); XOffsetBindable.BindTo(HitObject.XOffsetBindable); } protected override void OnFree() { base.OnFree(); OriginalXBindable.UnbindFrom(HitObject.OriginalXBindable); XOffsetBindable.UnbindFrom(HitObject.XOffsetBindable); } public Func CheckPosition; protected override JudgementResult CreateResult(Judgement judgement) => new CatchJudgementResult(HitObject, judgement); protected override void CheckForResult(bool userTriggered, double timeOffset) { if (CheckPosition == null) return; if (timeOffset >= 0 && Result != null) ApplyResult(r => r.Type = CheckPosition.Invoke(HitObject) ? r.Judgement.MaxResult : r.Judgement.MinResult); } protected override void UpdateHitStateTransforms(ArmedState state) { switch (state) { case ArmedState.Miss: this.FadeOut(250).RotateTo(Rotation * 2, 250, Easing.Out); break; case ArmedState.Hit: this.FadeOut(); break; } } } }