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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
//! 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::*;
/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboardtimescope?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKLeaderboardTimeScope(pub NSInteger);
impl GKLeaderboardTimeScope {
#[doc(alias = "GKLeaderboardTimeScopeToday")]
pub const Today: Self = Self(0);
#[doc(alias = "GKLeaderboardTimeScopeWeek")]
pub const Week: Self = Self(1);
#[doc(alias = "GKLeaderboardTimeScopeAllTime")]
pub const AllTime: Self = Self(2);
}
unsafe impl Encode for GKLeaderboardTimeScope {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for GKLeaderboardTimeScope {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboardplayerscope?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKLeaderboardPlayerScope(pub NSInteger);
impl GKLeaderboardPlayerScope {
#[doc(alias = "GKLeaderboardPlayerScopeGlobal")]
pub const Global: Self = Self(0);
#[doc(alias = "GKLeaderboardPlayerScopeFriendsOnly")]
pub const FriendsOnly: Self = Self(1);
}
unsafe impl Encode for GKLeaderboardPlayerScope {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for GKLeaderboardPlayerScope {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboardtype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKLeaderboardType(pub NSInteger);
impl GKLeaderboardType {
#[doc(alias = "GKLeaderboardTypeClassic")]
pub const Classic: Self = Self(0);
#[doc(alias = "GKLeaderboardTypeRecurring")]
pub const Recurring: Self = Self(1);
}
unsafe impl Encode for GKLeaderboardType {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for GKLeaderboardType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
/// GKLeaderboard represents a single instance of a leaderboard for the current game.
/// Leaderboards can be of the following types:
/// 1. Classic - Traditional, non-expiring leaderboards
/// 2. Recurring - Periodic timed leaderboards that follow a recurrence rule defined in App Store Connect.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboard?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct GKLeaderboard;
);
extern_conformance!(
unsafe impl NSObjectProtocol for GKLeaderboard {}
);
impl GKLeaderboard {
extern_methods!(
/// Localized title
#[unsafe(method(title))]
#[unsafe(method_family = none)]
pub unsafe fn title(&self) -> Option<Retained<NSString>>;
/// set when leaderboards have been designated a game group; set when loadLeaderboardsWithCompletionHandler has been called for leaderboards that support game groups
#[unsafe(method(groupIdentifier))]
#[unsafe(method_family = none)]
pub unsafe fn groupIdentifier(&self) -> Option<Retained<NSString>>;
/// Leaderboard ID defined in App Store Connect that this instance is associated with
#[unsafe(method(baseLeaderboardID))]
#[unsafe(method_family = none)]
pub unsafe fn baseLeaderboardID(&self) -> Retained<NSString>;
/// Type of leaderboard
#[unsafe(method(type))]
#[unsafe(method_family = none)]
pub unsafe fn r#type(&self) -> GKLeaderboardType;
/// Date and time this instance started accepting score submissions (only applicable to recurring leaderboards)
#[unsafe(method(startDate))]
#[unsafe(method_family = none)]
pub unsafe fn startDate(&self) -> Option<Retained<NSDate>>;
/// Date and time the next instance will start accepting score submissions (only applicable to recurring leaderboards)
#[unsafe(method(nextStartDate))]
#[unsafe(method_family = none)]
pub unsafe fn nextStartDate(&self) -> Option<Retained<NSDate>>;
/// Duration from startDate during which this leaderboard instance accepts score submissions (only applicable to recurring leaderboards)
#[unsafe(method(duration))]
#[unsafe(method_family = none)]
pub unsafe fn duration(&self) -> NSTimeInterval;
/// The description of this Leaderboard as configured by the developer in App Store Connect.
#[unsafe(method(leaderboardDescription))]
#[unsafe(method_family = none)]
pub unsafe fn leaderboardDescription(&self) -> Retained<NSString>;
#[cfg(feature = "GKReleaseState")]
/// The release state of the leaderboard in App Store Connect.
#[unsafe(method(releaseState))]
#[unsafe(method_family = none)]
pub unsafe fn releaseState(&self) -> GKReleaseState;
/// The identifier of the game activity associated with this leaderboard, as configured by the developer in App Store Connect.
#[unsafe(method(activityIdentifier))]
#[unsafe(method_family = none)]
pub unsafe fn activityIdentifier(&self) -> Retained<NSString>;
/// The properties when associating this leaderboard with a game activity, as configured by the developer in App Store Connect.
#[unsafe(method(activityProperties))]
#[unsafe(method_family = none)]
pub unsafe fn activityProperties(&self) -> Retained<NSDictionary<NSString, NSString>>;
/// A Boolean value that indicates whether the current leaderboard isn't visible in Game Center views.
///
/// You can still submit scores to a hidden leaderboard.
#[unsafe(method(isHidden))]
#[unsafe(method_family = none)]
pub unsafe fn isHidden(&self) -> bool;
#[cfg(feature = "block2")]
/// Loads classic and recurring leaderboards associated with the supplied App Store Connect leaderboard IDs.
/// If leaderboardIDs is nil, this loads all classic and recurring leaderboards for this game.
#[unsafe(method(loadLeaderboardsWithIDs:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadLeaderboardsWithIDs_completionHandler(
leaderboard_i_ds: Option<&NSArray<NSString>>,
completion_handler: &block2::DynBlock<
dyn Fn(*mut NSArray<GKLeaderboard>, *mut NSError),
>,
);
#[cfg(feature = "block2")]
/// Loads the occurrence preceding this occurrence for a recurring leaderboard in which the local player submitted a score. If no previous occurrence is found that the player submitted a score to, then the most recent previous occurrence is returned.
#[unsafe(method(loadPreviousOccurrenceWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadPreviousOccurrenceWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn(*mut GKLeaderboard, *mut NSError)>,
);
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
/// Class method to submit a single score to multiple leaderboards
/// score - earned by the player
/// context - developer supplied metadata associated with the player's score
/// player - the player for whom this score is being submitted
/// leaderboardIDs - one or more leaderboard IDs defined in App Store Connect
#[unsafe(method(submitScore:context:player:leaderboardIDs:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn submitScore_context_player_leaderboardIDs_completionHandler(
score: NSInteger,
context: NSUInteger,
player: &GKPlayer,
leaderboard_i_ds: &NSArray<NSString>,
completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
);
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
/// Instance method to submit a single score to the leaderboard associated with this instance
/// score - earned by the player
/// context - developer supplied metadata associated with the player's score
/// player - the player for whom this score is being submitted
#[unsafe(method(submitScore:context:player:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn submitScore_context_player_completionHandler(
&self,
score: NSInteger,
context: NSUInteger,
player: &GKPlayer,
completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
);
#[cfg(all(feature = "GKLeaderboardEntry", feature = "block2"))]
/// Loads leaderboard entries based on the supplied parameters.
/// playerScope - Friends or Global
/// timeScope - Today, Week, All Time (Only applicable to classic leaderboards)
/// range - Range of ranked entries to return (minimum start index 1, maximum length 100)
/// Upon completion, will return:
/// localPlayerEntry - entry for the local player
/// entries - requested entries matching supplied parameters
/// totalPlayerCount - total player count matching specified scope
#[unsafe(method(loadEntriesForPlayerScope:timeScope:range:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadEntriesForPlayerScope_timeScope_range_completionHandler(
&self,
player_scope: GKLeaderboardPlayerScope,
time_scope: GKLeaderboardTimeScope,
range: NSRange,
completion_handler: &block2::DynBlock<
dyn Fn(
*mut GKLeaderboardEntry,
*mut NSArray<GKLeaderboardEntry>,
NSInteger,
*mut NSError,
),
>,
);
#[cfg(all(
feature = "GKBasePlayer",
feature = "GKLeaderboardEntry",
feature = "GKPlayer",
feature = "block2"
))]
/// Loads leaderboard entries for specific players based on the supplied parameters.
/// players - Array of players to load entries for
/// timeScope - Today, Week, All Time (Only applicable to classic leaderboards)
/// Upon completion, will return:
/// localPlayerEntry - entry for the local player
/// entries - requested entries matching supplied parameters
#[unsafe(method(loadEntriesForPlayers:timeScope:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadEntriesForPlayers_timeScope_completionHandler(
&self,
players: &NSArray<GKPlayer>,
time_scope: GKLeaderboardTimeScope,
completion_handler: &block2::DynBlock<
dyn Fn(*mut GKLeaderboardEntry, *mut NSArray<GKLeaderboardEntry>, *mut NSError),
>,
);
);
}
/// Deprecated.
impl GKLeaderboard {
extern_methods!(
#[deprecated]
#[unsafe(method(category))]
#[unsafe(method_family = none)]
pub unsafe fn category(&self) -> Option<Retained<NSString>>;
/// Setter for [`category`][Self::category].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[deprecated]
#[unsafe(method(setCategory:))]
#[unsafe(method_family = none)]
pub unsafe fn setCategory(&self, category: Option<&NSString>);
#[deprecated]
#[unsafe(method(initWithPlayerIDs:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithPlayerIDs(
this: Allocated<Self>,
player_i_ds: Option<&NSArray<NSString>>,
) -> Option<Retained<Self>>;
#[cfg(feature = "block2")]
#[deprecated]
#[unsafe(method(loadCategoriesWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadCategoriesWithCompletionHandler(
completion_handler: Option<
&block2::DynBlock<
dyn Fn(*mut NSArray<NSString>, *mut NSArray<NSString>, *mut NSError),
>,
>,
);
#[cfg(feature = "block2")]
#[deprecated]
#[unsafe(method(setDefaultLeaderboard:withCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn setDefaultLeaderboard_withCompletionHandler(
leaderboard_identifier: Option<&NSString>,
completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
);
#[deprecated]
#[unsafe(method(timeScope))]
#[unsafe(method_family = none)]
pub unsafe fn timeScope(&self) -> GKLeaderboardTimeScope;
/// Setter for [`timeScope`][Self::timeScope].
#[deprecated]
#[unsafe(method(setTimeScope:))]
#[unsafe(method_family = none)]
pub unsafe fn setTimeScope(&self, time_scope: GKLeaderboardTimeScope);
/// Filter on friends. Does not apply to leaderboard initialized with players.
#[deprecated]
#[unsafe(method(playerScope))]
#[unsafe(method_family = none)]
pub unsafe fn playerScope(&self) -> GKLeaderboardPlayerScope;
/// Setter for [`playerScope`][Self::playerScope].
#[deprecated]
#[unsafe(method(setPlayerScope:))]
#[unsafe(method_family = none)]
pub unsafe fn setPlayerScope(&self, player_scope: GKLeaderboardPlayerScope);
/// leaderboardID. If nil, fetch the aggregate leaderboard.
#[deprecated]
#[unsafe(method(identifier))]
#[unsafe(method_family = none)]
pub unsafe fn identifier(&self) -> Option<Retained<NSString>>;
/// Setter for [`identifier`][Self::identifier].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[deprecated]
#[unsafe(method(setIdentifier:))]
#[unsafe(method_family = none)]
pub unsafe fn setIdentifier(&self, identifier: Option<&NSString>);
/// Leaderboards start at index 1 and the length should be less than 100. Does not apply to leaderboards initialized with players. Exception will be thrown if developer tries to set an invalid range.
#[deprecated]
#[unsafe(method(range))]
#[unsafe(method_family = none)]
pub unsafe fn range(&self) -> NSRange;
/// Setter for [`range`][Self::range].
#[deprecated]
#[unsafe(method(setRange:))]
#[unsafe(method_family = none)]
pub unsafe fn setRange(&self, range: NSRange);
#[cfg(feature = "GKScore")]
/// Scores are not valid until loadScores: has completed.
#[deprecated]
#[unsafe(method(scores))]
#[unsafe(method_family = none)]
pub unsafe fn scores(&self) -> Option<Retained<NSArray<GKScore>>>;
/// The maxRange which represents the size of the leaderboard is not valid until loadScores: has completed.
#[deprecated]
#[unsafe(method(maxRange))]
#[unsafe(method_family = none)]
pub unsafe fn maxRange(&self) -> NSUInteger;
#[cfg(feature = "GKScore")]
/// The local player's score
#[deprecated]
#[unsafe(method(localPlayerScore))]
#[unsafe(method_family = none)]
pub unsafe fn localPlayerScore(&self) -> Option<Retained<GKScore>>;
/// This property is true if the leaderboard is currently loading
#[deprecated]
#[unsafe(method(isLoading))]
#[unsafe(method_family = none)]
pub unsafe fn isLoading(&self) -> bool;
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
/// Specify an array of GKPlayers. For example, the players who are in a match together
/// Defaults to AllTime score, if you want to change the timeScope, set the property before loading the scores. Range and playerScope are not applicable. players may not be nil.
#[deprecated]
#[unsafe(method(initWithPlayers:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithPlayers(
this: Allocated<Self>,
players: &NSArray<GKPlayer>,
) -> Retained<Self>;
#[cfg(all(feature = "GKScore", feature = "block2"))]
/// Load the scores for this leader board asynchronously. Error will be nil on success.
/// Possible reasons for error:
/// 1. Communications problem
/// 2. Unauthenticated player
#[deprecated]
#[unsafe(method(loadScoresWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadScoresWithCompletionHandler(
&self,
completion_handler: Option<
&block2::DynBlock<dyn Fn(*mut NSArray<GKScore>, *mut NSError)>,
>,
);
#[cfg(feature = "block2")]
/// Loads the array of GKLeaderboard for your app
/// Possible reasons for error:
/// 1. Communications problem
/// 2. Unauthenticated player
/// 3. Leaderboard not present
#[deprecated]
#[unsafe(method(loadLeaderboardsWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadLeaderboardsWithCompletionHandler(
completion_handler: Option<
&block2::DynBlock<dyn Fn(*mut NSArray<GKLeaderboard>, *mut NSError)>,
>,
);
);
}
/// UI.
impl GKLeaderboard {
extern_methods!(
#[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
/// Asynchronously load the image. Error will be nil on success.
#[unsafe(method(loadImageWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadImageWithCompletionHandler(
&self,
completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSImage, *mut NSError)>>,
);
);
}