-
Notifications
You must be signed in to change notification settings - Fork 4
/
SteamStats.cpp
77 lines (68 loc) · 2.07 KB
/
SteamStats.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// 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 "SteamStats.h"
#include "steam/steam_api.h"
using namespace AGSteam::Plugin;
namespace AGSteam
{
namespace Plugin
{
struct SteamStats_Statics
{
public:
static SteamStats STATS;
};
}
}
SteamStats SteamStats_Statics::STATS;
SteamStats& SteamStats::GetSteamStats() noexcept
{
return SteamStats_Statics::STATS;
}
int SteamStats::GetIntStat(char const *name) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return 0;
int32 i = 0;
SteamUserStats()->GetStat(name, &i);
return static_cast<int>(i);
}
float SteamStats::GetFloatStat(char const *name) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return 0.0f;
float f = 0.0f;
SteamUserStats()->GetStat(name, &f);
return f;
}
float SteamStats::GetAverageRateStat(char const *name) const noexcept
{
return GetFloatStat(name); // average rates are calculated as float values
}
bool SteamStats::SetIntStat(char const *name, int value) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return false;
SteamUserStats()->SetStat(name, static_cast<int32>(value));
int result = SteamUserStats()->StoreStats();
SteamAPI_RunCallbacks();
return (result != 0);
}
bool SteamStats::SetFloatStat(char const *name, float value) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return false;
SteamUserStats()->SetStat(name, value);
int result = SteamUserStats()->StoreStats();
SteamAPI_RunCallbacks();
return (result != 0);
}
bool SteamStats::UpdateAverageRateStat(char const *name, float numerator, float denominator) const noexcept
{
if (!AGS2Client::GetClient()->IsInitialized()) return false;
SteamUserStats()->UpdateAvgRateStat(name, numerator, denominator);
int result = SteamUserStats()->StoreStats();
SteamAPI_RunCallbacks();
return (result != 0);
}