1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 08:53:17 +08:00

refactor(InputTrigger): move out of KCD

I love JetBrains Rider.
This commit is contained in:
tsrk 2023-02-22 15:03:44 +00:00
parent 1beec71037
commit 8c94b77de1
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6
8 changed files with 31 additions and 24 deletions

View File

@ -579,7 +579,7 @@ namespace osu.Game.Rulesets.Osu.Tests
private void checkNotPressed(OsuAction action) => AddAssert($"Not pressing {action}", () => !osuInputManager.PressedActions.Contains(action));
private void checkPressed(OsuAction action) => AddAssert($"Is pressing {action}", () => osuInputManager.PressedActions.Contains(action));
public partial class TestActionKeyCounterTrigger : KeyCounter.InputTrigger, IKeyBindingHandler<OsuAction>
public partial class TestActionKeyCounterTrigger : InputTrigger, IKeyBindingHandler<OsuAction>
{
public OsuAction Action { get; }

View File

@ -42,7 +42,7 @@ namespace osu.Game.Screens.Play
Size = keyFlow.Size;
}
public override void AddTrigger(KeyCounter.InputTrigger trigger)
public override void AddTrigger(InputTrigger trigger)
{
DefaultKeyCounter key = new DefaultKeyCounter(trigger);
Add(key);

View File

@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics;
namespace osu.Game.Screens.Play
{
public abstract partial class InputTrigger : Component
{
public event Action<bool>? OnActivate;
public event Action<bool>? OnDeactivate;
protected InputTrigger(string name)
{
Name = name;
}
protected void Activate(bool forwardPlayback = true) => OnActivate?.Invoke(forwardPlayback);
protected void Deactivate(bool forwardPlayback = true) => OnDeactivate?.Invoke(forwardPlayback);
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -80,20 +79,5 @@ namespace osu.Game.Screens.Play
Trigger.OnActivate -= Activate;
Trigger.OnDeactivate -= Deactivate;
}
public abstract partial class InputTrigger : Component
{
public event Action<bool>? OnActivate;
public event Action<bool>? OnDeactivate;
protected InputTrigger(string name)
{
Name = name;
}
protected void Activate(bool forwardPlayback = true) => OnActivate?.Invoke(forwardPlayback);
protected void Deactivate(bool forwardPlayback = true) => OnDeactivate?.Invoke(forwardPlayback);
}
}
}

View File

@ -7,7 +7,7 @@ using System.Collections.Generic;
namespace osu.Game.Screens.Play
{
public partial class KeyCounterActionTrigger<T> : KeyCounter.InputTrigger
public partial class KeyCounterActionTrigger<T> : InputTrigger
where T : struct
{
public T Action { get; }

View File

@ -25,7 +25,7 @@ namespace osu.Game.Screens.Play
public Bindable<bool> IsCounting { get; } = new BindableBool(true);
public IReadOnlyList<KeyCounter.InputTrigger> Triggers
public IReadOnlyList<InputTrigger> Triggers
{
get => Children.Select(c => c.Trigger).ToArray();
set
@ -56,9 +56,9 @@ namespace osu.Game.Screens.Play
this.receptor = receptor;
}
public abstract void AddTrigger(KeyCounter.InputTrigger trigger);
public abstract void AddTrigger(InputTrigger trigger);
public void AddTriggerRange(IEnumerable<KeyCounter.InputTrigger> triggers) => triggers.ForEach(AddTrigger);
public void AddTriggerRange(IEnumerable<InputTrigger> triggers) => triggers.ForEach(AddTrigger);
private bool checkType(KeyCounter key) => acceptedTypes.Length == 0 || acceptedTypes.Any(t => t.IsInstanceOfType(key));

View File

@ -8,7 +8,7 @@ using osuTK.Input;
namespace osu.Game.Screens.Play
{
public partial class KeyCounterKeyboardTrigger : KeyCounter.InputTrigger
public partial class KeyCounterKeyboardTrigger : InputTrigger
{
public Key Key { get; }

View File

@ -9,7 +9,7 @@ using osuTK;
namespace osu.Game.Screens.Play
{
public partial class KeyCounterMouseTrigger : KeyCounter.InputTrigger
public partial class KeyCounterMouseTrigger : InputTrigger
{
public MouseButton Button { get; }