1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
//! 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)>,
);
);
}