Adds the new steam achievement and leaderboards
This commit is contained in:
parent
d034a69f44
commit
8d09e8a23b
22
src/main.c
22
src/main.c
|
@ -900,6 +900,23 @@ run_game_render(void)
|
|||
SDL_RenderPresent(gRenderer);
|
||||
}
|
||||
|
||||
#ifdef STEAM_BUILD
|
||||
static inline void
|
||||
register_scores(void)
|
||||
{
|
||||
uint8_t details[4] = { (uint8_t) gPlayer->stats.lvl, (uint8_t) cLevel, 0, 0 };
|
||||
steam_register_score((int) gPlayer->gold, (int32_t*) &details, 1);
|
||||
steam_register_kills((int) gPlayer->stat_data.kills, (int32_t*) &details, 1);
|
||||
if (gPlayer->class == ROGUE) {
|
||||
steam_set_achievement(ROGUE_LIKE);
|
||||
steam_register_rogue_score((int) gPlayer->gold, (int32_t*) &details, 1);
|
||||
}
|
||||
else if (gPlayer->class == WARRIOR) {
|
||||
steam_register_warrior_score((int) gPlayer->gold, (int32_t*) &details, 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
run_game(void)
|
||||
{
|
||||
|
@ -925,9 +942,7 @@ run_game(void)
|
|||
createInGameGameOverMenu();
|
||||
hiscore_register(gPlayer, cLevel);
|
||||
#ifdef STEAM_BUILD
|
||||
uint8_t details[4] = { (uint8_t) gPlayer->stats.lvl, (uint8_t) cLevel, 0, 0 };
|
||||
steam_register_score((int) gPlayer->gold, (int32_t*) &details, 1);
|
||||
steam_register_kills((int) gPlayer->stat_data.kills, (int32_t*) &details, 1);
|
||||
register_scores();
|
||||
#endif // STEAM_BUILD
|
||||
|
||||
} else {
|
||||
|
@ -943,6 +958,7 @@ run_game(void)
|
|||
end_game_details();
|
||||
#ifdef STEAM_BUILD
|
||||
steam_set_achievement(BACK_TO_WORK);
|
||||
register_scores();
|
||||
#endif // STEAM_BUILD
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "../timer.h"
|
||||
|
||||
static const char *LB_HIGHSCORE = "Highscore";
|
||||
static const char *LB_ROGUE_HIGHSCORE = "Rogue Highscore";
|
||||
static const char *LB_WARRIOR_HIGHSCORE = "Warrior Highscore";
|
||||
static const char *LB_KILLS = "Most Kills";
|
||||
|
||||
static Achievement g_Achievements[] = {
|
||||
|
@ -15,15 +17,18 @@ static Achievement g_Achievements[] = {
|
|||
_ACH_ID(THE_DOCTOR_IS_OUT, "The Doctor is Out"),
|
||||
_ACH_ID(LIGHTS_ON, "Omnidirectional light"),
|
||||
_ACH_ID(BACK_TO_WORK, "Back to work"),
|
||||
_ACH_ID(DRAGON_SLAYER, "Platinum dragon slayer")
|
||||
_ACH_ID(DRAGON_SLAYER, "Platinum dragon slayer"),
|
||||
_ACH_ID(ROGUE_LIKE, "Rogue-like")
|
||||
};
|
||||
static Uint8 numAchievements = 5;
|
||||
static Uint8 numAchievements = 6;
|
||||
|
||||
static bool m_Initiated = false;
|
||||
static bool m_bStatsReceived = false;
|
||||
static Sint64 m_AppID = 0;
|
||||
static Sint64 m_hHighscoreLeaderboard = 0;
|
||||
static Sint64 m_hKillsLeaderboard = 0;
|
||||
static Sint64 m_hRogueHighscore = 0;
|
||||
static Sint64 m_hWarriorHighscore = 0;
|
||||
|
||||
static Timer *requestDataTimer = NULL;
|
||||
|
||||
|
@ -56,6 +61,10 @@ leaderboard_received(Sint64 hLeaderboard, const char *name)
|
|||
m_hHighscoreLeaderboard = hLeaderboard;
|
||||
else if (strcmp(LB_KILLS, name) == 0)
|
||||
m_hKillsLeaderboard = hLeaderboard;
|
||||
else if (strcmp(LB_ROGUE_HIGHSCORE, name) == 0)
|
||||
m_hRogueHighscore = hLeaderboard;
|
||||
else if (strcmp(LB_WARRIOR_HIGHSCORE, name) == 0)
|
||||
m_hWarriorHighscore = hLeaderboard;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -93,6 +102,10 @@ request_data_queue_run(void)
|
|||
c_SteamUserStats_FindLeaderboard(LB_HIGHSCORE);
|
||||
else if (!m_hKillsLeaderboard)
|
||||
c_SteamUserStats_FindLeaderboard(LB_KILLS);
|
||||
else if (!m_hRogueHighscore)
|
||||
c_SteamUserStats_FindLeaderboard(LB_ROGUE_HIGHSCORE);
|
||||
else if (!m_hWarriorHighscore)
|
||||
c_SteamUserStats_FindLeaderboard(LB_WARRIOR_HIGHSCORE);
|
||||
|
||||
timer_start(requestDataTimer);
|
||||
}
|
||||
|
@ -124,6 +137,20 @@ void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetail
|
|||
c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore, details, nDetails);
|
||||
}
|
||||
|
||||
void steam_register_warrior_score(Sint32 nScore, const int32_t * details, int32_t nDetails)
|
||||
{
|
||||
if (!m_hWarriorHighscore)
|
||||
return;
|
||||
c_SteamUserStats_UploadLeaderboardScore(m_hWarriorHighscore, nScore, details, nDetails);
|
||||
}
|
||||
|
||||
void steam_register_rogue_score(Sint32 nScore, const int32_t * details, int32_t nDetails)
|
||||
{
|
||||
if (!m_hRogueHighscore)
|
||||
return;
|
||||
c_SteamUserStats_UploadLeaderboardScore(m_hRogueHighscore, nScore, details, nDetails);
|
||||
}
|
||||
|
||||
void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails)
|
||||
{
|
||||
if (!m_hKillsLeaderboard)
|
||||
|
|
|
@ -11,7 +11,8 @@ typedef enum EAchievement
|
|||
BACK_TO_WORK = 5,
|
||||
DRAGON_SLAYER = 6,
|
||||
BUGGFIXER = 7,
|
||||
BUGGCREATOR = 8
|
||||
BUGGCREATOR = 8,
|
||||
ROGUE_LIKE = 9
|
||||
} EAchievement;
|
||||
|
||||
|
||||
|
@ -37,4 +38,8 @@ void steam_set_achievement(EAchievement eAch);
|
|||
|
||||
void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails);
|
||||
|
||||
void steam_register_warrior_score(Sint32 nScore, const int32_t *details, int32_t nDetails);
|
||||
|
||||
void steam_register_rogue_score(Sint32 nScore, const int32_t *details, int32_t nDetails);
|
||||
|
||||
void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails);
|
||||
|
|
Loading…
Reference in New Issue