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
|
use super::*;
/// Callback type after calling
/// [`request_current_stats()`](struct.UserStats.html#method.request_current_stats).
///
/// # Example
///
/// ```no_run
/// # use steamworks::*;
/// # let (client, single) = steamworks::Client::init().unwrap();
/// let callback_handle = client.register_callback(|val: UserStatsReceived| {
/// if val.result.is_err() {
/// // ...
/// }
/// });
/// ```
#[derive(Debug)]
pub struct UserStatsReceived {
pub steam_id: SteamId,
pub game_id: GameId,
pub result: Result<(), SteamError>,
}
unsafe impl Callback for UserStatsReceived {
const ID: i32 = CALLBACK_BASE_ID + 1;
const SIZE: i32 = std::mem::size_of::<sys::UserStatsReceived_t>() as i32;
unsafe fn from_raw(raw: *mut c_void) -> Self {
let val = &mut *(raw as *mut sys::UserStatsReceived_t);
Self {
steam_id: SteamId(val.m_steamIDUser.m_steamid.m_unAll64Bits),
game_id: GameId(val.m_nGameID),
result: match val.m_eResult {
sys::EResult::k_EResultOK => Ok(()),
err => Err(err.into()),
},
}
}
}
/// Callback triggered by [`store()`](stats/struct.StatsHelper.html#method.store).
///
/// # Example
///
/// ```no_run
/// # use steamworks::*;
/// # let (client, single) = steamworks::Client::init().unwrap();
/// let callback_handle = client.register_callback(|val: UserStatsStored| {
/// if val.result.is_err() {
/// // ...
/// }
/// });
/// ```
#[derive(Debug)]
pub struct UserStatsStored {
pub game_id: GameId,
pub result: Result<(), SteamError>,
}
unsafe impl Callback for UserStatsStored {
const ID: i32 = CALLBACK_BASE_ID + 2;
const SIZE: i32 = std::mem::size_of::<sys::UserStatsStored_t>() as i32;
unsafe fn from_raw(raw: *mut c_void) -> Self {
let val = &mut *(raw as *mut sys::UserStatsStored_t);
Self {
game_id: GameId(val.m_nGameID),
result: match val.m_eResult {
sys::EResult::k_EResultOK => Ok(()),
err => Err(err.into()),
},
}
}
}
/// Result of a request to store the achievements on the server, or an "indicate progress" call.
/// If both `current_progress` and `max_progress` are zero, that means the achievement has been
/// fully unlocked.
///
/// # Example
///
/// ```no_run
/// # use steamworks::*;
/// # let (client, single) = steamworks::Client::init().unwrap();
/// let callback_handle = client.register_callback(|val: UserAchievementStored| {
/// // ...
/// });
/// ```
#[derive(Debug)]
pub struct UserAchievementStored {
pub game_id: GameId,
pub achievement_name: String,
/// Current progress towards the achievement.
pub current_progress: u32,
/// The total amount of progress required to unlock.
pub max_progress: u32,
}
unsafe impl Callback for UserAchievementStored {
const ID: i32 = CALLBACK_BASE_ID + 3;
const SIZE: i32 = std::mem::size_of::<sys::UserAchievementStored_t>() as i32;
unsafe fn from_raw(raw: *mut c_void) -> Self {
let val = &mut *(raw as *mut sys::UserAchievementStored_t);
let name = CStr::from_ptr(val.m_rgchAchievementName.as_ptr()).to_owned();
Self {
game_id: GameId(val.m_nGameID),
achievement_name: name.into_string().unwrap(),
current_progress: val.m_nCurProgress,
max_progress: val.m_nMaxProgress,
}
}
}
|