-
Notifications
You must be signed in to change notification settings - Fork 0
/
usersettings.cpp
57 lines (49 loc) · 1.37 KB
/
usersettings.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
#include "usersettings.h"
#include "staffGamesConstants.h"
#include "exceptions.h"
#include <QSettings>
UserSettings::UserSettings() :
m_userName("default"), m_score(-1)
{
m_ownedGames.push_back(gameIDs::noteFinderSpaces);
}
UserSettings::UserSettings(QString name, int score) :
m_userName(name), m_score(score)
{
m_ownedGames.push_back(gameIDs::noteFinderSpaces);
}
void UserSettings::addScore(int addToScore)
{
int newScore = m_score + addToScore;
m_score = newScore < 0 ? 0 : newScore;
}
void UserSettings::setScore(int score)
{
if(score >=0 )
m_score = score;
else
m_score = 0;
}
void UserSettings::addOwnedGame(int gameId){
if(gameId>=0 && gameId<gameIDs::numGames){
if(m_ownedGames.contains(gameId)) return;
m_ownedGames.push_back(gameId);
}
else
throw Except_OutOfBounds(Q_FUNC_INFO);
}
void UserSettings::write()
{
QSettings settings;
settings.beginGroup(userSettingsKeys::users);
settings.beginGroup( m_userName );
settings.setValue(userSettingsKeys::totalBeats, m_score);
settings.beginGroup(userSettingsKeys::ownedGames);
for(int game : m_ownedGames){
settings.setValue(QString::number(game), true);
}
settings.endGroup();
settings.endGroup();
settings.endGroup();
settings.sync();
}