Save / load state of achievements.

This commit is contained in:
Bartosz Taudul 2024-06-07 23:48:56 +02:00
parent 3f2d28407b
commit a3b63bb468
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 48 additions and 0 deletions

View File

@ -1,7 +1,11 @@
#include <assert.h> #include <assert.h>
#include <inttypes.h>
#include <time.h> #include <time.h>
#include "../ini.h"
#include "TracyAchievements.hpp" #include "TracyAchievements.hpp"
#include "TracyStorage.hpp"
namespace tracy namespace tracy
{ {
@ -16,6 +20,49 @@ AchievementsMgr::AchievementsMgr()
FillMap( (*cat)->items, *cat ); FillMap( (*cat)->items, *cat );
cat++; cat++;
} }
const auto fn = tracy::GetSavePath( "achievements.ini" );
auto ini = ini_load( fn );
if( !ini ) return;
for( auto& v : m_map )
{
uint64_t unlockTime, doneTime;
int hideCompleted, hideNew;
if( ini_sget( ini, v.first, "unlockTime", "%" PRIu64, &unlockTime ) &&
ini_sget( ini, v.first, "doneTime", "%" PRIu64, &doneTime ) &&
ini_sget( ini, v.first, "hideCompleted", "%d", &hideCompleted ) &&
ini_sget( ini, v.first, "hideNew", "%d", &hideNew ) )
{
auto& it = v.second.item;
it->unlockTime = unlockTime;
it->doneTime = doneTime;
it->hideCompleted = hideCompleted != 0;
it->hideNew = hideNew != 0;
}
}
ini_free( ini );
}
AchievementsMgr::~AchievementsMgr()
{
const auto fn = tracy::GetSavePath( "achievements.ini" );
FILE* f = fopen( fn, "wb" );
if( !f ) return;
for( auto& v : m_map )
{
auto& it = v.second.item;
fprintf( f, "[%s]\n", it->id );
fprintf( f, "unlockTime=%" PRIu64 "\n", it->unlockTime );
fprintf( f, "doneTime=%" PRIu64 "\n", it->doneTime );
fprintf( f, "hideCompleted=%d\n", it->hideCompleted ? 1 : 0 );
fprintf( f, "hideNew=%d\n\n", it->hideNew ? 1 : 0 );
}
fclose( f );
} }
void AchievementsMgr::Achieve( const char* id ) void AchievementsMgr::Achieve( const char* id )

View File

@ -56,6 +56,7 @@ class AchievementsMgr
public: public:
AchievementsMgr(); AchievementsMgr();
~AchievementsMgr();
void Achieve( const char* id ); void Achieve( const char* id );
data::AchievementCategory** GetCategories() const; data::AchievementCategory** GetCategories() const;