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

0001 /* GCompris - chess.qml
0002  *
0003  * SPDX-FileCopyrightText: 2015 Bruno Coudoin <bruno.coudoin@gcompris.net>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port)
0008  *
0009  *   SPDX-License-Identifier: GPL-3.0-or-later
0010  */
0011 import QtQuick 2.12
0012 
0013 Image {
0014     id: piece
0015     property int pos
0016     Behavior on opacity { PropertyAnimation { easing.type: Easing.InOutQuad; duration: 200 } }
0017     Behavior on x { PropertyAnimation { easing.type: Easing.InOutQuad; duration: items.noPieceAnimation ? 0 : 200 } }
0018     Behavior on y { PropertyAnimation { easing.type: Easing.InOutQuad; duration: items.noPieceAnimation ? 0 : 200 } }
0019     z: 10
0020 
0021     property string img
0022     property bool acceptMove: false
0023     property int newPos
0024     // color = -1 if no piece, 0 is black and 1 is white
0025     property int isWhite: img[0] == 'w' ? 1 : img[0] == 'b' ? 0 : -1
0026 
0027     onImgChanged: {
0028         if(img == 'W')
0029             img = 'wk'
0030         else if(img == 'B')
0031             img = 'bk'
0032     }
0033 
0034     SequentialAnimation {
0035         id: hideAnim
0036         NumberAnimation {
0037             target: piece
0038             property: "scale"
0039             duration: 200
0040             to: 0
0041         }
0042         PropertyAction {
0043              target: piece
0044              property: 'img'
0045              value: ""
0046         }
0047         PropertyAction {
0048             target: piece
0049             property: 'pos'
0050             value: piece.newPos
0051         }
0052         PropertyAction {
0053             target: piece
0054             property: 'scale'
0055             value: 1
0056         }
0057         PropertyAction {
0058             target: piece
0059             property: 'z'
0060             value: 2
0061         }
0062     }
0063 
0064     SequentialAnimation {
0065         id: promotionAnim
0066         PauseAnimation {
0067             duration: 200
0068         }
0069         NumberAnimation {
0070             target: piece
0071             property: 'scale'
0072             to: 0
0073         }
0074         PropertyAction {
0075             target: piece
0076             property: 'img'
0077             value: isWhite ? 'wk' : 'bk'
0078         }
0079         NumberAnimation {
0080             target: piece
0081             property: 'scale'
0082             to: 1
0083             easing.type: Easing.OutElastic
0084         }
0085     }
0086 
0087     function hide(newPos) {
0088         piece.newPos = newPos
0089         hideAnim.start()
0090     }
0091 
0092     function promotion() {
0093         promotionAnim.start()
0094     }
0095 
0096     function move(to) {
0097         piece.newPos = to
0098         piece.pos = to
0099         piece.z = 2
0100     }
0101 }
0102