summaryrefslogtreecommitdiff
path: root/qml/pages
diff options
context:
space:
mode:
Diffstat (limited to 'qml/pages')
-rw-r--r--qml/pages/Board.qml4
-rw-r--r--qml/pages/Goban.qml31
2 files changed, 28 insertions, 7 deletions
diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml
index cee8492..16c4e6b 100644
--- a/qml/pages/Board.qml
+++ b/qml/pages/Board.qml
@@ -4,8 +4,6 @@ import Sailfish.Silica 1.0
import io.thp.pyotherside 1.2
-
-
Page {
width: Screen.width; height: Screen.height;
@@ -27,7 +25,7 @@ Page {
IconButton {
width: (parent.width - parent.height) / 2;
icon.source: "image://theme/icon-m-back"
- onClicked: console.log("Previous!")
+ onClicked: goban.undo();
}
Image {
diff --git a/qml/pages/Goban.qml b/qml/pages/Goban.qml
index 420d22d..5c86700 100644
--- a/qml/pages/Goban.qml
+++ b/qml/pages/Goban.qml
@@ -27,6 +27,8 @@ Item {
property variant tree;
+ property variant history;
+
/*
* Start the game.
*
@@ -48,13 +50,13 @@ Item {
i++;
}
- initial = tree[i]
+ initial = tree[i];
+ history = [];
var aw = initial.AW;
if (aw !== undefined) {
aw.forEach(function (pos) {
goban.getItemAt(pos[0], pos[1]).put(currentPlayer, false);
-// Actions.addPiece(pos[0] + (pos[1] * goban.columns), goban, currentPlayer, false, true, true);
});
}
@@ -62,7 +64,6 @@ Item {
if (ab !== undefined) {
ab.forEach(function (pos) {
goban.getItemAt(pos[0], pos[1]).put(!currentPlayer, false);
-// Actions.addPiece(pos[0] + (pos[1] * goban.columns), goban, !currentPlayer, false, true, true);
});
}
}
@@ -94,6 +95,22 @@ Item {
start();
}
+ /*
+ * Undo the last move.
+ */
+ function undo() {
+ if (history.length === 0) {
+ return;
+ }
+
+ var currentHistory = history;
+ var step = currentHistory.pop();
+ history = currentHistory;
+
+ Actions.undo(goban, step);
+ currentPlayer = step.player;
+ }
+
/**
* Handle a click on the goban.
*/
@@ -107,8 +124,14 @@ Item {
return;
}
- if (Actions.addPiece(index, goban, currentPlayer, true, false, false)) {
+ var step = Actions.addPiece(index, goban, currentPlayer, true, false, false);
+
+ if (step !== undefined) {
currentPlayer = !currentPlayer;
+
+ var currentHistory = history;
+ currentHistory.push(step);
+ history = currentHistory;
}
}