[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [gcompris/gsoc_pulkit_digital_electricity] src/activities/digital_electricity: digital_electricity: 
From:       Rudra Nil Basu <null () kde ! org>
Date:       2017-08-18 20:53:06
Message-ID: E1dioGQ-0001K1-7W () code ! kde ! org
[Download RAW message or body]

Git commit 0a79ffcc672194602792e0a2f0141d249f4b7d53 by Rudra Nil Basu.
Committed on 18/08/2017 at 20:27.
Pushed by rudranilbasu into branch 'gsoc_pulkit_digital_electricity'.

digital_electricity: Fix OK button skipping levels

The OK button was checking for the answer and if correct, the level was
changed after showing a "happy tux" image. However, once we press the OK
button for the same correct answer twice, the answer was calculated
twice and because of the delay between deciding the answer and changing
the level, the "happy tux" was shown twice and as a result a level was
skipped. This is avoided by keeping a variable "processingAnswer" to
check whether the answer is being checked or not. If yes, we do not
evaluate the OK click

  if (processingAnswer)
      return

If the calculated result is a wrong answer, the value of
processingAnswer is reset to its default value (false). If it is true,
we transition to the next level, and the value of processingAnswer is
marked false in the "initLevel()" method.

Fixed level 20 being incorrectly put in the "others" problem type, which
should be under the "problemType.equation2Variables" group, since it
deals with comparing two variables represented as switches.

Signed-off-by: Rudra Nil Basu <rudra.nil.basu.1996@gmail.com>

M  +1    -1    src/activities/digital_electricity/Dataset.qml
M  +20   -33   src/activities/digital_electricity/digital_electricity.js

https://commits.kde.org/gcompris/0a79ffcc672194602792e0a2f0141d249f4b7d53

diff --git a/src/activities/digital_electricity/Dataset.qml \
b/src/activities/digital_electricity/Dataset.qml index 52dcaee6..937c037f 100644
--- a/src/activities/digital_electricity/Dataset.qml
+++ b/src/activities/digital_electricity/Dataset.qml
@@ -406,7 +406,7 @@ QtObject {
             wires: [  ],
             playAreaComponentPositionX: [0.0, 0.0, 0.4, 0.9],
             playAreaComponentPositionY: [0.2, 0.4, 0.5, 0.5],
-            type: [problemType.others],
+            type: [problemType.equation2Variables],
             introMessage: [
                 qsTr("A comparator takes two numbers (A and B) as input and produces \
3 values as output. First value is 1 if A < B, second value is 1 for A = B and third \
value is 1 for A > B."),  qsTr("Create a circuit using the components provided such \
that the bulb will glow when the value of the current flowing through the first \
                switch is less than or equal to that of the second switch.")
diff --git a/src/activities/digital_electricity/digital_electricity.js \
b/src/activities/digital_electricity/digital_electricity.js index 7b674290..cce53fae \
                100644
--- a/src/activities/digital_electricity/digital_electricity.js
+++ b/src/activities/digital_electricity/digital_electricity.js
@@ -35,6 +35,7 @@ var deletedIndex = []
 var components = []
 var connected = []
 var determiningComponents = []
+var processingAnswer
 
 function start(items_) {
 
@@ -80,6 +81,7 @@ function initLevel() {
         loadFreeMode(sizeMultiplier)
     } else {
         // load tutorial levels from dataset
+        processingAnswer = false
         var levelProperties = items.tutorialDataset.tutorialLevels[currentLevel - 1]
 
         for (var i = 0; i < levelProperties.inputComponentList.length; i++) {
@@ -154,13 +156,19 @@ function isTutorialMode() {
 }
 
 function checkAnswer() {
+    if (processingAnswer)
+        return
+
+    processingAnswer = true
     var problemType = items.tutorialDataset.tutorialLevels[currentLevel - 1].type
 
     if (problemType == items.tutorialDataset.problemType.lightTheBulb) {
-        if (determiningComponents[0].inputTerminals.itemAt(0).value == 1)
+        if (determiningComponents[0].inputTerminals.itemAt(0).value == 1) {
             items.bonus.good('tux')
-        else
+        } else {
             items.bonus.bad('tux')
+            processingAnswer = false
+        }
     } else if (problemType == items.tutorialDataset.problemType.equation1Variable) {
         var switch1 = determiningComponents[0]
 
@@ -179,6 +187,7 @@ function checkAnswer() {
                 switch1.imgSrc = switch1InitialState
                 updateComponent(switch1.index)
                 items.bonus.bad('tux')
+                processingAnswer = false
                 return
             }
         }
@@ -210,6 +219,8 @@ function checkAnswer() {
                     operationResult = !(A | B)
                 } else if (currentLevel == 19) {
                     operationResult = !(A & B)
+                } else if (currentLevel == 20) {
+                    operationResult = (A <= B)
                 }
 
                 if (operationResult != digitalLight.inputTerminals.itemAt(0).value) \
{ @@ -218,6 +229,7 @@ function checkAnswer() {
                     updateComponent(switch1.index)
                     updateComponent(switch2.index)
                     items.bonus.bad('tux')
+                    processingAnswer = false
                     return
                 }
             }
@@ -259,6 +271,7 @@ function checkAnswer() {
                         updateComponent(switch1.index)
                         updateComponent(switch2.index)
                         updateComponent(switch3.index)
+                        processingAnswer = false
                         items.bonus.bad('tux')
                         return
                     }
@@ -267,37 +280,7 @@ function checkAnswer() {
         }
         items.bonus.good('tux')
     } else if (problemType == items.tutorialDataset.problemType.others) {
-        if (currentLevel == 20) {
-                var switch1 = determiningComponents[0]
-                var switch2 = determiningComponents[1]
-
-                var digitalLight = determiningComponents[2]
-
-                var switch1InitialState = switch1.imgSrc
-                var switch2InitialState = switch2.imgSrc
-
-                for (var A = 0; A <= 1; A++) {
-                    for (var B = 0; B <= 1; B++) {
-                        switch1.imgSrc = A == 1 ? "switchOn.svg" : "switchOff.svg"
-                        switch2.imgSrc = B == 1 ? "switchOn.svg" : "switchOff.svg"
-
-                        updateComponent(switch1.index)
-                        updateComponent(switch2.index)
-
-                        var operationResult = A <= B
-
-                        if (operationResult != \
                digitalLight.inputTerminals.itemAt(0).value) {
-                            switch1.imgSrc = switch1InitialState
-                            switch2.imgSrc = switch2InitialState
-                            updateComponent(switch1.index)
-                            updateComponent(switch2.index)
-                            items.bonus.bad('tux')
-                            return
-                        }
-                    }
-                }
-                items.bonus.good('tux')
-        } else if (currentLevel == 21) {
+        if (currentLevel == 21) {
             var bcdToSevenSegment = determiningComponents[0]
 
             var decimalValue =
@@ -311,6 +294,8 @@ function checkAnswer() {
                 return
             }
             items.bonus.bad('tux')
+            processingAnswer = false
+            return
         } else if (currentLevel == 22) {
             var bcdCounter = determiningComponents[0]
 
@@ -332,6 +317,7 @@ function checkAnswer() {
                     bcdCounter.outputTerminals.itemAt(2).wires.length == 0 ||
                     bcdCounter.outputTerminals.itemAt(3).wires.length == 0) {
                 items.bonus.bad('tux')
+                processingAnswer = false
                 return
             }
             if ((bcdOutput == digitalLightOutput) && \
(bcdCounter.inputTerminals.itemAt(0).wires.length != 0) ) { @@ -339,6 +325,7 @@ \
function checkAnswer() {  return
             }
             items.bonus.bad('tux')
+            processingAnswer = false
         }
     }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic