Warning, /education/gcompris/src/activities/gletters/FallingDomino.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - FallingDomino.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Holger Kaelberer <holger.k@elberer.de>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Holger Kaelberer <holger.k@elberer.de> (Qt Quick port)
0008  *
0009  *
0010  *   SPDX-License-Identifier: GPL-3.0-or-later
0011  */
0012 import QtQuick 2.12
0013 import QtGraphicalEffects 1.0
0014 import GCompris 1.0
0015 
0016 import "../../core"
0017 import "gletters.js" as Activity
0018 
0019 Item {
0020     id: word
0021 
0022     width: domino.width
0023     height: domino.height
0024 
0025     /// index into text.split("") where next typed match should occur
0026     property int unmatchedIndex: 0;
0027     property string text
0028     property var dominoValues
0029     property bool wonState: false
0030     property string mode: "dot"
0031 
0032     signal won
0033 
0034     onWon: {
0035         wonState = true
0036         particle.burst(30)
0037         fadeout.restart();
0038     }
0039 
0040     Component.onCompleted: {
0041         // make sure our word is completely visible
0042         if (x + width >= parent.width)
0043             x = parent.width - width;
0044     }
0045 
0046     PropertyAnimation {
0047         id: fadeout
0048         target: word;
0049         property: "opacity"
0050         to: 0
0051         duration: 1000
0052 
0053         onStopped: Activity.deleteWord(word);
0054     }
0055 
0056     function checkMatch(c)
0057     {
0058         // We are in the ending animation
0059         if (wonState)
0060             return
0061 
0062         var chars = text.split("");
0063         if (chars[unmatchedIndex] === c) {
0064             unmatchedIndex++;
0065             return true;
0066         } else {
0067             unmatchedIndex = 0;
0068             return false;
0069         }
0070     }
0071 
0072     function startMoving(dur)
0073     {
0074         down.duration = dur;
0075         down.restart();
0076     }
0077 
0078     function isCompleted()
0079     {
0080         return (unmatchedIndex === text.length);
0081     }
0082 
0083     Domino {
0084         id: domino
0085         width: 120 * ApplicationInfo.ratio
0086         height: width / 2
0087         mode: word.mode
0088         visible: dominoValues.length != 0
0089         value1: dominoValues[0]
0090         value2: dominoValues[1]
0091         isClickable: false
0092 
0093         ParticleSystemStarLoader {
0094             id: particle
0095             clip: false
0096         }
0097     }
0098 
0099     NumberAnimation {
0100         id: down
0101         target: word
0102         property: "y"
0103         to: parent.height
0104         duration: 10000
0105 
0106         onStopped: {
0107             Activity.audioCrashPlay();
0108             Activity.appendRandomWord(word.text)
0109             Activity.deleteWord(word);
0110         }
0111     }
0112 }