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>

source

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.

source

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.

source

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.

source

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");
    }
});
source

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();
source

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).

Auto Trait Implementations§

§

impl<'parent, M> RefUnwindSafe for AchievementHelper<'parent, M>
where M: RefUnwindSafe,

§

impl<'parent, M> !Send for AchievementHelper<'parent, M>

§

impl<'parent, M> !Sync for AchievementHelper<'parent, M>

§

impl<'parent, M> Unpin for AchievementHelper<'parent, M>

§

impl<'parent, M> UnwindSafe for AchievementHelper<'parent, M>
where M: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.