Skip to content

Commit

Permalink
Inject OsuTKMicrophoneHandler on ios target.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jul 25, 2020
1 parent a0a422f commit 3dbaa65
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
15 changes: 14 additions & 1 deletion osu.Framework.Microphone.Tests.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
// See the LICENCE file in the repository root for full licence text.

using Foundation;
using osu.Framework.Input.Handlers.Microphone;
using osu.Framework.iOS;
using osu.Framework.iOS.Input;

namespace osu.Framework.Tests
{
[Register("AppDelegate")]
public class AppDelegate : GameAppDelegate
{
protected override Game CreateGame() => new VisualTestGame();
protected override Game CreateGame() => new TestingVisualTestGame();

internal class TestingVisualTestGame : VisualTestGame
{
protected override void LoadComplete()
{
base.LoadComplete();

// Need to cache IOSMicrophoneHandler in here to let MicrophoneInputManager knows.
Host.Dependencies.CacheAs(typeof(OsuTKMicrophoneHandler), new IOSMicrophoneHandler());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu.Framework.Microphone.iOS\osu.Framework.Microphone.iOS.csproj">
<Project>{431614f4-d662-4cbd-b6c2-3e0d79ca968b}</Project>
<Name>osu.Framework.Microphone.iOS</Name>
</ProjectReference>
<ProjectReference Include="..\osu.Framework.Microphone\osu.Framework.Microphone.csproj">
<Project>{D0F85C61-800A-4645-8633-AC59208FA732}</Project>
<Name>osu.Framework.Microphone</Name>
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class IOSMicrophoneHandler : OsuTKMicrophoneHandler
{
public override bool IsActive => throw new System.NotImplementedException();

public IOSMicrophoneHandler(int device) : base(device)
public IOSMicrophoneHandler() : base(-1)
{
}

Expand Down
18 changes: 15 additions & 3 deletions osu.Framework.Microphone/Input/MicrophoneInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
using osu.Framework.Input.Handlers.Microphone;
using osu.Framework.Input.StateChanges.Events;
using osu.Framework.Input.States;
using System;

namespace osu.Framework.Input
{
public class MicrophoneInputManager : CustomInputManager
{
private readonly OsuTKMicrophoneHandler handler;

protected override InputState CreateInitialState() => new MicrophoneInputState(new MicrophoneState());

private readonly int deviceId;

public MicrophoneInputManager(int device = -1)
{
AddHandler(handler = new OsuTKMicrophoneHandler(device));
deviceId = device;
}

protected override void LoadComplete()
{
base.LoadComplete();

// Use handler like iOS microphone handler if there's exist handler in dependencies.
if (Host.Dependencies.Get(typeof(OsuTKMicrophoneHandler)) is OsuTKMicrophoneHandler handler)
AddHandler(Activator.CreateInstance(handler.GetType()) as OsuTKMicrophoneHandler);
else
AddHandler(new OsuTKMicrophoneHandler(deviceId));
}

public override void HandleInputStateChange(InputStateChangeEvent inputStateChange)
Expand Down

0 comments on commit 3dbaa65

Please sign in to comment.