Save achievements data after each completion.

This commit is contained in:
Bartosz Taudul 2024-06-16 12:53:40 +02:00
parent 50f5345ea5
commit 9f0f3a7218
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 23 additions and 15 deletions

View File

@ -82,21 +82,7 @@ AchievementsMgr::AchievementsMgr()
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 );
Save();
}
void AchievementsMgr::Achieve( const char* id )
@ -129,6 +115,8 @@ void AchievementsMgr::Achieve( const char* id )
c++;
}
}
Save();
}
data::AchievementCategory** AchievementsMgr::GetCategories() const
@ -200,4 +188,23 @@ void AchievementsMgr::FillMap( data::AchievementItem** items, data::AchievementC
}
}
void AchievementsMgr::Save()
{
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 );
}
}

View File

@ -71,6 +71,7 @@ public:
private:
void FillMap( data::AchievementItem** items, data::AchievementCategory* category );
void Save();
std::vector<data::AchievementItem*> m_queue;
tracy::unordered_flat_map<const char*, AchievementPair, charutil::Hasher, charutil::Comparator> m_map;