From 22bb752e6907e9d4c3f5159da01d8dfbdfd8b4bc Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Thu, 9 Apr 2020 17:20:49 +0200
Subject: Added piece layout
---
harbour-sailchess.pro | 1 +
qml/Functions.qml | 25 +++++++++++++++++++++++++
qml/Square.qml | 9 +++++++++
qml/images/bbishop.svg | 17 +++++++++++++++++
qml/images/bking.svg | 25 +++++++++++++++++++++++++
qml/images/bknight.svg | 14 ++++++++++++++
qml/images/bpawn.svg | 7 +++++++
qml/images/bqueen.svg | 34 ++++++++++++++++++++++++++++++++++
qml/images/brook.svg | 39 +++++++++++++++++++++++++++++++++++++++
qml/images/wbishop.svg | 17 +++++++++++++++++
qml/images/wking.svg | 27 +++++++++++++++++++++++++++
qml/images/wknight.svg | 13 +++++++++++++
qml/images/wpawn.svg | 7 +++++++
qml/images/wqueen.svg | 33 +++++++++++++++++++++++++++++++++
qml/images/wrook.svg | 25 +++++++++++++++++++++++++
qml/pages/Board.qml | 9 ++++++---
16 files changed, 299 insertions(+), 3 deletions(-)
create mode 100644 qml/Functions.qml
create mode 100644 qml/images/bbishop.svg
create mode 100644 qml/images/bking.svg
create mode 100644 qml/images/bknight.svg
create mode 100644 qml/images/bpawn.svg
create mode 100644 qml/images/bqueen.svg
create mode 100644 qml/images/brook.svg
create mode 100644 qml/images/wbishop.svg
create mode 100644 qml/images/wking.svg
create mode 100644 qml/images/wknight.svg
create mode 100644 qml/images/wpawn.svg
create mode 100644 qml/images/wqueen.svg
create mode 100644 qml/images/wrook.svg
diff --git a/harbour-sailchess.pro b/harbour-sailchess.pro
index 762f411..2e954fc 100644
--- a/harbour-sailchess.pro
+++ b/harbour-sailchess.pro
@@ -20,6 +20,7 @@ DISTFILES += qml/harbour-sailchess.qml \
qml/cover/CoverPage.qml \
qml/pages/Board.qml \
qml/Square.qml \
+ qml/Functions.qml \
rpm/harbour-sailchess.changes.in \
rpm/harbour-sailchess.changes.run.in \
rpm/harbour-sailchess.spec \
diff --git a/qml/Functions.qml b/qml/Functions.qml
new file mode 100644
index 0000000..7e32f4e
--- /dev/null
+++ b/qml/Functions.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+import "pages"
+
+Item {
+ id: functions
+
+ function get_piece(i) {
+ if (i === 0 || i === 7) return "rook";
+ else if (i === 1 || i === 6) return "knight";
+ else if (i === 2 || i === 5) return "bishop";
+ else if (i === 3) return "queen";
+ else if (i === 4) return "king";
+ else if (i >= 8 && i <= 15) return "pawn";
+ }
+
+ function fill() {
+ for (var i = 0; i < 16; i++) {
+ const piece = get_piece(i);
+ repeater.itemAt(i).image = piece !== "" ? "images/b" + piece + ".svg" : "";
+ repeater.itemAt(-i + 63).image = piece !== "" ? "images/w" + piece + ".svg" : "";
+ }
+ // Swap white king & queen
+ repeater.itemAt(60).image = [repeater.itemAt(59).image, repeater.itemAt(59).image = repeater.itemAt(60).image][0];
+ }
+}
diff --git a/qml/Square.qml b/qml/Square.qml
index de61de4..f71f3a5 100644
--- a/qml/Square.qml
+++ b/qml/Square.qml
@@ -1,11 +1,20 @@
import QtQuick 2.0
Rectangle {
+ property int i: 0
+ property string image: ""
+ width: page.width / 8
height: this.width
+ color: ((i >> 3 ^ i) & 1) == 1 ? "#e8ebef" : "#7d8796"
border.color: "yellow"
border.width: 0
MouseArea {
anchors.fill: parent
onClicked: parent.border.width ^= 3
}
+ Image {
+ width: parent.width
+ height: this.width
+ source: image
+ }
}
diff --git a/qml/images/bbishop.svg b/qml/images/bbishop.svg
new file mode 100644
index 0000000..4ce248f
--- /dev/null
+++ b/qml/images/bbishop.svg
@@ -0,0 +1,17 @@
+
+
+
diff --git a/qml/images/bking.svg b/qml/images/bking.svg
new file mode 100644
index 0000000..d90dc73
--- /dev/null
+++ b/qml/images/bking.svg
@@ -0,0 +1,25 @@
+
+
+
diff --git a/qml/images/bknight.svg b/qml/images/bknight.svg
new file mode 100644
index 0000000..02b0894
--- /dev/null
+++ b/qml/images/bknight.svg
@@ -0,0 +1,14 @@
+
+
+
diff --git a/qml/images/bpawn.svg b/qml/images/bpawn.svg
new file mode 100644
index 0000000..072f2fe
--- /dev/null
+++ b/qml/images/bpawn.svg
@@ -0,0 +1,7 @@
+
+
+
diff --git a/qml/images/bqueen.svg b/qml/images/bqueen.svg
new file mode 100644
index 0000000..6f1e4a5
--- /dev/null
+++ b/qml/images/bqueen.svg
@@ -0,0 +1,34 @@
+
+
+
diff --git a/qml/images/brook.svg b/qml/images/brook.svg
new file mode 100644
index 0000000..337af8f
--- /dev/null
+++ b/qml/images/brook.svg
@@ -0,0 +1,39 @@
+
+
+
diff --git a/qml/images/wbishop.svg b/qml/images/wbishop.svg
new file mode 100644
index 0000000..0f28d08
--- /dev/null
+++ b/qml/images/wbishop.svg
@@ -0,0 +1,17 @@
+
+
+
diff --git a/qml/images/wking.svg b/qml/images/wking.svg
new file mode 100644
index 0000000..8b2d7b7
--- /dev/null
+++ b/qml/images/wking.svg
@@ -0,0 +1,27 @@
+
+
+
diff --git a/qml/images/wknight.svg b/qml/images/wknight.svg
new file mode 100644
index 0000000..644d6e8
--- /dev/null
+++ b/qml/images/wknight.svg
@@ -0,0 +1,13 @@
+
+
+
diff --git a/qml/images/wpawn.svg b/qml/images/wpawn.svg
new file mode 100644
index 0000000..1142516
--- /dev/null
+++ b/qml/images/wpawn.svg
@@ -0,0 +1,7 @@
+
+
+
diff --git a/qml/images/wqueen.svg b/qml/images/wqueen.svg
new file mode 100644
index 0000000..97043c5
--- /dev/null
+++ b/qml/images/wqueen.svg
@@ -0,0 +1,33 @@
+
+
+
diff --git a/qml/images/wrook.svg b/qml/images/wrook.svg
new file mode 100644
index 0000000..8d2d932
--- /dev/null
+++ b/qml/images/wrook.svg
@@ -0,0 +1,25 @@
+
+
+
diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml
index f04a0f1..efa79f7 100644
--- a/qml/pages/Board.qml
+++ b/qml/pages/Board.qml
@@ -6,6 +6,10 @@ Page {
id: page
allowedOrientations: Orientation.Portrait
+ Functions {
+ id: functions
+ }
+
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
@@ -33,11 +37,10 @@ Page {
id: repeater
model: 64
delegate: Square {
- width: page.width / 8
- color: ((index >> 3 ^ index) & 1) == 1 ? "#e8ebef" : "#7d8796"
-
+ i: index
}
}
+ Component.onCompleted: functions.fill()
}
}
}
--
cgit v1.2.3