File indexing completed on 2024-05-05 15:53:05
0001 /* GCompris - explore-level.js 0002 * 0003 * SPDX-FileCopyrightText: 2015 Ayush Agrawal <ayushagrawal288@gmail.com> 0004 * 0005 * Authors: 0006 * Beth Hadley <bethmhadley@gmail.com> (GTK+ version) 0007 * Ayush Agrawal <ayushagrawal288@gmail.com> (Qt Quick port) 0008 * Djalil MESLI <djalilmesli@gmail.com> (Qt Quick port) 0009 * 0010 * SPDX-License-Identifier: GPL-3.0-or-later 0011 */ 0012 0013 .pragma library 0014 .import GCompris 1.0 as GCompris 0015 .import "qrc:/gcompris/src/core/core.js" as Core 0016 0017 var numberOfLevel 0018 var items 0019 var url 0020 0021 function start(items_,url_,levelCount_) { 0022 items = items_ 0023 url = url_ 0024 numberOfLevel = levelCount_ 0025 items.currentLevel = Core.getInitialLevel(numberOfLevel); 0026 items.score.currentSubLevel = 1 0027 0028 initLevel() 0029 } 0030 0031 function stop() { 0032 items.audioVoices.stop() 0033 } 0034 0035 function initLevel() { 0036 items.okButton.visible = false 0037 items.descriptionBonusDone = false 0038 var filename = url + "board" + "/" + "board" + (items.currentLevel + 1) + ".qml" 0039 items.dataset.source = filename 0040 items.progressbar.currentSubLevel = 0 0041 items.progressbar.numberOfSubLevels = items.dataModel.count 0042 items.score.numberOfSubLevels = items.hasAudioQuestions ? 3 : 2; 0043 // randomize the questions for level 2 and 3 0044 items.questionOrder = Array.apply(null, {length: items.dataModel.count}).map(Number.call, Number) 0045 Core.shuffle(items.questionOrder); 0046 0047 // Change the currentSubLevel value to 1 to be sure to update the question value 0048 // else if you are sublevel 0 and go to last level, the question is not the good one 0049 items.progressbar.currentSubLevel = 1 0050 items.progressbar.currentSubLevel = 0 0051 items.descriptionPanel.visible = false 0052 items.instruction.visible = true 0053 items.buttonsBlocked = false 0054 0055 reload(); 0056 } 0057 0058 function nextLevel() { 0059 items.progressbar.stopWinAnimation() 0060 ++items.score.currentSubLevel 0061 if((items.currentLevel + 1) >= numberOfLevel && items.score.numberOfSubLevels < items.score.currentSubLevel) 0062 { 0063 items.currentLevel = -1 0064 } 0065 if (items.score.numberOfSubLevels < items.score.currentSubLevel) { 0066 items.currentLevel ++ 0067 items.score.currentSubLevel = 1 0068 } 0069 initLevel(); 0070 0071 // Stop audio if necessary (switch from level 2 at beginning to a new level for example) 0072 items.audioVoices.stop() 0073 0074 if(items.score.currentSubLevel >= 2) { 0075 items.progressbar.currentSubLevel = 0; 0076 initSubSubLevel(); 0077 } 0078 } 0079 0080 function previousLevel() { 0081 items.progressbar.stopWinAnimation() 0082 --items.score.currentSubLevel 0083 if(items.currentLevel <= 0 && items.score.currentSubLevel < 1) 0084 { 0085 items.currentLevel = numberOfLevel-1 0086 items.score.currentSubLevel = items.score.numberOfSubLevels 0087 } 0088 else if(items.score.currentSubLevel < 1) { 0089 items.currentLevel-- 0090 items.score.currentSubLevel = items.score.numberOfSubLevels 0091 } 0092 initLevel(); 0093 0094 // Stop audio if necessary (switch from level 2 at beginning to a new level for example) 0095 items.audioVoices.stop() 0096 0097 if(items.score.currentSubLevel == 2 && items.hasAudioQuestions) { 0098 repeat(); 0099 } 0100 } 0101 0102 function isComplete() { 0103 for(var i = 0 ; i < items.dataModel.count ; ++ i) { 0104 if(!items.dataModel.itemAt(i).starVisible) 0105 return false; 0106 } 0107 return true; 0108 } 0109 0110 function initSubSubLevel() { 0111 if(items.progressbar.currentSubLevel >= items.dataModel.count) { 0112 items.bonus.good("smiley"); 0113 return 0114 } 0115 items.currentQuestion = getCurrentQuestion(); 0116 0117 if(items.score.currentSubLevel == 2 && items.hasAudioQuestions) { 0118 if(items.bonus.isPlaying) { 0119 items.bonusPlaying = true; 0120 } else { 0121 repeat(); 0122 } 0123 } 0124 items.buttonsBlocked = false; 0125 } 0126 0127 function nextSubSubLevel() { 0128 items.audioVoices.silence(2000) 0129 initSubSubLevel() 0130 } 0131 0132 function reload() { 0133 for(var i = 0 ; i < items.dataModel.count ; ++ i) { 0134 items.dataModel.itemAt(i).starVisible = false; 0135 } 0136 } 0137 0138 function repeat() { 0139 items.audioVoices.stop(); 0140 items.audioVoices.clearQueue(); 0141 items.audioVoices.append(getCurrentQuestion().audio); 0142 } 0143 0144 function getCurrentQuestion() { 0145 return items.dataset.item.tab[items.questionOrder[items.progressbar.currentSubLevel]]; 0146 }