summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-04-10 23:58:11 +0200
committerMarvin Borner2020-04-10 23:58:11 +0200
commitf4b275b744c22953c0c5dab1573df1bae4f11927 (patch)
tree48dd1403d81aa8509ff58d0da38ec2ac5a8fe8be
parent84637c0ad061d7c69420dca5a97708b4b1d494e6 (diff)
Added turn reminder
-rw-r--r--qml/Functions.qml28
-rw-r--r--qml/pages/Board.qml10
-rw-r--r--translations/harbour-sailchess-de.ts8
-rw-r--r--translations/harbour-sailchess.ts8
4 files changed, 41 insertions, 13 deletions
diff --git a/qml/Functions.qml b/qml/Functions.qml
index 7e1c576..9355af8 100644
--- a/qml/Functions.qml
+++ b/qml/Functions.qml
@@ -32,7 +32,7 @@ Item {
property var selected: []
function select(i) {
- if (selected.length < 2 && game_id !== "") {
+ if (selected.length < 2 && game_id !== "" && turn) {
if (selected.indexOf(i) === -1) selected.push(i)
else selected.splice(selected.indexOf(i), 1)
@@ -67,17 +67,20 @@ Item {
}
function move(from, to) {
- console.log(convert_index(from) + "-" + convert_index(to));
post("board/game/" + game_id + "/move/" + convert_index(from) + convert_index(to), "", function (response) {
console.log(JSON.stringify(response));
- if (response["ok"])
+ if (response["ok"]) {
+ turn = false;
move_piece(from, to);
+ }
})
selected = [];
}
// END LOGIC
+ property bool start: true
+ property bool turn: true
property var game_id: ""
property var moves: ""
@@ -89,10 +92,10 @@ Item {
xhr.onreadystatechange = function() {
if (xhr.readyState === 3) {
- try {
- const new_data = xhr.response.substr(xhr.seenBytes);
- xhr.seenBytes = xhr.responseText.length;
+ const new_data = xhr.response.substr(xhr.seenBytes);
+ xhr.seenBytes = xhr.responseText.length;
+ if (new_data !== "\n") {
console.log(new_data);
const data = JSON.parse(new_data);
if (data["type"] === "gameStart") {
@@ -101,7 +104,7 @@ Item {
game_id = data["game"]["id"];
game_stream();
}
- } catch (Exception) {}
+ }
}
};
@@ -117,11 +120,12 @@ Item {
game_xhr.onreadystatechange = function() {
if (game_xhr.readyState === 3) {
- try {
- const new_data = game_xhr.response.substr(game_xhr.seenBytes);
- game_xhr.seenBytes = game_xhr.responseText.length;
+ const new_data = game_xhr.response.substr(game_xhr.seenBytes);
+ game_xhr.seenBytes = game_xhr.responseText.length;
+ if (new_data !== "\n") {
console.log(new_data);
+
const data = JSON.parse(new_data);
var all_moves;
if (data["type"] === "gameFull") {
@@ -135,6 +139,8 @@ Item {
const new_moves = all_moves.slice(moves.length)
moves += new_moves;
+ turn = moves.split(" ").length % 2 === (start ? 0 : 1);
+ console.log(moves.split(" ").length % 2 === (start ? 1 : 0));
console.log(moves);
@@ -144,7 +150,7 @@ Item {
move_piece(arr[0], arr[1]);
}
});
- } catch (Exception) {}
+ }
}
};
diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml
index bbf41c3..68dc56d 100644
--- a/qml/pages/Board.qml
+++ b/qml/pages/Board.qml
@@ -76,11 +76,17 @@ Page {
}
}
Component.onCompleted: {
- // functions.fill();
functions.event_stream();
- // functions.challenge("GodelEscherBot");
}
}
+
+ Label {
+ // id: turn_label
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.top: grid.bottom
+ topPadding: Theme.paddingMedium
+ text: functions.turn ? qsTr("Your turn") : qsTr("Opponents turn");
+ }
}
}
diff --git a/translations/harbour-sailchess-de.ts b/translations/harbour-sailchess-de.ts
index 19923ee..4826908 100644
--- a/translations/harbour-sailchess-de.ts
+++ b/translations/harbour-sailchess-de.ts
@@ -27,6 +27,14 @@
<source>Refresh login</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>Your turn</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Opponents turn</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
<context>
<name>CoverPage</name>
diff --git a/translations/harbour-sailchess.ts b/translations/harbour-sailchess.ts
index 269bcbb..7c7c19f 100644
--- a/translations/harbour-sailchess.ts
+++ b/translations/harbour-sailchess.ts
@@ -27,6 +27,14 @@
<source>Refresh login</source>
<translation type="unfinished"></translation>
</message>
+ <message>
+ <source>Your turn</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <source>Opponents turn</source>
+ <translation type="unfinished"></translation>
+ </message>
</context>
<context>
<name>CoverPage</name>