From f4b275b744c22953c0c5dab1573df1bae4f11927 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 10 Apr 2020 23:58:11 +0200 Subject: Added turn reminder --- qml/Functions.qml | 28 +++++++++++++++++----------- qml/pages/Board.qml | 10 ++++++++-- translations/harbour-sailchess-de.ts | 8 ++++++++ translations/harbour-sailchess.ts | 8 ++++++++ 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 @@ Refresh login + + Your turn + + + + Opponents turn + + CoverPage 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 @@ Refresh login + + Your turn + + + + Opponents turn + + CoverPage -- cgit v1.2.3