[Kde-games-devel] How to overwrite a KCFG setting?
Parker Coates
parker.coates at gmail.com
Fri Jan 4 12:18:52 UTC 2013
Hello Ian,
If you need to set a value you should enable the generation of mutator
methods in your .kcfgc file. To add setters for every property, use
"Mutators=true". To add setters just a few, use
"Mutators=CubeDim,SomeOtherProp". Then you can just call
"Prefs::self()->SetCubeDim( previousCubeDim );" (See [1] for more
details.)
Personally, when I ran into this issue in Killbots, after a fair bit
of experimentation, I opted for a slightly different approach. Instead
of game parameters being pulled directly from KConfig in the game
logic, it is read just at the start of the game and then cached
internally. If the user changes ruleset midgame, they are prompted to
either continue the current game or start a new one with the new rules
(like your suggestion), but the advantage is that we don't need to
overwrite the user's rule selection. It'll just be used the next time
a game is started.
I wouldn't argue that my solution is necessarily better than yours, it
just happens to match what I personally would expect as a user. For
the code in question, see [2].
Hope that helps.
Parker
[1] http://api.kde.org/4.9-api/kdelibs-apidocs/kdecore/html/kconfig_compiler.html
[2] https://projects.kde.org/projects/kde/kdegames/killbots/repository/revisions/master/entry/mainwindow.cpp#L97
On Fri, Jan 4, 2013 at 3:33 AM, Ian Wadham wrote:
> In a board-style game, the size of the board may be a config item. It certainly
> is in KJumpingCube.
>
> If the user changes the board size, it is necessary to clear the board and
> start a new game. I would like to offer the user a chance to override that and
> not automatically lose a game that is in progress if he/she accidentally clicked
> a new board size in the settings dialog generated by KCFG and Qt Designer.
>
> Here is some code that seems to work if I want to put the board size
> back as it was and continue the current game:
>
> ((KConfigSkeleton::ItemInt *) (Prefs::self()->findItem ("CubeDim")))->
> setValue (previousCubeDim);
> Prefs::self()->writeConfig();
>
> Is this OK? It seems a bit hairy to me, i.e. dependent on too many details
> of kdelibs and internals of KCFG, any of which may change in future.
>
> All the best, Ian W.
> _______________________________________________
> kde-games-devel mailing list
> kde-games-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kde-games-devel
More information about the kde-games-devel
mailing list