Struct steamworks::stats::AchievementHelper
source · pub struct AchievementHelper<'parent, M> { /* private fields */ }
Expand description
Achievement API.
Methods require
request_current_stats()
to have been called and a successful UserStatsReceived
callback processed.
§Example
// Unlock the 'WIN_THE_GAME' achievement
client.user_stats().achievement("WIN_THE_GAME").set()?;
Implementations§
source§impl<M> AchievementHelper<'_, M>
impl<M> AchievementHelper<'_, M>
sourcepub fn get(&self) -> Result<bool, ()>
pub fn get(&self) -> Result<bool, ()>
Gets the unlock status of the Achievement.
This call only modifies Steam’s in-memory state so it is quite cheap. To send the unlock
status to the server and to trigger the Steam overlay notification you must call
store_stats()
.
Fails if this achievement’s ‘API Name’ is unknown, or unsuccessful
UserStatsReceived
.
sourcepub fn set(&self) -> Result<(), ()>
pub fn set(&self) -> Result<(), ()>
Unlocks an achievement.
This call only modifies Steam’s in-memory state so it is quite cheap. To send the unlock
status to the server and to trigger the Steam overlay notification you must call
store_stats()
.
Fails if this achievement’s ‘API Name’ is unknown, or unsuccessful
UserStatsReceived
.
sourcepub fn clear(&self) -> Result<(), ()>
pub fn clear(&self) -> Result<(), ()>
Resets the unlock status of an achievement.
This call only modifies Steam’s in-memory state so it is quite cheap. To send the unlock
status to the server and to trigger the Steam overlay notification you must call
store_stats()
.
Fails if this achievement’s ‘API Name’ is unknown, or unsuccessful
UserStatsReceived
.
sourcepub fn get_achievement_achieved_percent(&self) -> Result<f32, ()>
pub fn get_achievement_achieved_percent(&self) -> Result<f32, ()>
Returns the percentage of users who have unlocked the specified achievement.
You must have called request_global_achievement_percentages()
and it needs to return
successfully via its callback prior to calling this.
Note: Always returns an error for AppId 480
(Spacewar)!
Other AppIds work fine though.
§Example
// Get the current unlock percentage for the 'WIN_THE_GAME' achievement
client.user_stats().request_global_achievement_percentages(move|result| {
if !result.is_err() {
let user_stats = client.user_stats();
let achievement = user_stats.achievement("WIN_THE_GAME");
let ach_percent = achievement.get_achievement_achieved_percent().expect("Failed to get achievement percentage");
println!("{}",ach_percent);
} else {
println!("Error requesting global achievement percentages");
}
});
sourcepub fn get_achievement_display_attribute(&self, key: &str) -> Result<&str, ()>
pub fn get_achievement_display_attribute(&self, key: &str) -> Result<&str, ()>
Get general attributes for an achievement. Currently provides: Name
, Description
,
and Hidden
status.
This receives the value from a dictionary/map keyvalue store, so you must provide one of the following keys:
"name"
to retrive the localized achievement name in UTF8"desc"
to retrive the localized achievement description in UTF8"hidden"
for retrieving if an achievement is hidden. Returns"0"
when not hidden,"1"
when hidden
This localization is provided based on the games language if it’s set, otherwise it checks if a localization is available for the users Steam UI Language. If that fails too, then it falls back to english.
This function returns the value as a string
upon success if all of the following
conditions are met; otherwise, an empty string: ""
.
request_current_stats()
has completed and successfully returned its callback.- The specified achievement exists in App Admin on the Steamworks website, and the changes are published.
- The specified
pchKey
is valid.
§Example
// Get the "description" string for the 'WIN_THE_GAME' achievement
client.user_stats().achievement("WIN_THE_GAME").get_achievement_display_attribute("desc").unwrap();
sourcepub fn get_achievement_icon(&self) -> Option<Vec<u8>>
pub fn get_achievement_icon(&self) -> Option<Vec<u8>>
Gets the icon for an achievement.
The image is returned as a handle to be used with ISteamUtils::GetImageRGBA
to get
the actual image data.*
*Note: This is handled within the function. Returns a Vec<u8>
buffer on success,
which can be converted into the image data and saved to disk (e.g. via external RGBA to image crate).