|
| 1 | +using System; |
| 2 | +using fluXis.Input; |
| 3 | +using fluXis.Map.Structures; |
| 4 | +using fluXis.Scoring.Enums; |
| 5 | +using fluXis.Utils.Extensions; |
| 6 | +using osu.Framework.Allocation; |
| 7 | +using osu.Framework.Graphics; |
| 8 | +using osu.Framework.Input.Bindings; |
| 9 | +using osu.Framework.Input.Events; |
| 10 | + |
| 11 | +namespace fluXis.Modes.Keys.Map.Objects.Drawable; |
| 12 | + |
| 13 | +#nullable enable |
| 14 | + |
| 15 | +public partial class DrawableTick : DrawableKeysHitObject<HitObject>, IKeyBindingHandler<FluXisGameplayKeybind> |
| 16 | +{ |
| 17 | + public override bool CanBeRemoved => Judged || wouldMiss; |
| 18 | + private bool wouldMiss => Time.Current - Object.Time > HitWindows.TimingFor(HitWindows.LowestHitable); |
| 19 | + |
| 20 | + private int actionIndex; |
| 21 | + |
| 22 | + private bool heldDown; |
| 23 | + private bool directHit = false; |
| 24 | + private double? holdStartTime; |
| 25 | + |
| 26 | + public DrawableTick(HitObject o) |
| 27 | + : base(o) |
| 28 | + { |
| 29 | + } |
| 30 | + |
| 31 | + [BackgroundDependencyLoader] |
| 32 | + private void load() |
| 33 | + { |
| 34 | + InternalChild = Skin.GetTickNote(PlayerLane, Manager.KeyCount, Object.HoldTime > 0).WithRelativeSize(Axes.X); |
| 35 | + actionIndex = Array.IndexOf(Keybinds.Keys, Action); |
| 36 | + } |
| 37 | + |
| 38 | + protected override void Update() |
| 39 | + { |
| 40 | + base.Update(); |
| 41 | + |
| 42 | + heldDown = Keybinds.PressedActions.Contains(Action); |
| 43 | + holdStartTime = heldDown ? Keybinds.PressTimes[actionIndex] : null; |
| 44 | + |
| 45 | + if (heldDown) UpdateJudgement(true); |
| 46 | + } |
| 47 | + |
| 48 | + protected override void CheckJudgement(bool byUser, double offset) |
| 49 | + { |
| 50 | + if (!byUser) |
| 51 | + { |
| 52 | + ApplyResult(lagCompensation() ?? HitWindows.TimingFor(HitWindows.Lowest)); |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + if (offset >= 0 && !directHit) |
| 57 | + return; |
| 58 | + |
| 59 | + if (wouldMiss) |
| 60 | + { |
| 61 | + var off = lagCompensation(); |
| 62 | + |
| 63 | + if (off != null) |
| 64 | + { |
| 65 | + ApplyResult(off.Value); |
| 66 | + return; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + // ObjectManager.PlayHitSound(Data, false); |
| 71 | + ApplyResult(lagCompensation() ?? offset); |
| 72 | + return; |
| 73 | + |
| 74 | + double? lagCompensation() |
| 75 | + { |
| 76 | + if (heldDown && holdStartTime != null) |
| 77 | + { |
| 78 | + var delta = holdStartTime.Value - Object.Time; |
| 79 | + return delta < 0 ? 0 : delta; |
| 80 | + } |
| 81 | + |
| 82 | + return null; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + public bool OnPressed(KeyBindingPressEvent<FluXisGameplayKeybind> e) |
| 87 | + { |
| 88 | + if (e.Action != Action) |
| 89 | + return false; |
| 90 | + |
| 91 | + var flWindow = HitWindows.TimingFor(Judgement.Flawless); |
| 92 | + |
| 93 | + if (Math.Abs(TimeDelta) < flWindow) |
| 94 | + { |
| 95 | + directHit = true; |
| 96 | + UpdateJudgement(true); |
| 97 | + return true; |
| 98 | + } |
| 99 | + |
| 100 | + return false; |
| 101 | + } |
| 102 | + |
| 103 | + public void OnReleased(KeyBindingReleaseEvent<FluXisGameplayKeybind> e) |
| 104 | + { |
| 105 | + if (e.Action != Action) |
| 106 | + return; |
| 107 | + |
| 108 | + UpdateJudgement(true); |
| 109 | + } |
| 110 | +} |
0 commit comments