objc2-game-kit 0.3.2

Bindings to the GameKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
use objc2_app_kit::*;
use objc2_foundation::*;

use crate::*;

extern "C" {
    /// Deprecated methods that previously returned player IDs will return GKPlayerIDNoLongerAvailable instead.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkplayeridnolongeravailable?language=objc)
    pub static GKPlayerIDNoLongerAvailable: &'static NSString;
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkplayer?language=objc)
    #[unsafe(super(GKBasePlayer, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "GKBasePlayer")]
    pub struct GKPlayer;
);

#[cfg(feature = "GKBasePlayer")]
extern_conformance!(
    unsafe impl NSCopying for GKPlayer {}
);

#[cfg(feature = "GKBasePlayer")]
unsafe impl CopyingHelper for GKPlayer {
    type Result = Self;
}

#[cfg(feature = "GKBasePlayer")]
extern_conformance!(
    unsafe impl NSObjectProtocol for GKPlayer {}
);

#[cfg(feature = "GKBasePlayer")]
impl GKPlayer {
    extern_methods!(
        /// This convenience method checks if the gamePlayerID and the teamPlayerID (scopedIDs) are persistent or unique for the instantiation of this app.
        #[unsafe(method(scopedIDsArePersistent))]
        #[unsafe(method_family = none)]
        pub unsafe fn scopedIDsArePersistent(&self) -> bool;

        /// This is the player's unique and persistent ID that is scoped to this application.
        #[unsafe(method(gamePlayerID))]
        #[unsafe(method_family = none)]
        pub unsafe fn gamePlayerID(&self) -> Retained<NSString>;

        /// This is the player's unique and persistent ID that is scoped to the Apple Store Connect Team identifier of this application.
        #[unsafe(method(teamPlayerID))]
        #[unsafe(method_family = none)]
        pub unsafe fn teamPlayerID(&self) -> Retained<NSString>;

        /// This is player's alias to be displayed. The display name may be very long, so be sure to use appropriate string truncation API when drawing.
        #[unsafe(method(displayName))]
        #[unsafe(method_family = none)]
        pub unsafe fn displayName(&self) -> Retained<NSString>;

        /// The alias property contains the player's nickname. When you need to display the name to the user, consider using displayName instead. The nickname is unique but not invariant: the player may change their nickname. The nickname may be very long, so be sure to use appropriate string truncation API when drawing.
        #[unsafe(method(alias))]
        #[unsafe(method_family = none)]
        pub unsafe fn alias(&self) -> Retained<NSString>;

        #[unsafe(method(anonymousGuestPlayerWithIdentifier:))]
        #[unsafe(method_family = none)]
        pub unsafe fn anonymousGuestPlayerWithIdentifier(
            guest_identifier: &NSString,
        ) -> Retained<Self>;

        #[unsafe(method(guestIdentifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn guestIdentifier(&self) -> Option<Retained<NSString>>;

        #[unsafe(method(isInvitable))]
        #[unsafe(method_family = none)]
        pub unsafe fn isInvitable(&self) -> bool;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "GKBasePlayer")]
impl GKPlayer {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkphotosize?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKPhotoSize(pub NSInteger);
impl GKPhotoSize {
    #[doc(alias = "GKPhotoSizeSmall")]
    pub const Small: Self = Self(0);
    #[doc(alias = "GKPhotoSizeNormal")]
    pub const Normal: Self = Self(1);
}

unsafe impl Encode for GKPhotoSize {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for GKPhotoSize {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// UI.
#[cfg(feature = "GKBasePlayer")]
impl GKPlayer {
    extern_methods!(
        #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
        #[cfg(target_os = "macos")]
        /// Asynchronously load the player's photo. Error will be nil on success.
        /// Possible reasons for error:
        /// 1. Communications failure
        #[unsafe(method(loadPhotoForSize:withCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadPhotoForSize_withCompletionHandler(
            &self,
            size: GKPhotoSize,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSImage, *mut NSError)>>,
        );
    );
}

extern "C" {
    /// Notification will be posted whenever the player details changes. The object of the notification will be the player.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkplayerdidchangenotificationname?language=objc)
    pub static GKPlayerDidChangeNotificationName: &'static NSNotificationName;
}

/// Deprecated.
#[cfg(feature = "GKBasePlayer")]
impl GKPlayer {
    extern_methods!(
        #[deprecated]
        #[unsafe(method(isFriend))]
        #[unsafe(method_family = none)]
        pub unsafe fn isFriend(&self) -> bool;

        #[deprecated = "Use ``GKPlayer/gamePlayerID`` or ``GKPlayer/teamPlayerID`` instead."]
        #[unsafe(method(playerID))]
        #[unsafe(method_family = none)]
        pub unsafe fn playerID(&self) -> Retained<NSString>;

        #[cfg(feature = "block2")]
        /// Load the Game Center players for the playerIDs provided. Error will be nil on success.
        /// Possible reasons for error:
        /// 1. Unauthenticated local player
        /// 2. Communications failure
        /// 3. Invalid player identifier
        #[deprecated]
        #[unsafe(method(loadPlayersForIdentifiers:withCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadPlayersForIdentifiers_withCompletionHandler(
            identifiers: &NSArray<NSString>,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
            >,
        );
    );
}