Changeset View
Changeset View
Standalone View
Standalone View
src/activities/scalesboard/scalesboard.js
Show All 28 Lines | |||||
29 | var numberOfLevel | 29 | var numberOfLevel | ||
30 | var items | 30 | var items | ||
31 | var currentTargets = [] | 31 | var currentTargets = [] | ||
32 | var initCompleted = false | 32 | var initCompleted = false | ||
33 | 33 | | |||
34 | function start(items_) { | 34 | function start(items_) { | ||
35 | items = items_ | 35 | items = items_ | ||
36 | currentLevel = 0 | 36 | currentLevel = 0 | ||
37 | numberOfLevel = items.dataset.length | 37 | numberOfLevel = items.levels.length | ||
38 | initLevel() | 38 | initLevel() | ||
39 | } | 39 | } | ||
40 | 40 | | |||
41 | function stop() { | 41 | function stop() { | ||
42 | } | 42 | } | ||
43 | 43 | | |||
44 | function initLevel() { | 44 | function initLevel() { | ||
45 | items.bar.level = currentLevel + 1 | 45 | items.bar.level = currentLevel + 1 | ||
46 | currentTargets = Core.shuffle(items.dataset[currentLevel].targets) | 46 | currentTargets = Core.shuffle(items.levels[currentLevel].targets) | ||
47 | items.currentSubLevel = 1 | 47 | items.currentSubLevel = 1 | ||
48 | items.numberOfSubLevels = currentTargets.length | 48 | items.numberOfSubLevels = currentTargets.length | ||
49 | items.rightDrop = items.levels[currentLevel].rightDrop | ||||
50 | items.question.text = items.levels[currentLevel].question != undefined ? items.levels[currentLevel].question : "" | ||||
49 | displayLevel() | 51 | displayLevel() | ||
50 | } | 52 | } | ||
51 | 53 | | |||
52 | function displayLevel() | 54 | function displayLevel() | ||
53 | { | 55 | { | ||
54 | 56 | | |||
55 | initCompleted = false | 57 | initCompleted = false | ||
56 | items.numpad.answer = "" | 58 | items.numpad.answer = "" | ||
57 | items.masseAreaLeft.init() | 59 | items.masseAreaLeft.init() | ||
58 | items.masseAreaRight.init() | 60 | items.masseAreaRight.init() | ||
59 | items.masseAreaCenter.init() | 61 | items.masseAreaCenter.init() | ||
60 | var data = items.dataset[currentLevel] | 62 | var data = items.levels[currentLevel] | ||
61 | for(var i=0; i < data.masses.length; i++) | 63 | for(var i=0; i < data.masses.length; i++) | ||
62 | items.masseAreaCenter.addMasse("masse" + (i % 5 + 1) + ".svg", | 64 | items.masseAreaCenter.addMasse("masse" + (i % 5 + 1) + ".svg", | ||
63 | data.masses[i][0], | 65 | data.masses[i][0], | ||
64 | data.masses[i][1], | 66 | data.masses[i][1], | ||
65 | i, | 67 | i, | ||
66 | /* dragEnabled */ true) | 68 | /* dragEnabled */ true) | ||
67 | 69 | | |||
68 | items.giftWeight = currentTargets[items.currentSubLevel - 1][0] | 70 | items.giftWeight = currentTargets[items.currentSubLevel - 1][0] | ||
69 | items.masseAreaRight.addMasse("gift.svg", | 71 | items.masseAreaRight.addMasse("gift.svg", | ||
70 | currentTargets[items.currentSubLevel - 1][0], | 72 | currentTargets[items.currentSubLevel - 1][0], | ||
71 | data.question ? "" : currentTargets[items.currentSubLevel - 1][1], | 73 | data.question ? "" : currentTargets[items.currentSubLevel - 1][1], | ||
72 | 0, | 74 | 0, | ||
73 | /* dragEnabled */ false) | 75 | /* dragEnabled */ false) | ||
74 | 76 | | |||
75 | initCompleted = true | 77 | initCompleted = true | ||
76 | } | 78 | } | ||
77 | 79 | | |||
80 | function checkAnswer() { | ||||
81 | if((initCompleted && items.scaleHeight == 0 && !items.question.visible) | ||||
jjazeix: items.question.hasText is a boolean, it would be better to check with true or false | |||||
Why do we need initCompleted here? Is displayLevel so slow that we it is possible for the user to click on ok button before displayLevel is executed? Just a question for my own knowledge :) echarruau: Why do we need initCompleted here? Is displayLevel so slow that we it is possible for the user… | |||||
@echarruau I think just to check that the level has been displayed properly or not. As it is a boolean used in the function displaylevel() and it is true after all the items of the level has been loaded. dekumar: @echarruau I think just to check that the level has been displayed properly or not. As it is a… | |||||
82 | || (items.question.userEntry == items.question.answer)) { | ||||
83 | items.bonus.good("flower") | ||||
84 | } | ||||
85 | else { | ||||
86 | items.bonus.bad("flower") | ||||
87 | } | ||||
88 | } | ||||
89 | | ||||
78 | function nextSubLevel() { | 90 | function nextSubLevel() { | ||
79 | if(items.numberOfSubLevels < ++items.currentSubLevel ) { | 91 | if(items.numberOfSubLevels < ++items.currentSubLevel ) { | ||
80 | nextLevel(); | 92 | nextLevel(); | ||
81 | } | 93 | } | ||
82 | displayLevel() | 94 | displayLevel() | ||
83 | } | 95 | } | ||
84 | 96 | | |||
85 | function nextLevel() { | 97 | function nextLevel() { | ||
Show All 12 Lines |
items.question.hasText is a boolean, it would be better to check with true or false