diff options
author | Marvin Borner | 2020-04-09 17:20:49 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-09 17:20:49 +0200 |
commit | 22bb752e6907e9d4c3f5159da01d8dfbdfd8b4bc (patch) | |
tree | a5651ab16b4762e6ab7b8c73d311787f3d8e54b0 /qml/Functions.qml | |
parent | ebb1ab3d05b1e61a491375b7640196e04f1bab06 (diff) |
Added piece layout
Diffstat (limited to 'qml/Functions.qml')
-rw-r--r-- | qml/Functions.qml | 25 |
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]; + } +} |