summaryrefslogtreecommitdiffstats
path: root/libksirtet/common/highscores.cpp
blob: 9ac4a005946072f480e8041de7cba6cbe065c2e5 (plain)
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
#include "highscores.h"

#include <klocale.h>
#include <tdeapplication.h>
#include <tdeconfig.h>

#include "base/factory.h"


using namespace KExtHighscore;

CommonHighscores::CommonHighscores()
{
    Item *item = new Item((uint)1, i18n("Level"), TQt::AlignRight);
    addScoreItem("level", item);
    item = new Item((uint)0, i18n(bfactory->mainData.removedLabel),
                    TQt::AlignRight);
    addScoreItem("removed", item);
}

void CommonHighscores::convertLegacy(uint)
{
    TDEConfigGroupSaver cg(kapp->config(), "High Scores");
    for (uint i=0; i<10; i++) {
        TQString name
            = cg.config()->readEntry(TQString("name%1").arg(i), TQString());
        if ( name.isNull() ) break;
        if ( name.isEmpty() ) name = i18n("anonymous");
        uint score
            = cg.config()->readUnsignedNumEntry(TQString("score%1").arg(i), 0);
        uint level
            = cg.config()->readUnsignedNumEntry(TQString("level%1").arg(i), 1);
        Score s(Won);
        s.setScore(score);
        s.setData("name", name);
        s.setData("level", level);
        submitLegacyScore(s);
    }
}

bool CommonHighscores::isStrictlyLess(const Score &s1, const Score &s2) const
{
    uint l1 = s1.data("level").toUInt();
    uint r1 = s1.data("removed").toUInt();
    uint l2 = s2.data("level").toUInt();
    uint r2 = s2.data("removed").toUInt();

    if ( s1.score()==s2.score() ) {
        if ( l1==l2 ) return r1<r2;
        else return l1<l2;
    } else return BaseHighscores::isStrictlyLess(s1, s2);
}

void CommonHighscores::additionalQueryItems(KURL &url, const Score &s) const
{
    uint l = s.data("level").toUInt();
    addToQueryURL(url, "scoreLevel", TQString::number(l));
    uint r = s.data("removed").toUInt();
    addToQueryURL(url, "scoreRemoved", TQString::number(r));
}