-
Notifications
You must be signed in to change notification settings - Fork 4
/
SteamAchievements.cpp
53 lines (47 loc) · 1.58 KB
/
SteamAchievements.cpp
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
//
// AGSteam: Steam API Plugin for AGS
// (C) 2011-2017 MonkeyMoto Productions, Inc.
//
// NOTICE: This file contains references to the Steamworks API. See the included
// LICENSE file for details and restrictions on using this file.
#include "ags2client/IAGS2Client.h"
#include "SteamAchievements.h"
#include "steam/steam_api.h"
using namespace AGSteam::Plugin;
namespace AGSteam
{
namespace Plugin
{
struct SteamAchievements_Statics
{
public:
static SteamAchievements ACHIEVEMENTS;
};
}
}
SteamAchievements SteamAchievements_Statics::ACHIEVEMENTS;
SteamAchievements& SteamAchievements::GetSteamAchievements() noexcept
{
return SteamAchievements_Statics::ACHIEVEMENTS;
}
bool SteamAchievements::ResetAchievement(char const *ID) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return false;
SteamUserStats()->ClearAchievement(ID);
return SteamUserStats()->StoreStats();
}
bool SteamAchievements::IsAchievementAchieved(char const *ID) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return false; // Steam not initialized, we can't do anything
bool achieved = false;
SteamUserStats()->GetAchievement(ID, &achieved);
return achieved;
}
bool SteamAchievements::SetAchievementAchieved(char const *ID) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return false; // Steam not initialized or haven't received call back from Steam yet, so we can't set achievements
int result = SteamUserStats()->SetAchievement(ID);
SteamUserStats()->StoreStats();
SteamAPI_RunCallbacks();
return (result != 0);
}