File indexing completed on 2024-04-28 15:07:47
0001 /* GCompris - colormix.js' 0002 * 0003 * SPDX-FileCopyrightText: 2014 Stephane Mankowski <stephane@mankowski.fr> 0004 * 0005 * Authors: 0006 * Matilda Bernard <serah4291@gmail.com> (GTK+ version) 0007 * Stephane Mankowski <stephane@mankowski.fr> (Qt Quick port) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 .import "qrc:/gcompris/src/core/core.js" as Core 0012 0013 var url = "qrc:/gcompris/src/activities/color_mix/resource/" 0014 0015 var numberOfLevel = 6 0016 var items 0017 var maxSteps = 1 0018 0019 function start(items_) { 0020 items = items_ 0021 items.currentLevel = Core.getInitialLevel(numberOfLevel) 0022 items.score.numberOfSubLevels = 6 0023 items.score.currentSubLevel = 0 0024 initLevel() 0025 } 0026 0027 function stop() {} 0028 0029 function initLevel() { 0030 0031 /* Set max steps */ 0032 maxSteps = items.currentLevel + 1 0033 items.maxSteps = maxSteps 0034 0035 /* Compute target color */ 0036 items.targetColor1 = Math.floor(Math.random() * (maxSteps + 1)) 0037 items.targetColor2 = Math.floor(Math.random() * (maxSteps + 1)) 0038 items.targetColor3 = Math.floor(Math.random() * (maxSteps + 1)) 0039 0040 /* Reset current color */ 0041 items.currentColor1 = 0 0042 items.currentColor2 = 0 0043 items.currentColor3 = 0 0044 0045 /* Enable controls */ 0046 items.buttonsBlocked = false 0047 } 0048 0049 function getColor(i1, i2, i3) { 0050 return activity.modeRGB ? Qt.rgba(i1 / maxSteps, i2 / maxSteps, 0051 i3 / maxSteps, 0052 1) : Qt.rgba(1 - i3 / maxSteps, 0053 1 - i1 / maxSteps, 0054 1 - i2 / maxSteps, 1) 0055 } 0056 0057 function nextSubLevel() { 0058 if (items.score.numberOfSubLevels > items.score.currentSubLevel) { 0059 initLevel() 0060 } else { 0061 items.bonus.good("gnu") 0062 } 0063 } 0064 0065 function nextLevel() { 0066 items.score.stopWinAnimation() 0067 items.score.currentSubLevel = 0 0068 0069 items.currentLevel = Core.getNextLevel(items.currentLevel, numberOfLevel); 0070 initLevel() 0071 } 0072 0073 function previousLevel() { 0074 items.score.stopWinAnimation() 0075 items.score.currentSubLevel = 0 0076 items.currentLevel = Core.getPreviousLevel(items.currentLevel, numberOfLevel); 0077 initLevel() 0078 }