summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Wadham <[email protected]>2015-11-01 10:49:05 +1100
committerIan Wadham <[email protected]>2015-11-09 14:34:00 +1100
commit015645c66433300924273686b06d7e7cc5c6ad9d (patch)
tree2ccf1495194034a2c3062f2a6428a4c87b586f8d
parentf04dc6f196565a11ad7855b3244325f75096c2f3 (diff)
Set Hero's dig-while-falling option from game-files (default = true).
-rw-r--r--src/kgrgame.cpp26
-rw-r--r--src/kgrlevelplayer.cpp1
2 files changed, 21 insertions, 6 deletions
diff --git a/src/kgrgame.cpp b/src/kgrgame.cpp
index 6df5cb2..2e894b1 100644
--- a/src/kgrgame.cpp
+++ b/src/kgrgame.cpp
@@ -2075,8 +2075,11 @@ bool KGrGame::initRecordingData (const Owner fileOwner, const QString & prefix,
else {
KGrGameIO io (view);
KGrLevelData levelData;
+ KGrGameData * gameData = gameList.at (gameIndex);
- // Read the level data.
+ // Set digWhileFalling same as game, by default: read the level data.
+ // The dig-while-falling setting can be overridden for a single level.
+ levelData.digWhileFalling = gameData->digWhileFalling;
if (! io.readLevelData (dir, prefix, levelNo, levelData)) {
return false;
}
@@ -2086,7 +2089,6 @@ bool KGrGame::initRecordingData (const Owner fileOwner, const QString & prefix,
.toString (Qt::ISODate);
// kDebug() << "Recording at" << recording->dateTime;
- KGrGameData * gameData = gameList.at (gameIndex);
recording->owner = gameData->owner;
recording->rules = gameData->rules;
recording->prefix = gameData->prefix;
@@ -2097,8 +2099,8 @@ bool KGrGame::initRecordingData (const Owner fileOwner, const QString & prefix,
recording->height = levelData.height;
recording->layout = levelData.layout;
- // Record whether this level will allow the hero to dig while falling.
- recording->digWhileFalling = levelData.digWhileFalling;
+ // Record whether this level will allow the hero to dig while falling.
+ recording->digWhileFalling = levelData.digWhileFalling;
// If there is a name or hint, translate the UTF-8 code right now.
recording->levelName = (levelData.name.size() > 0) ?
@@ -2211,6 +2213,8 @@ bool KGrGame::loadRecording (const QString & dir, const QString & prefix,
// If demoType is DEMO or SOLVE, get the TRANSLATED gameName, levelName and
// hint from current data (other recordings have been translated already).
+ // Also get the CURRENT setting of digWhileFalling for this game and level
+ // (in case the demo or solution file contains out-of-date settings).
if ((demoType == DEMO) || (demoType == SOLVE)) {
int index = -1;
for (int i = 0; i < gameList.count(); i++) { // Find the game.
@@ -2220,15 +2224,21 @@ bool KGrGame::loadRecording (const QString & dir, const QString & prefix,
}
}
if (index >= 0) {
- // Get the current translation of the name of the game.
+ // Get digWhileFalling flag and current translation of name of game.
+ recording->digWhileFalling = gameList.at (index)->digWhileFalling;
recording->gameName = gameList.at (index)->name;
+ // kDebug() << "GAME" << gameList.at (index)->name << levelNo
+ // << "set digWhileFalling to"
+ // << gameList.at (index)->digWhileFalling;
// Read the current level data.
KGrGameIO io (view);
KGrLevelData levelData;
- QString levelDir = (gameList.at (index)->owner == USER) ?
+ QString levelDir = (gameList.at (index)->owner == USER) ?
userDataDir : systemDataDir;
+ // Set digWhileFalling same as game, by default.
+ levelData.digWhileFalling = gameList.at (index)->digWhileFalling;
if (io.readLevelData (levelDir, recording->prefix, recording->level,
levelData)) {
// If there is a level name or hint, translate it.
@@ -2236,6 +2246,10 @@ bool KGrGame::loadRecording (const QString & dir, const QString & prefix,
i18n (levelData.name.constData()) : "";
recording->hint = (levelData.hint.size() > 0) ?
i18n (levelData.hint.constData()) : "";
+ recording->digWhileFalling = levelData.digWhileFalling;
+ // kDebug() << "LEVEL" << gameList.at (index)->name << levelNo
+ // << "digWhileFalling is NOW"
+ // << levelData.digWhileFalling;
}
}
}
diff --git a/src/kgrlevelplayer.cpp b/src/kgrlevelplayer.cpp
index 96d2ab9..461722e 100644
--- a/src/kgrlevelplayer.cpp
+++ b/src/kgrlevelplayer.cpp
@@ -193,6 +193,7 @@ void KGrLevelPlayer::init (KGrView * view,
heroId = emit makeSprite (HERO, i, j);
hero = new KGrHero (this, grid, i, j, heroId, rules);
hero->setNuggets (nuggets);
+ hero->setDigWhileFalling (recording->digWhileFalling);
if ((controlMode == MOUSE) || (controlMode == LAPTOP)) {
emit setMousePos (targetI, targetJ);
}