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::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// `GKGameActivity` represents a single instance of a game activity for the current game.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkgameactivity?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GKGameActivity;
);

unsafe impl Send for GKGameActivity {}

unsafe impl Sync for GKGameActivity {}

extern_conformance!(
    unsafe impl NSObjectProtocol for GKGameActivity {}
);

impl GKGameActivity {
    extern_methods!(
        /// The identifier of this activity instance.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(identifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifier(&self) -> Retained<NSString>;

        #[cfg(feature = "GKGameActivityDefinition")]
        /// The activity definition that this activity instance is based on.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(activityDefinition))]
        #[unsafe(method_family = none)]
        pub unsafe fn activityDefinition(&self) -> Retained<GKGameActivityDefinition>;

        /// Properties that contain additional information about the activity.
        ///
        /// This takes precedence over the `defaultProperties` on the `activityDefinition`.
        ///
        /// 1. This dictionary is initialized with the default properties from the activity definition and deep linked properties if any.
        /// 2. If deep linking contains the same key as the default properties, the deep linked value will override the default value.
        /// 3. The properties can be updated at runtime.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(properties))]
        #[unsafe(method_family = none)]
        pub unsafe fn properties(&self) -> Retained<NSDictionary<NSString, NSString>>;

        /// Setter for [`properties`][Self::properties].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setProperties:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setProperties(&self, properties: &NSDictionary<NSString, NSString>);

        #[cfg(feature = "GKGameActivityState")]
        /// The state of the game activity.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(state))]
        #[unsafe(method_family = none)]
        pub unsafe fn state(&self) -> GKGameActivityState;

        /// If the game supports party code, this is the party code that can be shared among players to join the party.
        ///
        /// If the game does not support party code, this value will be nil.
        /// - SeeAlso: ``-[GKGameActivity startWithDefinition:partyCode:completionHandler:]`` for creating a game activity with a custom party code.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(partyCode))]
        #[unsafe(method_family = none)]
        pub unsafe fn partyCode(&self) -> Option<Retained<NSString>>;

        /// If the game supports party code, this is the URL that can be shared among players to join the party.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(partyURL))]
        #[unsafe(method_family = none)]
        pub unsafe fn partyURL(&self) -> Option<Retained<NSURL>>;

        /// The date when the activity was created.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(creationDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn creationDate(&self) -> Retained<NSDate>;

        /// The date when the activity was initially started.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(startDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn startDate(&self) -> Option<Retained<NSDate>>;

        /// The date when the activity was last resumed.
        ///
        /// - If the activity was first started, this will be the same as the start date.
        /// - If the activity was paused and resumed, this will be the date when the activity was resumed.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(lastResumeDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn lastResumeDate(&self) -> Option<Retained<NSDate>>;

        /// The date when the activity was officially ended.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(endDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn endDate(&self) -> Option<Retained<NSDate>>;

        /// Total time elapsed while in active state.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(duration))]
        #[unsafe(method_family = none)]
        pub unsafe fn duration(&self) -> NSTimeInterval;

        #[cfg(feature = "GKAchievement")]
        /// All achievements that have been associated with this activity.
        ///
        /// Progress of each achievement will be reported when the activity ends.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(achievements))]
        #[unsafe(method_family = none)]
        pub unsafe fn achievements(&self) -> Retained<NSSet<GKAchievement>>;

        #[cfg(feature = "GKLeaderboardScore")]
        /// All leaderboard scores that have been associated with this activity.
        ///
        /// Scores will be submitted to the leaderboards when the activity ends.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(leaderboardScores))]
        #[unsafe(method_family = none)]
        pub unsafe fn leaderboardScores(&self) -> Retained<NSSet<GKLeaderboardScore>>;

        /// Allowed characters for the party code to be used to share this activity.
        #[unsafe(method(validPartyCodeAlphabet))]
        #[unsafe(method_family = none)]
        pub unsafe fn validPartyCodeAlphabet() -> Retained<NSArray<NSString>>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(feature = "GKGameActivityDefinition")]
        /// Creates and starts a new game activity with a custom party code.
        ///
        /// The party code will be converted to uppercased.
        #[unsafe(method(startWithDefinition:partyCode:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn startWithDefinition_partyCode_error(
            activity_definition: &GKGameActivityDefinition,
            party_code: &NSString,
        ) -> Result<Retained<GKGameActivity>, Retained<NSError>>;

        #[cfg(feature = "GKGameActivityDefinition")]
        /// Initializes and starts a game activity with definition.
        #[unsafe(method(startWithDefinition:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn startWithDefinition_error(
            activity_definition: &GKGameActivityDefinition,
        ) -> Result<Retained<GKGameActivity>, Retained<NSError>>;

        /// Checks whether a party code is in valid format.
        ///
        /// Party code should be two parts of strings with the same length (2-6) connected with a dash, and the code can be either pure digits (0-9), or both parts are uppercased characters from `validPartyCodeAlphabet`.
        /// - SeeAlso: `validPartyCodeAlphabet` for allowed characters.
        #[unsafe(method(isValidPartyCode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn isValidPartyCode(party_code: &NSString) -> bool;

        #[cfg(feature = "GKGameActivityDefinition")]
        /// Initializes a game activity with definition.
        #[unsafe(method(initWithDefinition:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDefinition(
            this: Allocated<Self>,
            activity_definition: &GKGameActivityDefinition,
        ) -> Retained<Self>;

        /// Starts the game activity if it is not already started.
        #[unsafe(method(start))]
        #[unsafe(method_family = none)]
        pub unsafe fn start(&self);

        /// Pauses the game activity if it is not already paused.
        #[unsafe(method(pause))]
        #[unsafe(method_family = none)]
        pub unsafe fn pause(&self);

        /// Resumes the game activity if it was paused.
        #[unsafe(method(resume))]
        #[unsafe(method_family = none)]
        pub unsafe fn resume(&self);

        /// Ends the game activity if it is not already ended.
        ///
        /// This will report all associated achievements and submit scores to leaderboards.
        #[unsafe(method(end))]
        #[unsafe(method_family = none)]
        pub unsafe fn end(&self);

        #[cfg(feature = "GKLeaderboard")]
        /// Set a score of a leaderboard with a context for a player.
        ///
        /// The score will be submitted to the leaderboard when the activity ends.
        #[unsafe(method(setScoreOnLeaderboard:toScore:context:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setScoreOnLeaderboard_toScore_context(
            &self,
            leaderboard: &GKLeaderboard,
            score: NSInteger,
            context: NSUInteger,
        );

        #[cfg(feature = "GKLeaderboard")]
        /// Set a score of a leaderboard for a player.
        ///
        /// The score will be submitted to the leaderboard when the activity ends.
        #[unsafe(method(setScoreOnLeaderboard:toScore:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setScoreOnLeaderboard_toScore(
            &self,
            leaderboard: &GKLeaderboard,
            score: NSInteger,
        );

        #[cfg(all(feature = "GKLeaderboard", feature = "GKLeaderboardScore"))]
        /// Get the leaderboard score from a specific leaderboard of the local player if previously set.
        #[unsafe(method(getScoreOnLeaderboard:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getScoreOnLeaderboard(
            &self,
            leaderboard: &GKLeaderboard,
        ) -> Option<Retained<GKLeaderboardScore>>;

        #[cfg(feature = "GKLeaderboard")]
        /// Removes all scores from leaderboards for a player if exist.
        #[unsafe(method(removeScoresFromLeaderboards:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeScoresFromLeaderboards(&self, leaderboards: &NSArray<GKLeaderboard>);

        #[cfg(feature = "GKAchievement")]
        /// Set a progress for an achievement for a player.
        ///
        /// Achievement progress will be reported when the activity ends.
        #[unsafe(method(setProgressOnAchievement:toPercentComplete:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setProgressOnAchievement_toPercentComplete(
            &self,
            achievement: &GKAchievement,
            percent_complete: c_double,
        );

        #[cfg(feature = "GKAchievement")]
        /// Convenience method to set a progress to 100% for an achievement for a player.
        ///
        /// Achievement completion will be reported when the activity ends.
        #[unsafe(method(setAchievementCompleted:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAchievementCompleted(&self, achievement: &GKAchievement);

        #[cfg(feature = "GKAchievement")]
        /// Get the achievement progress from a specific achievement of the local player if previously set.
        ///
        /// Returns 0 if the achievement has not been set in the current activity.
        #[unsafe(method(getProgressOnAchievement:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getProgressOnAchievement(&self, achievement: &GKAchievement) -> c_double;

        #[cfg(feature = "GKAchievement")]
        /// Removes all achievements if exist.
        #[unsafe(method(removeAchievements:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeAchievements(&self, achievements: &NSArray<GKAchievement>);
    );
}

/// Methods declared on superclass `NSObject`.
impl GKGameActivity {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// Multiplayer.
impl GKGameActivity {
    extern_methods!(
        #[cfg(feature = "GKMatchmaker")]
        /// Makes a `GKMatchRequest` object with information from the activity, which can be used to find matches for the local player.
        #[unsafe(method(makeMatchRequest))]
        #[unsafe(method_family = none)]
        pub unsafe fn makeMatchRequest(&self) -> Option<Retained<GKMatchRequest>>;

        #[cfg(all(feature = "GKMatch", feature = "block2"))]
        /// Use information from the activity to find matches for the local player.
        ///
        /// GameKit will create a classic match making request with the activity's party code and other information, and return the match object in the completion handler or any error that occurred.
        /// Error occurs if this activity doesn't support party code, or has unsupported range of players, which is used to be configured as match request's minPlayers and maxPlayers.
        #[unsafe(method(findMatchWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn findMatchWithCompletionHandler(
            &self,
            completion_handler: &block2::DynBlock<dyn Fn(*mut GKMatch, *mut NSError)>,
        );

        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
        /// Use information from the activity to find server hosted players for the local player.
        ///
        /// GameKit will create a classic server hosted match making request with the activity's party code and other information, and return the players in the completion handler or any error that occurred.
        /// Error occurs if this activity doesn't support party code, or has unsupported range of players, which is used to be configured as match request's minPlayers and maxPlayers.
        #[unsafe(method(findPlayersForHostedMatchWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn findPlayersForHostedMatchWithCompletionHandler(
            &self,
            completion_handler: &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
        );
    );
}

/// State.
impl GKGameActivity {
    extern_methods!(
        #[cfg(feature = "block2")]
        /// Checks whether there is a pending activity to handle for the current game.
        #[unsafe(method(checkPendingGameActivityExistenceWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn checkPendingGameActivityExistenceWithCompletionHandler(
            completion_handler: &block2::DynBlock<dyn Fn(Bool)>,
        );
    );
}