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
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 checkNotPressed(OsuAction action) => AddAssert($"Not pressing {action}", () => !osuInputManager.PressedActions.Contains(action));
private void checkPressed(OsuAction action) => AddAssert($"Is 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; } public OsuAction Action { get; }

View File

@ -42,7 +42,7 @@ namespace osu.Game.Screens.Play
Size = keyFlow.Size; Size = keyFlow.Size;
} }
public override void AddTrigger(KeyCounter.InputTrigger trigger) public override void AddTrigger(InputTrigger trigger)
{ {
DefaultKeyCounter key = new DefaultKeyCounter(trigger); DefaultKeyCounter key = new DefaultKeyCounter(trigger);
Add(key); 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. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -80,20 +79,5 @@ namespace osu.Game.Screens.Play
Trigger.OnActivate -= Activate; Trigger.OnActivate -= Activate;
Trigger.OnDeactivate -= Deactivate; 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 namespace osu.Game.Screens.Play
{ {
public partial class KeyCounterActionTrigger<T> : KeyCounter.InputTrigger public partial class KeyCounterActionTrigger<T> : InputTrigger
where T : struct where T : struct
{ {
public T Action { get; } public T Action { get; }

View File

@ -25,7 +25,7 @@ namespace osu.Game.Screens.Play
public Bindable<bool> IsCounting { get; } = new BindableBool(true); public Bindable<bool> IsCounting { get; } = new BindableBool(true);
public IReadOnlyList<KeyCounter.InputTrigger> Triggers public IReadOnlyList<InputTrigger> Triggers
{ {
get => Children.Select(c => c.Trigger).ToArray(); get => Children.Select(c => c.Trigger).ToArray();
set set
@ -56,9 +56,9 @@ namespace osu.Game.Screens.Play
this.receptor = receptor; 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)); 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 namespace osu.Game.Screens.Play
{ {
public partial class KeyCounterKeyboardTrigger : KeyCounter.InputTrigger public partial class KeyCounterKeyboardTrigger : InputTrigger
{ {
public Key Key { get; } public Key Key { get; }

View File

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