[Kde-games-devel] KScore2

Stefan Majewsky kdemailinglists at bethselamin.de
Fri Aug 6 16:45:10 CEST 2010


Hi folks,

after KGameRenderer is mostly complete, I come to occupy myself
with the next
part of libkdegames that is worth working on: the score
management.

In the "kscore2" branch of my kdegames Git repo [1][2], you
find a first draft
for what shall constitute the backend of KScore2. The
concept is roughly as
follows:

* The KScore2::Model is a
QAbstractItemModel-derived data model which will be
used in the score
dialogs.
* The basic structure of the score model is defined by a category
model (of
type QStandardItemModel). For example, KGameDifficulty could
provide a
category model with its difficulties. On the other hand,
KGoldRunner could
implement its own category model which is populated with
its level packs.
* The score model itself does not know how the data is
stored on disk. This
job is handled by the KScore2::Engine. For example,
KGoldRunner could
implement its own engine to support its legacy highscore
file format, while
most other games, which use KScoreDialog now, could just
use a default
KHighscore-based Engine.

The first goal of my design is
near-trivial integration with existing games.
In a game which uses
KScoreDialog with KHighscore, the relevant code would
become:

>
//initialization
> KScore2::Model::init(KGameDifficulty::categoryModel());
>
KScore2::Model::instance()->addFields(KScore2::PlayerNameField |
KScore2::ScoreField);
> //showing the score dialog
> KScore2::Dialog
dialog;
> dialog.show();
> //adding a new score
> KScore2::DataSet
dataset;
> dataset[KScore2::PlayerNameField] = "Stefan";
>
dataset[KScore2::ScoreField] = 42;
>
KScore2::Model::instance()->addScore(dataset);
> KScore2::Dialog dialog;
>
dialog.show();

Another design goal is high flexibility. For example, the
separation of engines from the model will make it possible to integrate GGZ
highscore lists.

I will post more code once it is at least a bit stable,
though you are welcome to comment on what is in my Git repo already. I have
not tested anything yet, but I plan to implement extensive unit tests
shortly.

Greetings
Stefan

[1] git clone
git://git.bethselamin.de/kdegames-work.git
[2]
http://git.bethselamin.de/?p=kdegames-work.git;a=summary


More information about the kde-games-devel mailing list