diff options
author | Marvin Borner | 2020-04-05 19:24:57 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-05 19:24:57 +0200 |
commit | bf800f3b9a78140d6ee5c031389af67f67d52d8f (patch) | |
tree | 0756b7ebd20e618b5d02a26a099b1eae61b2440b | |
parent | bfb99fed8efd71290f67735d27c7aa6bf4ee88f0 (diff) |
v1.0 - Added awesome leaderboard!1.0
Was quite some work but I finally implemented a frontend for my backend
leaderboard - works flawless! Furthermore this is now named v1.0 because
I'm probably finished with the main work and won't add many more
features.
-rw-r--r-- | qml/pages/Game.qml | 27 | ||||
-rw-r--r-- | qml/pages/LeaderBoard.qml | 106 | ||||
-rw-r--r-- | qml/pages/Menu.qml | 7 | ||||
-rw-r--r-- | rpm/harbour-binaryfun.spec | 3 | ||||
-rw-r--r-- | rpm/harbour-binaryfun.yaml | 5 | ||||
-rw-r--r-- | translations/harbour-binaryfun-de.ts | 44 | ||||
-rw-r--r-- | translations/harbour-binaryfun.ts | 38 |
7 files changed, 212 insertions, 18 deletions
diff --git a/qml/pages/Game.qml b/qml/pages/Game.qml index fb0f01d..c99c8a3 100644 --- a/qml/pages/Game.qml +++ b/qml/pages/Game.qml @@ -1,5 +1,6 @@ import QtQuick 2.2 import Sailfish.Silica 1.0 +import org.nemomobile.configuration 1.0 import ".." Page { @@ -14,12 +15,12 @@ Page { anchors.fill: parent contentHeight: root.height - /*PullDownMenu { + PullDownMenu { MenuItem { text: qsTr("Leaderboard") onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml")) } - }*/ + } Column { property int bits: page.bits @@ -37,6 +38,18 @@ Page { title: qsTr("Binary Fun") } + function submit(start_time, end_time, difficulty, level) { + var key = "RmMwQ0ptT1FlSkpIeEdzNDB3a1B5OVk1ZE8wYkRjSzI="; + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https://marvinborner.de/lead/binaryfun1/add", true); + 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") + + "&name="+ username.value + "&mods=0" + "&time=" + (end_time - start_time); + xhr.send(query); + } + function nearest(number) { if (number % (bits + 1) === 0) { return number @@ -63,10 +76,12 @@ Page { if (correct.filter(function(i) { return i === 1 }).length === bits) { if (timer.running) { // aka still playing + var end_time = (new Date()).getTime(); info_label.text = "Yeeehaaw!"; - timer_label.text = ((new Date().getTime() - start_time) / 1000) + "s - " + qsTr("Not bad!"); + timer_label.text = ((end_time - start_time) / 1000) + "s - " + qsTr("Not bad!"); timer.running = false; new_game.visible = true; + submit(start_time, end_time, bits, root.matrix.join(",")) } } } @@ -124,4 +139,10 @@ Page { } } } + + ConfigurationValue { + id: username + key: "/com/binaryfun/username" + defaultValue: "anon" + } } diff --git a/qml/pages/LeaderBoard.qml b/qml/pages/LeaderBoard.qml index eae37b0..f80c969 100644 --- a/qml/pages/LeaderBoard.qml +++ b/qml/pages/LeaderBoard.qml @@ -1,22 +1,114 @@ import QtQuick 2.2 import Sailfish.Silica 1.0 +import org.nemomobile.configuration 1.0 Page { id: page allowedOrientations: Orientation.Portrait - SilicaFlickable { + Column { anchors.fill: parent - contentHeight: column.height + anchors.margins: Theme.paddingMedium - Column { - id: column + PageHeader { + title: qsTr("Leaderboard") + } + + TextField { + placeholderText: "Enter username (default: anon)" + text: username.value + label: "Username" width: page.width - spacing: Theme.paddingLarge + EnterKey.enabled: text.length > 0 && text.length <= 16 + EnterKey.iconSource: "image://theme/icon-m-enter-close" + EnterKey.onClicked: { + focus = false + username.value = text + } + } + + ComboBox { + id: selector + label: "Difficulty" - PageHeader { - title: qsTr("Under Construction!") + function select(diff) { + var xhr = new XMLHttpRequest() + xhr.open("GET", + "https://marvinborner.de/lead/binaryfun1/list?sort=time&order=asc&count=1000&filter=difficulty,"+diff, + false) + xhr.send() + if (xhr.status !== 0) { + list.model = JSON.parse(xhr.responseText); + internet.visible = false; + } else { + internet.visible = true; + } } + + menu: ContextMenu { + MenuItem { + text: qsTr("Please select") + } + MenuItem { + property int diff: 2 + text: qsTr("Very easy (2 Bit)") + onClicked: selector.select(diff) + } + MenuItem { + property int diff: 4 + text: qsTr("Easy (4 Bit)") + onClicked: selector.select(diff) + } + MenuItem { + property int diff: 6 + text: qsTr("Medium (6 Bit)") + onClicked: selector.select(diff) + } + MenuItem { + property int diff: 8 + text: qsTr("Hard (8 Bit)") + onClicked: selector.select(diff) + } + MenuItem { + property int diff: 10 + text: qsTr("God-like (10 Bit)") + onClicked: selector.select(diff) + } + } + } + + Label { + id: internet + text: qsTr("No internet connection!") + visible: false } + + ListView { + id: list + clip: true + width: page.width + height: page.height - y + model: [] + delegate: ListItem { + contentHeight: Theme.itemSizeMedium + + Label { + id: name + text: index + 1 + ". " + modelData.name + } + + Label { + anchors.top: name.bottom + text: ((modelData.end_time[1] - modelData.start_time[1]) / 1000) + "s - Help: " + modelData.cheats + font.pixelSize: Theme.fontSizeSmall + } + } + } + } + + ConfigurationValue { + id: username + key: "/com/binaryfun/username" + defaultValue: "anon" } } diff --git a/qml/pages/Menu.qml b/qml/pages/Menu.qml index caf2e00..6c1dd08 100644 --- a/qml/pages/Menu.qml +++ b/qml/pages/Menu.qml @@ -9,6 +9,13 @@ Page { anchors.fill: parent contentHeight: column.height + PullDownMenu { + MenuItem { + text: qsTr("Leaderboard") + onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml")) + } + } + Column { property bool bar: false diff --git a/rpm/harbour-binaryfun.spec b/rpm/harbour-binaryfun.spec index eaff5f8..4ad17dc 100644 --- a/rpm/harbour-binaryfun.spec +++ b/rpm/harbour-binaryfun.spec @@ -13,7 +13,7 @@ Name: harbour-binaryfun %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: An awesome binary game -Version: 0.2 +Version: 1.0 Release: 1 Group: Qt/Qt License: MIT @@ -21,6 +21,7 @@ URL: https://openrepos.net/content/melvin/binary-fun Source0: %{name}-%{version}.tar.bz2 Source100: harbour-binaryfun.yaml Requires: sailfishsilica-qt5 >= 0.10.9 +Requires: nemo-qml-plugin-configuration-qt5 BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 BuildRequires: pkgconfig(Qt5Core) BuildRequires: pkgconfig(Qt5Qml) diff --git a/rpm/harbour-binaryfun.yaml b/rpm/harbour-binaryfun.yaml index 72896d7..1d45899 100644 --- a/rpm/harbour-binaryfun.yaml +++ b/rpm/harbour-binaryfun.yaml @@ -1,6 +1,6 @@ Name: harbour-binaryfun Summary: An awesome binary game -Version: 0.2 +Version: 1.0 Release: 1 # The contents of the Group field should be one of the groups listed here: # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS @@ -32,7 +32,8 @@ PkgConfigBR: # Runtime dependencies which are not automatically detected Requires: - - sailfishsilica-qt5 >= 0.10.9 + - sailfishsilica-qt5 >= 0.10.9 + - nemo-qml-plugin-configuration-qt5 # All installed files Files: diff --git a/translations/harbour-binaryfun-de.ts b/translations/harbour-binaryfun-de.ts index 1b660f8..efb8610 100644 --- a/translations/harbour-binaryfun-de.ts +++ b/translations/harbour-binaryfun-de.ts @@ -5,7 +5,7 @@ <name>CoverPage</name> <message> <source>Binary Fun</source> - <translation type="unfinished">Binär-Spaß</translation> + <translation>Binär-Spaß</translation> </message> </context> <context> @@ -22,12 +22,44 @@ <source>Not bad!</source> <translation>Nicht schlecht!</translation> </message> + <message> + <source>Leaderboard</source> + <translation>Bestenliste</translation> + </message> </context> <context> <name>LeaderBoard</name> <message> - <source>Under Construction!</source> - <translation>Im Aufbau!</translation> + <source>Leaderboard</source> + <translation>Bestenliste</translation> + </message> + <message> + <source>Very easy (2 Bit)</source> + <translation>Sehr einfach (2 Bit)</translation> + </message> + <message> + <source>Easy (4 Bit)</source> + <translation>Einfach (4 Bit)</translation> + </message> + <message> + <source>Medium (6 Bit)</source> + <translation>Mittel (6 Bit)</translation> + </message> + <message> + <source>Hard (8 Bit)</source> + <translation>Schwer (8 Bit)</translation> + </message> + <message> + <source>God-like (10 Bit)</source> + <translation>Krass (10 Bit)</translation> + </message> + <message> + <source>Please select</source> + <translation>Bitte auswählen</translation> + </message> + <message> + <source>No internet connection!</source> + <translation>Keine Internetverbindung!</translation> </message> </context> <context> @@ -58,7 +90,11 @@ </message> <message> <source>Help bar</source> - <translation>Legende</translation> + <translation>Hilfs-Legende</translation> + </message> + <message> + <source>Leaderboard</source> + <translation>Bestenliste</translation> </message> </context> </TS> diff --git a/translations/harbour-binaryfun.ts b/translations/harbour-binaryfun.ts index 31d14b0..3902a1f 100644 --- a/translations/harbour-binaryfun.ts +++ b/translations/harbour-binaryfun.ts @@ -22,11 +22,43 @@ <source>Not bad!</source> <translation type="unfinished"></translation> </message> + <message> + <source>Leaderboard</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>LeaderBoard</name> <message> - <source>Under Construction!</source> + <source>Leaderboard</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Very easy (2 Bit)</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Easy (4 Bit)</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Medium (6 Bit)</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Hard (8 Bit)</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>God-like (10 Bit)</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Please select</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>No internet connection!</source> <translation type="unfinished"></translation> </message> </context> @@ -60,5 +92,9 @@ <source>Help bar</source> <translation type="unfinished"></translation> </message> + <message> + <source>Leaderboard</source> + <translation type="unfinished"></translation> + </message> </context> </TS> |