objc2_game_kit/generated/GKGameActivity.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// `GKGameActivity` represents a single instance of a game activity for the current game.
12 ///
13 /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkgameactivity?language=objc)
14 #[unsafe(super(NSObject))]
15 #[derive(Debug, PartialEq, Eq, Hash)]
16 pub struct GKGameActivity;
17);
18
19unsafe impl Send for GKGameActivity {}
20
21unsafe impl Sync for GKGameActivity {}
22
23extern_conformance!(
24 unsafe impl NSObjectProtocol for GKGameActivity {}
25);
26
27impl GKGameActivity {
28 extern_methods!(
29 /// The identifier of this activity instance.
30 ///
31 /// This property is not atomic.
32 ///
33 /// # Safety
34 ///
35 /// This might not be thread-safe.
36 #[unsafe(method(identifier))]
37 #[unsafe(method_family = none)]
38 pub unsafe fn identifier(&self) -> Retained<NSString>;
39
40 #[cfg(feature = "GKGameActivityDefinition")]
41 /// The activity definition that this activity instance is based on.
42 ///
43 /// This property is not atomic.
44 ///
45 /// # Safety
46 ///
47 /// This might not be thread-safe.
48 #[unsafe(method(activityDefinition))]
49 #[unsafe(method_family = none)]
50 pub unsafe fn activityDefinition(&self) -> Retained<GKGameActivityDefinition>;
51
52 /// Properties that contain additional information about the activity.
53 ///
54 /// This takes precedence over the `defaultProperties` on the `activityDefinition`.
55 ///
56 /// 1. This dictionary is initialized with the default properties from the activity definition and deep linked properties if any.
57 /// 2. If deep linking contains the same key as the default properties, the deep linked value will override the default value.
58 /// 3. The properties can be updated at runtime.
59 ///
60 /// This property is not atomic.
61 ///
62 /// # Safety
63 ///
64 /// This might not be thread-safe.
65 #[unsafe(method(properties))]
66 #[unsafe(method_family = none)]
67 pub unsafe fn properties(&self) -> Retained<NSDictionary<NSString, NSString>>;
68
69 /// Setter for [`properties`][Self::properties].
70 ///
71 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
72 ///
73 /// # Safety
74 ///
75 /// This might not be thread-safe.
76 #[unsafe(method(setProperties:))]
77 #[unsafe(method_family = none)]
78 pub unsafe fn setProperties(&self, properties: &NSDictionary<NSString, NSString>);
79
80 #[cfg(feature = "GKGameActivityState")]
81 /// The state of the game activity.
82 ///
83 /// This property is not atomic.
84 ///
85 /// # Safety
86 ///
87 /// This might not be thread-safe.
88 #[unsafe(method(state))]
89 #[unsafe(method_family = none)]
90 pub unsafe fn state(&self) -> GKGameActivityState;
91
92 /// If the game supports party code, this is the party code that can be shared among players to join the party.
93 ///
94 /// If the game does not support party code, this value will be nil.
95 /// - SeeAlso: ``-[GKGameActivity startWithDefinition:partyCode:completionHandler:]`` for creating a game activity with a custom party code.
96 ///
97 /// This property is not atomic.
98 ///
99 /// # Safety
100 ///
101 /// This might not be thread-safe.
102 #[unsafe(method(partyCode))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn partyCode(&self) -> Option<Retained<NSString>>;
105
106 /// If the game supports party code, this is the URL that can be shared among players to join the party.
107 ///
108 /// This property is not atomic.
109 ///
110 /// # Safety
111 ///
112 /// This might not be thread-safe.
113 #[unsafe(method(partyURL))]
114 #[unsafe(method_family = none)]
115 pub unsafe fn partyURL(&self) -> Option<Retained<NSURL>>;
116
117 /// The date when the activity was created.
118 ///
119 /// This property is not atomic.
120 ///
121 /// # Safety
122 ///
123 /// This might not be thread-safe.
124 #[unsafe(method(creationDate))]
125 #[unsafe(method_family = none)]
126 pub unsafe fn creationDate(&self) -> Retained<NSDate>;
127
128 /// The date when the activity was initially started.
129 ///
130 /// This property is not atomic.
131 ///
132 /// # Safety
133 ///
134 /// This might not be thread-safe.
135 #[unsafe(method(startDate))]
136 #[unsafe(method_family = none)]
137 pub unsafe fn startDate(&self) -> Option<Retained<NSDate>>;
138
139 /// The date when the activity was last resumed.
140 ///
141 /// - If the activity was first started, this will be the same as the start date.
142 /// - If the activity was paused and resumed, this will be the date when the activity was resumed.
143 ///
144 /// This property is not atomic.
145 ///
146 /// # Safety
147 ///
148 /// This might not be thread-safe.
149 #[unsafe(method(lastResumeDate))]
150 #[unsafe(method_family = none)]
151 pub unsafe fn lastResumeDate(&self) -> Option<Retained<NSDate>>;
152
153 /// The date when the activity was officially ended.
154 ///
155 /// This property is not atomic.
156 ///
157 /// # Safety
158 ///
159 /// This might not be thread-safe.
160 #[unsafe(method(endDate))]
161 #[unsafe(method_family = none)]
162 pub unsafe fn endDate(&self) -> Option<Retained<NSDate>>;
163
164 /// Total time elapsed while in active state.
165 ///
166 /// This property is not atomic.
167 ///
168 /// # Safety
169 ///
170 /// This might not be thread-safe.
171 #[unsafe(method(duration))]
172 #[unsafe(method_family = none)]
173 pub unsafe fn duration(&self) -> NSTimeInterval;
174
175 #[cfg(feature = "GKAchievement")]
176 /// All achievements that have been associated with this activity.
177 ///
178 /// Progress of each achievement will be reported when the activity ends.
179 ///
180 /// This property is not atomic.
181 ///
182 /// # Safety
183 ///
184 /// This might not be thread-safe.
185 #[unsafe(method(achievements))]
186 #[unsafe(method_family = none)]
187 pub unsafe fn achievements(&self) -> Retained<NSSet<GKAchievement>>;
188
189 #[cfg(feature = "GKLeaderboardScore")]
190 /// All leaderboard scores that have been associated with this activity.
191 ///
192 /// Scores will be submitted to the leaderboards when the activity ends.
193 ///
194 /// This property is not atomic.
195 ///
196 /// # Safety
197 ///
198 /// This might not be thread-safe.
199 #[unsafe(method(leaderboardScores))]
200 #[unsafe(method_family = none)]
201 pub unsafe fn leaderboardScores(&self) -> Retained<NSSet<GKLeaderboardScore>>;
202
203 /// Allowed characters for the party code to be used to share this activity.
204 #[unsafe(method(validPartyCodeAlphabet))]
205 #[unsafe(method_family = none)]
206 pub unsafe fn validPartyCodeAlphabet() -> Retained<NSArray<NSString>>;
207
208 #[unsafe(method(init))]
209 #[unsafe(method_family = init)]
210 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
211
212 #[cfg(feature = "GKGameActivityDefinition")]
213 /// Creates and starts a new game activity with a custom party code.
214 ///
215 /// The party code will be converted to uppercased.
216 #[unsafe(method(startWithDefinition:partyCode:error:_))]
217 #[unsafe(method_family = none)]
218 pub unsafe fn startWithDefinition_partyCode_error(
219 activity_definition: &GKGameActivityDefinition,
220 party_code: &NSString,
221 ) -> Result<Retained<GKGameActivity>, Retained<NSError>>;
222
223 #[cfg(feature = "GKGameActivityDefinition")]
224 /// Initializes and starts a game activity with definition.
225 #[unsafe(method(startWithDefinition:error:_))]
226 #[unsafe(method_family = none)]
227 pub unsafe fn startWithDefinition_error(
228 activity_definition: &GKGameActivityDefinition,
229 ) -> Result<Retained<GKGameActivity>, Retained<NSError>>;
230
231 /// Checks whether a party code is in valid format.
232 ///
233 /// 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`.
234 /// - SeeAlso: `validPartyCodeAlphabet` for allowed characters.
235 #[unsafe(method(isValidPartyCode:))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn isValidPartyCode(party_code: &NSString) -> bool;
238
239 #[cfg(feature = "GKGameActivityDefinition")]
240 /// Initializes a game activity with definition.
241 #[unsafe(method(initWithDefinition:))]
242 #[unsafe(method_family = init)]
243 pub unsafe fn initWithDefinition(
244 this: Allocated<Self>,
245 activity_definition: &GKGameActivityDefinition,
246 ) -> Retained<Self>;
247
248 /// Starts the game activity if it is not already started.
249 #[unsafe(method(start))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn start(&self);
252
253 /// Pauses the game activity if it is not already paused.
254 #[unsafe(method(pause))]
255 #[unsafe(method_family = none)]
256 pub unsafe fn pause(&self);
257
258 /// Resumes the game activity if it was paused.
259 #[unsafe(method(resume))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn resume(&self);
262
263 /// Ends the game activity if it is not already ended.
264 ///
265 /// This will report all associated achievements and submit scores to leaderboards.
266 #[unsafe(method(end))]
267 #[unsafe(method_family = none)]
268 pub unsafe fn end(&self);
269
270 #[cfg(feature = "GKLeaderboard")]
271 /// Set a score of a leaderboard with a context for a player.
272 ///
273 /// The score will be submitted to the leaderboard when the activity ends.
274 #[unsafe(method(setScoreOnLeaderboard:toScore:context:))]
275 #[unsafe(method_family = none)]
276 pub unsafe fn setScoreOnLeaderboard_toScore_context(
277 &self,
278 leaderboard: &GKLeaderboard,
279 score: NSInteger,
280 context: NSUInteger,
281 );
282
283 #[cfg(feature = "GKLeaderboard")]
284 /// Set a score of a leaderboard for a player.
285 ///
286 /// The score will be submitted to the leaderboard when the activity ends.
287 #[unsafe(method(setScoreOnLeaderboard:toScore:))]
288 #[unsafe(method_family = none)]
289 pub unsafe fn setScoreOnLeaderboard_toScore(
290 &self,
291 leaderboard: &GKLeaderboard,
292 score: NSInteger,
293 );
294
295 #[cfg(all(feature = "GKLeaderboard", feature = "GKLeaderboardScore"))]
296 /// Get the leaderboard score from a specific leaderboard of the local player if previously set.
297 #[unsafe(method(getScoreOnLeaderboard:))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn getScoreOnLeaderboard(
300 &self,
301 leaderboard: &GKLeaderboard,
302 ) -> Option<Retained<GKLeaderboardScore>>;
303
304 #[cfg(feature = "GKLeaderboard")]
305 /// Removes all scores from leaderboards for a player if exist.
306 #[unsafe(method(removeScoresFromLeaderboards:))]
307 #[unsafe(method_family = none)]
308 pub unsafe fn removeScoresFromLeaderboards(&self, leaderboards: &NSArray<GKLeaderboard>);
309
310 #[cfg(feature = "GKAchievement")]
311 /// Set a progress for an achievement for a player.
312 ///
313 /// Achievement progress will be reported when the activity ends.
314 #[unsafe(method(setProgressOnAchievement:toPercentComplete:))]
315 #[unsafe(method_family = none)]
316 pub unsafe fn setProgressOnAchievement_toPercentComplete(
317 &self,
318 achievement: &GKAchievement,
319 percent_complete: c_double,
320 );
321
322 #[cfg(feature = "GKAchievement")]
323 /// Convenience method to set a progress to 100% for an achievement for a player.
324 ///
325 /// Achievement completion will be reported when the activity ends.
326 #[unsafe(method(setAchievementCompleted:))]
327 #[unsafe(method_family = none)]
328 pub unsafe fn setAchievementCompleted(&self, achievement: &GKAchievement);
329
330 #[cfg(feature = "GKAchievement")]
331 /// Get the achievement progress from a specific achievement of the local player if previously set.
332 ///
333 /// Returns 0 if the achievement has not been set in the current activity.
334 #[unsafe(method(getProgressOnAchievement:))]
335 #[unsafe(method_family = none)]
336 pub unsafe fn getProgressOnAchievement(&self, achievement: &GKAchievement) -> c_double;
337
338 #[cfg(feature = "GKAchievement")]
339 /// Removes all achievements if exist.
340 #[unsafe(method(removeAchievements:))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn removeAchievements(&self, achievements: &NSArray<GKAchievement>);
343 );
344}
345
346/// Methods declared on superclass `NSObject`.
347impl GKGameActivity {
348 extern_methods!(
349 #[unsafe(method(new))]
350 #[unsafe(method_family = new)]
351 pub unsafe fn new() -> Retained<Self>;
352 );
353}
354
355/// Multiplayer.
356impl GKGameActivity {
357 extern_methods!(
358 #[cfg(feature = "GKMatchmaker")]
359 /// Makes a `GKMatchRequest` object with information from the activity, which can be used to find matches for the local player.
360 #[unsafe(method(makeMatchRequest))]
361 #[unsafe(method_family = none)]
362 pub unsafe fn makeMatchRequest(&self) -> Option<Retained<GKMatchRequest>>;
363
364 #[cfg(all(feature = "GKMatch", feature = "block2"))]
365 /// Use information from the activity to find matches for the local player.
366 ///
367 /// 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.
368 /// 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.
369 #[unsafe(method(findMatchWithCompletionHandler:))]
370 #[unsafe(method_family = none)]
371 pub unsafe fn findMatchWithCompletionHandler(
372 &self,
373 completion_handler: &block2::DynBlock<dyn Fn(*mut GKMatch, *mut NSError)>,
374 );
375
376 #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
377 /// Use information from the activity to find server hosted players for the local player.
378 ///
379 /// 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.
380 /// 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.
381 #[unsafe(method(findPlayersForHostedMatchWithCompletionHandler:))]
382 #[unsafe(method_family = none)]
383 pub unsafe fn findPlayersForHostedMatchWithCompletionHandler(
384 &self,
385 completion_handler: &block2::DynBlock<dyn Fn(*mut NSArray<GKPlayer>, *mut NSError)>,
386 );
387 );
388}
389
390/// State.
391impl GKGameActivity {
392 extern_methods!(
393 #[cfg(feature = "block2")]
394 /// Checks whether there is a pending activity to handle for the current game.
395 #[unsafe(method(checkPendingGameActivityExistenceWithCompletionHandler:))]
396 #[unsafe(method_family = none)]
397 pub unsafe fn checkPendingGameActivityExistenceWithCompletionHandler(
398 completion_handler: &block2::DynBlock<dyn Fn(Bool)>,
399 );
400 );
401}