aboutsummaryrefslogtreecommitdiffhomepage
path: root/qml
diff options
context:
space:
mode:
authorMarvin Borner2020-04-23 22:13:45 +0200
committerMarvin Borner2020-04-23 22:13:45 +0200
commit7af9769b48321376153b5ceee5c17050eb7d211e (patch)
tree5a3762c27f1b12bd1881afe1eb00821d39b7cf6b /qml
parent31867b1a0292267db51f7eb9ba916b572295f4a3 (diff)
Added new help modes and fixed timing issues
Diffstat (limited to 'qml')
-rw-r--r--qml/Bit.qml2
-rw-r--r--qml/pages/Game.qml15
-rw-r--r--qml/pages/LeaderBoard.qml11
-rw-r--r--qml/pages/Menu.qml24
4 files changed, 29 insertions, 23 deletions
diff --git a/qml/Bit.qml b/qml/Bit.qml
index 1b1e4b1..8332747 100644
--- a/qml/Bit.qml
+++ b/qml/Bit.qml
@@ -49,7 +49,7 @@ Loader {
}
} else if (index !== bits){
var num = Math.floor(Math.random() * (Math.pow(2, bits) - 1)) + 1;
- this.text = root.help ? (Math.pow(2, bits - index - 1)) : num;
+ this.text = root.help > 1 ? (Math.pow(2, bits - index - 1)) : num;
root.matrix[index] = num;
} else {
this.text = "0/1";
diff --git a/qml/pages/Game.qml b/qml/pages/Game.qml
index 702c4a7..9e89765 100644
--- a/qml/pages/Game.qml
+++ b/qml/pages/Game.qml
@@ -6,7 +6,8 @@ import ".."
Page {
// Get passed by previous page
property int bits: 0
- property bool help: false
+ property var help: 0
+ property var modes: []
id: page
allowedOrientations: Orientation.Portrait
@@ -18,13 +19,14 @@ Page {
PullDownMenu {
MenuItem {
text: qsTr("Leaderboard")
- onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
+ onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"), {modes: root.help_modes})
}
}
Column {
property int bits: page.bits
- property bool help: page.help
+ property var help: page.help
+ property var help_modes: page.modes
property var correct: new Array(bits)
property var matrix: new Array(Math.pow(bits + 1, 2))
property var start_time: 0
@@ -45,7 +47,7 @@ Page {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
var query = "writeKey=" + Qt.atob(key) + "&win=true&board=default&start_time=" + start_time
+ "&end_time=" + end_time + "&difficulty=" + difficulty
- + "&level=" + level + "&cheats=" + (root.help ? "true" : "false")
+ + "&level=" + level + "&cheats=" + root.help
+ "&name="+ username.value + "&mods=1" + "&time=" + (end_time - start_time);
xhr.send(query);
}
@@ -107,13 +109,14 @@ Page {
Label {
id: info_label
text: "0 / " + root.bits
+ visible: root.help === 1 || root.help === 3
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: page.bottom
}
Label {
id: timer_label
- text: "0s"
+ text: "-1s"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: page.bottom
}
@@ -127,7 +130,7 @@ Page {
onTriggered: {
if (root.start_time === 0)
root.start_time = (new Date()).getTime();
- timer_label.text = parseInt(timer_label.text.substr(0, timer_label.text.indexOf('s'))) + "s";
+ timer_label.text = parseInt(timer_label.text.substr(0, timer_label.text.indexOf('s'))) + 1 + "s";
}
}
diff --git a/qml/pages/LeaderBoard.qml b/qml/pages/LeaderBoard.qml
index bb45e07..cd76c5d 100644
--- a/qml/pages/LeaderBoard.qml
+++ b/qml/pages/LeaderBoard.qml
@@ -3,6 +3,8 @@ import Sailfish.Silica 1.0
import Nemo.Configuration 1.0
Page {
+ property var modes: []
+
id: page
allowedOrientations: Orientation.Portrait
@@ -137,11 +139,12 @@ Page {
Label {
anchors.top: level.bottom
- text: (((modelData.end_time[1] - modelData.start_time[1]) / 1000) + (modelData.mods === "0" ? 1.0 : 0)).toFixed(3) + qsTr("s - Help: ") + modelData.cheats
- font.pixelSize: Theme.fontSizeExtraSmall
- Component.onCompleted: {
- console.log(modelData.mods);
+ text: {
+ const time = (((modelData.end_time[1] - modelData.start_time[1]) / 1000) + (modelData.mods === "0" ? 1.0 : 0)).toFixed(3);
+ const help = modelData.cheats === "true" ? 3 : (modelData.cheats === "false" ? 1 : parseInt(modelData.cheats));
+ return time + qsTr("s - Help: ") + page.modes[help];
}
+ font.pixelSize: Theme.fontSizeExtraSmall
}
}
}
diff --git a/qml/pages/Menu.qml b/qml/pages/Menu.qml
index 6c1dd08..938d95c 100644
--- a/qml/pages/Menu.qml
+++ b/qml/pages/Menu.qml
@@ -7,19 +7,20 @@ Page {
SilicaFlickable {
anchors.fill: parent
- contentHeight: column.height
+ contentHeight: menu.height
PullDownMenu {
MenuItem {
text: qsTr("Leaderboard")
- onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
+ onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"), {modes: menu.help_modes})
}
}
Column {
- property bool bar: false
+ property var help: 0
+ property var help_modes: [qsTr("None"), qsTr("Counter"), qsTr("Bar"), qsTr("Both")]
- id: column
+ id: menu
width: page.width
height: page.height
spacing: Theme.paddingLarge
@@ -34,10 +35,9 @@ Page {
rowSpacing: Theme.paddingLarge * 2
Button {
- text: qsTr("Help bar") + ": 0"
+ text: qsTr("Help") + ": " + menu.help_modes[menu.help]
onClicked: {
- column.bar = this.text.slice(-1) === "0";
- this.text = column.bar ? qsTr("Help bar") + ": 1" : qsTr("Help bar") + ": 0"
+ menu.help = menu.help !== 3 ? ++menu.help : 0;
}
}
@@ -45,35 +45,35 @@ Page {
text: qsTr("Very easy (2 Bit)")
ButtonLayout.newLine: true
onClicked: {
- pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 2, help: column.bar});
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 2, help: menu.help, modes: menu.help_modes});
}
}
Button {
text: qsTr("Easy (4 Bit)")
onClicked: {
- pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 4, help: column.bar});
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 4, help: menu.help, modes: menu.help_modes});
}
}
Button {
text: qsTr("Medium (6 Bit)")
onClicked: {
- pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 6, help: column.bar});
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 6, help: menu.help, modes: menu.help_modes});
}
}
Button {
text: qsTr("Hard (8 Bit)")
onClicked: {
- pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 8, help: column.bar});
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 8, help: menu.help, modes: menu.help_modes});
}
}
Button {
text: qsTr("God-like (10 Bit)")
onClicked: {
- pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 10, help: column.bar});
+ pageStack.push(Qt.resolvedUrl("Game.qml"), {bits: 10, help: menu.help, modes: menu.help_modes});
}
}
}