Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GameController] Add missing API for XCode15. Fixes #15725 #19708

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
39 changes: 39 additions & 0 deletions src/GameController/GCButtonElementName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#if !WATCH

using Foundation;
using ObjCRuntime;
using System;
using System.Runtime.InteropServices;

#nullable enable

namespace GameController {

public class GCButtonElementName {

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos14.0")]
#else
[TV (16, 0), Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0)]
#endif
[DllImport (Constants.GameControllerLibrary)]
static extern /* GCButtonElementName */ IntPtr GCInputArcadeButtonName (nint row, nint column);

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos14.0")]
#else
[TV (16, 0), Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0)]
#endif
public static NSString? GetArcadeButtonName (nint row, nint column)
=> Runtime.GetNSObject<NSString> (GCInputArcadeButtonName (row, column));

}

}
#endif
44 changes: 44 additions & 0 deletions src/GameController/GCPhysicalInputElementCollection_2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Versioning;
using ObjCRuntime;
using Foundation;

#if !NET
using NativeHandle = System.IntPtr;
#endif

#nullable enable

namespace GameController {

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[TV (16, 0), Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0)]
#endif
[Register ("GCPhysicalInputElementCollection", SkipRegistration = true)]
public sealed partial class GCPhysicalInputElementCollection<TKey, TValue> : GCPhysicalInputElementCollection
where TKey : NSString
where TValue : class, IGCPhysicalInputElement {

public GCPhysicalInputElementCollection (NSObjectFlag coder)
: base (coder)
{
}

public TValue? GetElement (TKey alias)
=> Runtime.GetINativeObject<TValue> (_ObjectForKeyedSubscript (alias), false);

public TValue? GetObject (TKey keyedSubscript)
=> Runtime.GetINativeObject<TValue> (_ObjectForKeyedSubscript (keyedSubscript), false);

public NSEnumerator<IGCPhysicalInputElement> ElementEnumerator
=> Runtime.GetNSObject<NSEnumerator<IGCPhysicalInputElement>> (_ElementEnumerator)!;
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a property, not a field.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a property, notice the '=>' and not a '='

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - this is exactly why Sebastien said to not use => for properties, it's a very small difference from fields (just a single character), and can end up confusing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also public and not private which is the better indicator for me personally.


}
}
2 changes: 2 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -907,9 +907,11 @@ GAMECONTROLLER_CORE_SOURCES = \
GameController/GCMotion.cs \

GAMECONTROLLER_SOURCES = \
GameController/GCButtonElementName.cs \
GameController/GCExtendedGamepadSnapshot.cs \
GameController/GCGamepadSnapshot.cs \
GameController/GCMicroGamepadSnapshot.cs \
GameController/GCPhysicalInputElementCollection_2.cs \

# GameKit

Expand Down
Loading
Loading