Add support for making moves from QML

This commit is contained in:
ItsDrike 2024-12-04 00:05:29 +01:00
parent 4dbcd700c0
commit 986c2ce2be
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -64,8 +64,16 @@ ApplicationWindow {
model: Math.min(GameState.throwawayPile.length, 3)
delegate: CardModel {
required property int index // passed from repeater
card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - index]
property int reversedIndex: Math.min(GameState.throwawayPile.length, 3) - 1 - index;
card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - reversedIndex]
isFaceDown: false
onClicked: {
// Only auto-move the last card in the throwaway pile
// cards below it are shown, but shouldn't have a click effect
if (reversedIndex == 0) {
GameState.autoMoveThrownCard()
}
}
}
}
}
@ -74,6 +82,9 @@ ApplicationWindow {
CardModel {
card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null
isFaceDown: true
onClicked: {
GameState.drawNextCard()
}
}
}
}
@ -102,6 +113,11 @@ ApplicationWindow {
card: col.card
isFaceDown: !col.revealed
onClicked: {
if (col.revealed) {
GameState.autoMoveColumnCard(parent.index, index)
}
}
}
}
}