Difference between revisions of "Projects/Games/Porting to libkdegames v5"

(Moved to Community Wiki)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This document describes the changes introduced with libkdegames v5, which first appeared in the KDE 4.9 release.
+
{{Moved_To_Community|Projects/Games/Porting_to_libkdegames_v5}}
 
 
== New components ==
 
 
 
* '''KgSound''' provides a simple API for playback of short event sounds. Low latency is achieved through the use of OpenAL, with a Phonon fallback if the required libraries are not available.
 
 
 
Also, multiple new components have been added which replace existing components. These can be identified by the common class name prefix "Kg". See [[#Reworked components|Reworked components]] for details.
 
 
 
== Removed components ==
 
 
 
* The '''KGGZ''' framework has been removed completely.
 
* '''KGameLCD''' — Use QLCDNumber instead.
 
* '''KGameMisc''' — Instead of a random name, we advise to use generic names where appropriate.
 
* '''KGameProgress''' — Use QProgressBar instead.
 
* '''KGameSvgDigits''' — If you need SVG digits, include them in your own SVG theme.
 
* '''KGrid2D''' — You'll need to do the math yourself.
 
 
 
== Reworked components ==
 
 
 
=== Difficulty ===
 
 
 
'''KGameDifficulty''' has been replaced by the '''KgDifficulty''' and '''KgDifficultyLevel''' classes. KgDifficulty stores the current level by itself, and allows for multiple KgDifficulty instances at the same time, although a singleton is provided by the Kg::difficulty() function. The following table shows how to port common uses of KGameDifficulty to this singleton:
 
 
 
{| border="1" cellpadding="5" cellspacing="0" style="border: gray solid 1px; border-collapse: collapse; text-align: left; width:100%;"
 
|- style="background: #ececec; white-space:nowrap;"
 
! Replace this...
 
! ...by this
 
! Comment
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::standardLevel</tt>
 
| style="white-space:nowrap" | <tt>KgDifficultyLevel::StandardLevel</tt>
 
|
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::Medium etc.</tt>
 
| style="white-space:nowrap" | <tt>KgDifficultyLevel::Medium etc.</tt>
 
|
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::addStandardLevel(level)</tt>
 
| style="white-space:nowrap" | <tt>Kg::difficulty()->addStandardLevel(level)</tt>
 
| As a convenience, consider to use the new <tt>addStandardLevelRange()</tt> method.
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| rowspan="2" style="white-space:nowrap" | <tt>KGameDifficulty::init<br/>(window, receiver, slot)</tt>
 
| style="white-space:nowrap" | <tt>KgDifficultyGUI::init(window);</tt>
 
|
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>QObject::connect(Kg::difficulty(),<br/>SLOT(currentLevelChanged(const KgDifficultyLevel*)),<br/>receiver, slot);</tt>
 
| Change the slot to the new signature. The old signature contained a standard level argument: Use the "standardLevel" property of the new argument instead.
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::level()</tt>
 
| style="white-space:nowrap" | <tt>Kg::difficultyLevel()</tt>
 
|
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::setLevel(level)</tt>
 
| style="white-space:nowrap" | <tt>Kg::difficulty()->select(level)</tt>
 
| If used to restore the selected difficulty from the config file, delete the whole call and your custom config key. KgDifficulty remembers the level selection by itself. Please refer to the APIDOX for details, e.g. how to specify a default difficulty for the first run.
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::levelWeights(),<br />KGameDifficulty::localizedLevelStrings(),</tt><br/>etc. while setting up a KScoreDialog
 
| style="white-space:nowrap" | <tt>dialog->initFromDifficulty(Kg::difficulty());</tt>
 
| If you need the QMaps from these KGameDifficulty functions, you can construct them by iterating over the <tt>KgDifficultyLevel</tt>s. <tt>levelWeights</tt> maps <tt>hardness-&gt;key</tt> and <tt>localizedLevelStrings</tt> maps <tt>key-&gt;title</tt>.
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::setRestartOnChange(roc)</tt>
 
| rowspan="2" style="white-space:nowrap" | <tt>Kg::difficulty()->setGameRunning(roc && running)</tt>
 
| rowspan="2" | These two properties of KGameDifficulty are redundant: If both are true, the user will be asked for confirmation before the level is changed. If you do not want this, just do not use the <tt>setGameRunning</tt> method.
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::setRunning(running)</tt>
 
|- style="border:gray solid 1px; border-collapse: collapse;"
 
| style="white-space:nowrap" | <tt>KGameDifficulty::setEnabled()</tt>
 
| style="white-space:nowrap" | <tt>Kg::difficulty()->setEditable()</tt>
 
| The property has been renamed to clarify its purpose.
 
|}
 

Latest revision as of 13:14, 7 June 2019

This page is now on the community wiki.


This page was last edited on 7 June 2019, at 13:14. Content is available under Creative Commons License SA 4.0 unless otherwise noted.