Skip to content

Commit a2067c5

Browse files
committed
Code tidy up
1 parent e6afa86 commit a2067c5

File tree

8 files changed

+9
-22
lines changed

8 files changed

+9
-22
lines changed

engine/Orbit.Input/GameControllerManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ namespace Orbit.Input;
22

33
public partial class GameControllerManager
44
{
5-
private List<GameController> gameControllers = [];
5+
private readonly List<GameController> gameControllers = [];
66

77
private static GameControllerManager? current;
88

9-
public static GameControllerManager Current => current ?? (current = new GameControllerManager());
9+
public static GameControllerManager Current => current ??= new GameControllerManager();
1010

1111
public partial Task StartDiscovery();
1212

@@ -16,6 +16,7 @@ public partial class GameControllerManager
1616

1717
private void OnGameControllerConnected(GameController controller)
1818
{
19+
gameControllers.Add(controller);
1920
this.GameControllerConnected?.Invoke(this, new GameControllerConnectedEventArgs(controller));
2021
}
2122
}

engine/Orbit.Input/Platforms/Android/GameControllerManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public partial Task StartDiscovery()
5151

5252
if (sources.HasFlag(InputSourceType.Gamepad) || sources.HasFlag(InputSourceType.Joystick))
5353
{
54-
gameControllers.Add(new GameController(deviceId));
54+
OnGameControllerConnected(new GameController(deviceId));
5555
}
5656
}
5757

engine/Orbit.Input/Platforms/Android/GenericMotionListener.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ namespace Orbit.Input;
77

88
public class GenericMotionListener : Java.Lang.Object, ViewTreeObserver.IOnGlobalFocusChangeListener, View.IOnGenericMotionListener
99
{
10-
private readonly Activity activity;
1110
private readonly Func<MotionEvent, bool> callback;
1211

1312
public GenericMotionListener(Activity activity, Func<MotionEvent, bool> callback)
1413
{
1514
this.callback = callback ?? throw new ArgumentNullException(nameof(callback));
16-
this.activity = activity;
17-
this.activity.Window?.DecorView.ViewTreeObserver?.AddOnGlobalFocusChangeListener(this);
15+
16+
activity.Window?.DecorView.ViewTreeObserver?.AddOnGlobalFocusChangeListener(this);
1817
}
1918

2019
public void OnGlobalFocusChanged(View? oldFocus, View? newFocus)

engine/Orbit.Input/Platforms/Android/KeyListener.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ namespace Orbit.Input;
77

88
public class KeyListener : Java.Lang.Object, ViewTreeObserver.IOnGlobalFocusChangeListener, View.IOnKeyListener
99
{
10-
private readonly Activity activity;
1110
private readonly Func<Keycode, KeyEvent, bool> callback;
1211

1312
public KeyListener(Activity activity, Func<Keycode, KeyEvent, bool> callback)
1413
{
1514
this.callback = callback ?? throw new ArgumentNullException(nameof(callback));
16-
this.activity = activity;
17-
this.activity.Window?.DecorView.ViewTreeObserver?.AddOnGlobalFocusChangeListener(this);
15+
16+
activity.Window?.DecorView.ViewTreeObserver?.AddOnGlobalFocusChangeListener(this);
1817
}
1918

2019
public void OnGlobalFocusChanged(View? oldFocus, View? newFocus)

engine/Orbit.Input/Platforms/MacCatalyst/GameControllerManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ private void ConnectToController(object? sender, NSNotificationEventArgs e)
2121
if (e.Notification.Object is GCController controller)
2222
{
2323
var gameController = new GameController(controller);
24-
gameControllers.Add(gameController);
2524
OnGameControllerConnected(gameController);
2625
}
2726
}

engine/Orbit.Input/Platforms/Tizen/PlatformClass1.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

engine/Orbit.Input/Platforms/Windows/GameControllerManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ private void OnRawGameControllerAdded(object? sender, RawGameController rawGameC
3535
private void OnGamepadAdded(object? sender, Gamepad gamepad)
3636
{
3737
var controller = new GameController(gamepad);
38-
gameControllers.Add(controller);
39-
GameControllerConnected?.Invoke(this, new GameControllerConnectedEventArgs(controller));
38+
OnGameControllerConnected(controller);
4039

4140
if (StartControllerMonitoringUponDetection)
4241
{

engine/Orbit.Input/Platforms/iOS/GameControllerManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ private void ConnectToController(object? sender, NSNotificationEventArgs e)
2121
if (e.Notification.Object is GCController controller)
2222
{
2323
var gameController = new GameController(controller);
24-
gameControllers.Add(gameController);
2524
OnGameControllerConnected(gameController);
2625
}
2726
}

0 commit comments

Comments
 (0)