summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-04-11 17:04:42 +0200
committerMarvin Borner2020-04-11 17:04:42 +0200
commit0cc8b365bfdf030820cdbaad87709a38e591b0b2 (patch)
tree452499616fec59770d3588878e8cce3542931115
parenta2aa0f7c634dfa47fc82c38581bce8dd0a8fa053 (diff)
Added castling support - HEUREKA!
-rw-r--r--qml/Functions.qml41
-rw-r--r--translations/harbour-sailchess-de.ts2
-rw-r--r--translations/harbour-sailchess.ts2
3 files changed, 38 insertions, 7 deletions
diff --git a/qml/Functions.qml b/qml/Functions.qml
index 430b9d7..67c5f30 100644
--- a/qml/Functions.qml
+++ b/qml/Functions.qml
@@ -71,12 +71,36 @@ Item {
console.log(JSON.stringify(response));
if (response["ok"]) {
turn = false;
- move_piece(from, to);
+ // move_piece(from, to);
}
})
selected = [];
}
+ function castle(move) {
+ console.log("'" + move + "'");
+ if (["e1c1", "e1g1", "e8c8", "e8g8"].indexOf(move) !== -1) {
+ var rook;
+ switch (move) {
+ case "e1c1":
+ rook = convert_movement("a1d1")
+ break;
+ case "e1g1":
+ rook = convert_movement("h1f1")
+ break;
+ case "e8c8":
+ rook = convert_movement("a8d8")
+ break;
+ case "e8g8":
+ rook = convert_movement("h8f8")
+ break;
+ }
+ console.log(rook);
+
+ move_piece(rook[0], rook[1]);
+ }
+ }
+
// END LOGIC
property bool start: true
@@ -103,6 +127,8 @@ Item {
data_arr.forEach(function (data) {
if (data["type"] === "gameStart") {
information.text = qsTr("Game started!");
+ clear();
+ stop_game();
fill();
game_id = data["game"]["id"];
game_stream();
@@ -140,7 +166,6 @@ Item {
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;
if (data["type"] === "gameFull") {
all_moves = data["state"]["moves"];
@@ -153,6 +178,8 @@ Item {
clear();
stop_game();
return;
+ } else if (data["type"] === "chatLine") {
+ return;
}
const new_moves = all_moves.slice(moves.length)
@@ -162,8 +189,10 @@ Item {
new_moves.split(" ").forEach(function(move) {
if (move !== "") {
+ // TODO: Implement pawn promotion and en passant
const arr = convert_movement(move);
move_piece(arr[0], arr[1]);
+ castle(move);
}
});
@@ -193,9 +222,11 @@ Item {
}
function stop_game() {
- game_id = "";
- moves = "";
- game_xhr.abort();
+ try {
+ game_id = "";
+ moves = "";
+ game_xhr.abort();
+ } catch (Exception) {} // idc
}
function abort() {
diff --git a/translations/harbour-sailchess-de.ts b/translations/harbour-sailchess-de.ts
index e5b0895..25b3944 100644
--- a/translations/harbour-sailchess-de.ts
+++ b/translations/harbour-sailchess-de.ts
@@ -69,7 +69,7 @@
<translation type="unfinished"></translation>
</message>
<message>
- <source>An error occured: </source>
+ <source>An error occurred: </source>
<translation type="unfinished"></translation>
</message>
</context>
diff --git a/translations/harbour-sailchess.ts b/translations/harbour-sailchess.ts
index ccfea16..dbba811 100644
--- a/translations/harbour-sailchess.ts
+++ b/translations/harbour-sailchess.ts
@@ -69,7 +69,7 @@
<translation type="unfinished"></translation>
</message>
<message>
- <source>An error occured: </source>
+ <source>An error occurred: </source>
<translation type="unfinished"></translation>
</message>
</context>