Warning, /education/gcompris/src/activities/submarine/BallastTank.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - BallastTank.qml 0002 * 0003 * SPDX-FileCopyrightText: 2017 RUDRA NIL BASU <rudra.nil.basu.1996@gmail.com> 0004 * 0005 * Authors: 0006 * Pascal Georges <pascal.georges1@free.fr> (GTK+ version) 0007 * Rudra Nil Basu <rudra.nil.basu.1996@gmail.com> (Qt Quick port) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 0012 import QtQuick 2.12 0013 0014 Item { 0015 property int initialWaterLevel: 0 0016 property int waterLevel: 0 0017 property int maxWaterLevel: 500 0018 property int waterRate: 100 0019 property bool waterFilling: false 0020 property bool waterFlushing: false 0021 0022 signal stop 0023 0024 Component.onCompleted: { 0025 activity.stop.connect(stop); 0026 } 0027 0028 onStop: { 0029 fillBallastTanks.stop(); 0030 flushBallastTanks.stop(); 0031 } 0032 0033 function fillBallastTanks() { 0034 waterFilling = !waterFilling 0035 } 0036 0037 function flushBallastTanks() { 0038 waterFlushing = !waterFlushing 0039 } 0040 0041 function updateWaterLevel(isInflow) { 0042 if (isInflow) { 0043 if (waterLevel < maxWaterLevel) { 0044 waterLevel += waterRate 0045 0046 } 0047 } else { 0048 if (waterLevel > 0) { 0049 waterLevel -= waterRate 0050 } 0051 } 0052 0053 if (waterLevel > maxWaterLevel) { 0054 waterLevel = maxWaterLevel 0055 } 0056 0057 if (waterLevel < 0) { 0058 waterLevel = 0 0059 } 0060 } 0061 0062 function resetBallastTanks() { 0063 waterFilling = false 0064 waterFlushing = false 0065 0066 waterLevel = initialWaterLevel 0067 } 0068 0069 Timer { 0070 id: fillBallastTanks 0071 interval: 500 0072 running: waterFilling && !waterFlushing 0073 repeat: true 0074 0075 onTriggered: updateWaterLevel(true) 0076 } 0077 0078 Timer { 0079 id: flushBallastTanks 0080 interval: 500 0081 running: waterFlushing && !waterFilling 0082 repeat: true 0083 0084 onTriggered: updateWaterLevel(false) 0085 } 0086 }