steamworks/user_stats/stat_callback.rs
1use super::*;
2
3/// Callback type after calling
4/// [`request_current_stats()`](struct.UserStats.html#method.request_current_stats).
5///
6/// # Example
7///
8/// ```no_run
9/// # use steamworks::*;
10/// # let client = steamworks::Client::init().unwrap();
11/// let callback_handle = client.register_callback(|val: UserStatsReceived| {
12/// if val.result.is_err() {
13/// // ...
14/// }
15/// });
16/// ```
17#[derive(Clone, Debug)]
18pub struct UserStatsReceived {
19 pub steam_id: SteamId,
20 pub game_id: GameId,
21 pub result: Result<(), SteamError>,
22}
23
24impl_callback!(cb: UserStatsReceived_t => UserStatsReceived {
25 Self {
26 steam_id: SteamId(cb.m_steamIDUser.m_steamid.m_unAll64Bits),
27 game_id: GameId(cb.m_nGameID),
28 result: crate::to_steam_result(cb.m_eResult),
29 }
30});
31
32/// Callback triggered by [`store()`](stats/struct.StatsHelper.html#method.store).
33///
34/// # Example
35///
36/// ```no_run
37/// # use steamworks::*;
38/// # let client = steamworks::Client::init().unwrap();
39/// let callback_handle = client.register_callback(|val: UserStatsStored| {
40/// if val.result.is_err() {
41/// // ...
42/// }
43/// });
44/// ```
45#[derive(Clone, Debug)]
46pub struct UserStatsStored {
47 pub game_id: GameId,
48 pub result: Result<(), SteamError>,
49}
50
51impl_callback!(cb: UserStatsStored_t => UserStatsStored {
52 Self {
53 game_id: GameId(cb.m_nGameID),
54 result: crate::to_steam_result(cb.m_eResult),
55 }
56});
57
58/// Result of a request to store the achievements on the server, or an "indicate progress" call.
59/// If both `current_progress` and `max_progress` are zero, that means the achievement has been
60/// fully unlocked.
61///
62/// # Example
63///
64/// ```no_run
65/// # use steamworks::*;
66/// # let client = steamworks::Client::init().unwrap();
67/// let callback_handle = client.register_callback(|val: UserAchievementStored| {
68/// // ...
69/// });
70/// ```
71#[derive(Clone, Debug)]
72pub struct UserAchievementStored {
73 pub game_id: GameId,
74 pub achievement_name: String,
75 /// Current progress towards the achievement.
76 pub current_progress: u32,
77 /// The total amount of progress required to unlock.
78 pub max_progress: u32,
79}
80
81impl_callback!(cb: UserAchievementStored_t => UserAchievementStored {
82 let name = CStr::from_ptr(cb.m_rgchAchievementName.as_ptr()).to_owned();
83 Self {
84 game_id: GameId(cb.m_nGameID),
85 achievement_name: name.into_string().unwrap(),
86 current_progress: cb.m_nCurProgress,
87 max_progress: cb.m_nMaxProgress,
88 }
89});
90
91/// Result of a request to retrieve the achievement icon if the icon was not available at the time of the function call.
92/// # Example
93///
94/// ```no_run
95/// # use steamworks::*;
96/// # let client = steamworks::Client::init().unwrap();
97/// let callback_handle = client.register_callback(|val: UserAchievementIconFetched| {
98/// // ...
99/// });
100/// ```
101#[derive(Clone, Debug)]
102pub struct UserAchievementIconFetched {
103 pub game_id: GameId,
104 pub achievement_name: String,
105 pub achieved: bool,
106 pub icon_handle: i32,
107}
108
109impl_callback!(cb: UserAchievementIconFetched_t => UserAchievementIconFetched {
110 let name = CStr::from_ptr(cb.m_rgchAchievementName.as_ptr()).to_owned();
111 Self {
112 game_id: GameId(cb.m_nGameID.__bindgen_anon_1.m_ulGameID),
113 achievement_name: name.into_string().unwrap(),
114 achieved: cb.m_bAchieved,
115 icon_handle: cb.m_nIconHandle,
116 }
117});