diff options
author | Marvin Borner | 2020-04-11 14:24:25 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-11 14:24:25 +0200 |
commit | a2aa0f7c634dfa47fc82c38581bce8dd0a8fa053 (patch) | |
tree | fc208b18d1bebbf1558cdb4c880742a236f1d2ab | |
parent | 53abf21bad1d10ff8a62da25578c116780d9d20a (diff) |
Added challenge dialog and ndjson verificator
-rw-r--r-- | harbour-sailchess.pro | 1 | ||||
-rw-r--r-- | qml/Functions.qml | 23 | ||||
-rw-r--r-- | qml/Square.qml | 2 | ||||
-rw-r--r-- | qml/harbour-sailchess.qml | 2 | ||||
-rw-r--r-- | qml/pages/Board.qml | 8 | ||||
-rw-r--r-- | qml/pages/ChallengeDialog.qml | 17 | ||||
-rw-r--r-- | translations/harbour-sailchess-de.ts | 11 | ||||
-rw-r--r-- | translations/harbour-sailchess.ts | 11 |
8 files changed, 65 insertions, 10 deletions
diff --git a/harbour-sailchess.pro b/harbour-sailchess.pro index bcd00e7..bf82072 100644 --- a/harbour-sailchess.pro +++ b/harbour-sailchess.pro @@ -21,6 +21,7 @@ DISTFILES += qml/harbour-sailchess.qml \ qml/pages/Board.qml \ qml/Square.qml \ qml/Functions.qml \ + qml/pages/ChallengeDialog.qml \ qml/pages/Login.qml \ rpm/harbour-sailchess.changes.in \ rpm/harbour-sailchess.changes.run.in \ diff --git a/qml/Functions.qml b/qml/Functions.qml index 292df3f..430b9d7 100644 --- a/qml/Functions.qml +++ b/qml/Functions.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.2 import "pages" Item { @@ -97,15 +97,23 @@ Item { if (new_data !== "\n") { // TODO: Fix resign - console.log("[" + new_data.replace("\n", ",").replace(/.$/, "]")); + console.log("[" + new_data.replace(/(?:\r\n|\r|\n)/g, ",").replace(/\,$/, "") + "]"); - const data_arr = JSON.parse("[" + new_data.replace("\n", ",").replace(/.$/, "]")); + const data_arr = JSON.parse("[" + new_data.replace(/(?:\r\n|\r|\n)/g, ",").replace(/\,$/, "") + "]"); data_arr.forEach(function (data) { if (data["type"] === "gameStart") { information.text = qsTr("Game started!"); fill(); game_id = data["game"]["id"]; game_stream(); + } else if (data["type"] === "challenge") { + var dialog = pageStack.push("pages/ChallengeDialog.qml", {"name": data["challenge"]["challenger"]["name"]}); + dialog.accepted.connect(function() { + post("challenge/" + data["challenge"]["id"] + "/accept", "", function() {}); + }) + dialog.rejected.connect(function() { + post("challenge/" + data["challenge"]["id"] + "/decline", "", function() {}); + }) } }); } @@ -128,9 +136,9 @@ Item { game_xhr.seenBytes = game_xhr.responseText.length; if (new_data !== "\n") { - console.log("[" + new_data.replace("\n", ",").replace(/.$/, "]")); + console.log("[" + new_data.replace(/(?:\r\n|\r|\n)/g, ",").replace(/\,$/, "") + "]"); - const data_arr = JSON.parse("[" + new_data.replace("\n", ",").replace(/.$/, "]")); + const data_arr = JSON.parse("[" + new_data.replace(/(?:\r\n|\r|\n)/g, ",").replace(/\,$/, "") + "]"); data_arr.forEach(function (data) { // TODO: Implement castling: e1c1, e1, g1, e8c8, e8g8 var all_moves, status; @@ -140,6 +148,11 @@ Item { } else if (data["type"] === "gameState") { all_moves = data["moves"]; status = data["status"]; + } else if (data["error"]) { + information.text = qsTr("An error occurred: ") + data["error"]; + clear(); + stop_game(); + return; } const new_moves = all_moves.slice(moves.length) diff --git a/qml/Square.qml b/qml/Square.qml index 2169290..bb13184 100644 --- a/qml/Square.qml +++ b/qml/Square.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.2 Rectangle { property int i: 0 diff --git a/qml/harbour-sailchess.qml b/qml/harbour-sailchess.qml index 6142693..aed55f7 100644 --- a/qml/harbour-sailchess.qml +++ b/qml/harbour-sailchess.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.2 import Sailfish.Silica 1.0 import org.nemomobile.configuration 1.0 import "pages" diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml index 58af5ee..240fa11 100644 --- a/qml/pages/Board.qml +++ b/qml/pages/Board.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.2 import Sailfish.Silica 1.0 import org.nemomobile.configuration 1.0 import ".." @@ -52,12 +52,14 @@ Page { title: qsTr("Chess") } - Label { + LinkedLabel { id: information + width: parent.width + color: "white" anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: grid.top bottomPadding: Theme.paddingMedium - text: qsTr("Please start a game"); + plainText: qsTr("Please start a game"); } Grid { diff --git a/qml/pages/ChallengeDialog.qml b/qml/pages/ChallengeDialog.qml new file mode 100644 index 0000000..037d53d --- /dev/null +++ b/qml/pages/ChallengeDialog.qml @@ -0,0 +1,17 @@ +import QtQuick 2.2 +import Sailfish.Silica 1.0 + +Dialog { + property var name + + Column { + width: parent.width + + DialogHeader { } + + Label { + width: parent.width + text: name + qsTr(" challenges you") + } + } +} diff --git a/translations/harbour-sailchess-de.ts b/translations/harbour-sailchess-de.ts index 8b746b1..e5b0895 100644 --- a/translations/harbour-sailchess-de.ts +++ b/translations/harbour-sailchess-de.ts @@ -37,6 +37,13 @@ </message> </context> <context> + <name>ChallengeDialog</name> + <message> + <source> challenges you</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>CoverPage</name> <message> <source>My Cover</source> @@ -61,5 +68,9 @@ <source>Game over: </source> <translation type="unfinished"></translation> </message> + <message> + <source>An error occured: </source> + <translation type="unfinished"></translation> + </message> </context> </TS> diff --git a/translations/harbour-sailchess.ts b/translations/harbour-sailchess.ts index 4b0d9c0..ccfea16 100644 --- a/translations/harbour-sailchess.ts +++ b/translations/harbour-sailchess.ts @@ -37,6 +37,13 @@ </message> </context> <context> + <name>ChallengeDialog</name> + <message> + <source> challenges you</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> <name>CoverPage</name> <message> <source>My Cover</source> @@ -61,5 +68,9 @@ <source>Game over: </source> <translation type="unfinished"></translation> </message> + <message> + <source>An error occured: </source> + <translation type="unfinished"></translation> + </message> </context> </TS> |