summaryrefslogtreecommitdiff
path: root/qml/Functions.qml
diff options
context:
space:
mode:
Diffstat (limited to 'qml/Functions.qml')
-rw-r--r--qml/Functions.qml25
1 files changed, 25 insertions, 0 deletions
diff --git a/qml/Functions.qml b/qml/Functions.qml
new file mode 100644
index 0000000..7e32f4e
--- /dev/null
+++ b/qml/Functions.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+import "pages"
+
+Item {
+ id: functions
+
+ function get_piece(i) {
+ if (i === 0 || i === 7) return "rook";
+ else if (i === 1 || i === 6) return "knight";
+ else if (i === 2 || i === 5) return "bishop";
+ else if (i === 3) return "queen";
+ else if (i === 4) return "king";
+ else if (i >= 8 && i <= 15) return "pawn";
+ }
+
+ function fill() {
+ for (var i = 0; i < 16; i++) {
+ const piece = get_piece(i);
+ repeater.itemAt(i).image = piece !== "" ? "images/b" + piece + ".svg" : "";
+ repeater.itemAt(-i + 63).image = piece !== "" ? "images/w" + piece + ".svg" : "";
+ }
+ // Swap white king & queen
+ repeater.itemAt(60).image = [repeater.itemAt(59).image, repeater.itemAt(59).image = repeater.itemAt(60).image][0];
+ }
+}