diff options
Diffstat (limited to 'qml/Functions.qml')
-rw-r--r-- | qml/Functions.qml | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/qml/Functions.qml b/qml/Functions.qml index 7e32f4e..4b90cc7 100644 --- a/qml/Functions.qml +++ b/qml/Functions.qml @@ -5,21 +5,43 @@ 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"; + if (i === 0 || i === 7) return "r"; + else if (i === 1 || i === 6) return "n"; + else if (i === 2 || i === 5) return "b"; + else if (i === 3) return "q"; + else if (i === 4) return "k"; + else if (i >= 8 && i <= 15) return "p"; } 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" : ""; + + board.itemAt(i).piece = "b" + piece; + board.itemAt(-i + 63).piece = "w" + piece; } // Swap white king & queen - repeater.itemAt(60).image = [repeater.itemAt(59).image, repeater.itemAt(59).image = repeater.itemAt(60).image][0]; + board.itemAt(60).piece = [board.itemAt(59).piece, board.itemAt(59).piece = board.itemAt(60).piece][0]; + } + + property var selected: [] + function select(i) { + if (selected.length < 2) { + if (selected.indexOf(i) === -1) selected.push(i) + else selected.splice(selected.indexOf(i), 1) + + if (selected.length === 2) { + board.itemAt(selected[0]).border.width = 0; + move(selected[0], selected[1]); + } else { + board.itemAt(i).border.width ^= parseInt(0.1 * board.itemAt(i).width); + } + } + } + + function move(from, to) { + board.itemAt(to).piece = board.itemAt(from).piece; + board.itemAt(from).piece = ""; + selected = []; } } |