Commit ea84fbcf authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

explore, simplified code

Better use of dynamic nature of Qml.
parent 9e3a5c3a
......@@ -38,6 +38,7 @@ Item {
property real animalHeight: animalHeight
property alias starVisible: star.visible
property int questionId
property string title
property string description
property string imageSource
......@@ -93,21 +94,14 @@ Item {
onStartedChanged: started ? retouch.start() : retouch.stop()
onPressed: {
var questionTargetId = items.questionOrder[Activity.items.score.currentSubLevel]
Activity.items.instruction.visible = false
if (Activity.items.currentLevel == 0) {
audioEffects.play(animal.audio);
displayDescription(animal)
star.visible = true;
} else if (Activity.items.currentLevel == 1 && Activity.items.hasAudioQuestions) {
if (Activity.getCurrentQuestion().audio == animal.audio) {
animWin.start();
items.bonus.good("smiley");
Activity.nextSubLevel();
} else {
items.bonus.bad("smiley")
}
} else {
if (items.questionText.text == animal.question) {
if (questionId === questionTargetId) {
animWin.start();
items.bonus.good("smiley");
Activity.nextSubLevel();
......
......@@ -101,6 +101,8 @@ ActivityBase {
property bool hasAudioQuestions: activity.hasAudioQuestions
property int currentLevel
property string currentAudio
property var questionOrder
property var currentQuestion: activity.dataset.tab[items.questionOrder[score.currentSubLevel]]
}
onStart: { Activity.start(items, dataset) }
......@@ -114,6 +116,7 @@ ActivityBase {
id: dataModel
model: dataset.tab.length
Animals {
questionId: index
animalSource: dataset.tab[index].image
xA: background.playX + background.playWidth * dataset.tab[index].x - animalWidth / 2
yA: background.playY + background.playHeight * dataset.tab[index].y - animalHeight / 2
......@@ -184,11 +187,11 @@ ActivityBase {
id: question
width: parent.width * 0.9
height: questionText.height
color: "lightgray"
color: '#CCCCCCCC'
radius: 10
border.width: 3
border.color: "black"
opacity: 0
visible: items.currentLevel == 2 || (items.currentLevel == 1 && !items.hasAudioQuestions)
anchors {
top: instruction.visible ? instruction.bottom : parent.top
horizontalCenter: parent.horizontalCenter
......@@ -202,6 +205,7 @@ ActivityBase {
color: "black"
width: parent.width
wrapMode: Text.Wrap
text: items.currentQuestion.text2
}
}
......@@ -209,7 +213,7 @@ ActivityBase {
id: instruction
width: parent.width * 0.9
height: instructionText.height
color: "lightgray"
color: "#CCCCCCCC"
radius: 10
border.width: 3
border.color: "black"
......@@ -227,6 +231,7 @@ ActivityBase {
color: "black"
width: parent.width
wrapMode: Text.Wrap
text: activity.dataset.instruction[items.currentLevel].text
}
MouseArea {
anchors.fill: parent
......
......@@ -28,8 +28,6 @@ var numberOfLevel
var items
var dataset
var questionOrder
function start(items_,var_) {
items = items_
dataset = var_
......@@ -38,7 +36,7 @@ function start(items_,var_) {
items.score.numberOfSubLevels = items.dataModel.count
numberOfLevel = items.hasAudioQuestions ? 3 : 2;
// create table of size N filled with numbers from 0 to N
questionOrder = Array.apply(null, {length: items.dataModel.count}).map(Number.call, Number)
items.questionOrder = Array.apply(null, {length: items.dataModel.count}).map(Number.call, Number)
initLevel()
}
......@@ -50,7 +48,7 @@ function stop() {
function initLevel() {
items.bar.level = items.currentLevel + 1
// randomize the questions for level 2 and 3
Core.shuffle(questionOrder);
Core.shuffle(items.questionOrder);
items.score.currentSubLevel = 0
items.descriptionPanel.visible = false
......@@ -59,9 +57,6 @@ function initLevel() {
items.instruction.visible = true
reload();
changeOpacity();
setQuestionText();
setInstruction();
}
function nextLevel() {
......@@ -70,8 +65,8 @@ function nextLevel() {
}
initLevel();
if (items.currentLevel == 1) {
items.score.currentSubLevel --;
nextSubLevel();
items.score.currentSubLevel = 0;
initSubLevel();
}
}
......@@ -94,8 +89,7 @@ function isComplete() {
return true;
}
function nextSubLevel() {
items.score.currentSubLevel ++;
function initSubLevel() {
if(items.score.currentSubLevel == items.dataModel.count) {
items.bonus.good("smiley");
items.score.currentSubLevel = 0;
......@@ -104,9 +98,11 @@ function nextSubLevel() {
else if(items.currentLevel == 1 && items.hasAudioQuestions) {
items.audioEffects.play(getCurrentQuestion().audio);
}
else if(items.currentLevel != 0) {
setQuestionText();
}
}
function nextSubLevel() {
items.score.currentSubLevel ++;
initSubLevel()
}
function reload() {
......@@ -119,25 +115,6 @@ function repeat() {
items.audioEffects.play(getCurrentQuestion().audio);
}
function changeOpacity() {
if (items.currentLevel == 2 || (items.currentLevel == 1 && !items.hasAudioQuestions)) {
items.question.opacity = 0.8;
items.questionText.opacity = 1;
}
else {
items.question.opacity = 0;
items.questionText.opacity = 0;
}
}
function getCurrentQuestion() {
return dataset.tab[questionOrder[items.score.currentSubLevel]];
}
function setQuestionText() {
items.questionText.text = getCurrentQuestion().text2;
}
function setInstruction() {
items.instructionText.text = dataset.instruction[items.currentLevel].text
return dataset.tab[items.questionOrder[items.score.currentSubLevel]];
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment