Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit bf800f3

Browse files
committed
v1.0 - Added awesome leaderboard!
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.
1 parent bfb99fe commit bf800f3

7 files changed

Lines changed: 212 additions & 18 deletions

File tree

qml/pages/Game.qml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import QtQuick 2.2
22
import Sailfish.Silica 1.0
3+
import org.nemomobile.configuration 1.0
34
import ".."
45

56
Page {
@@ -14,12 +15,12 @@ Page {
1415
anchors.fill: parent
1516
contentHeight: root.height
1617

17-
/*PullDownMenu {
18+
PullDownMenu {
1819
MenuItem {
1920
text: qsTr("Leaderboard")
2021
onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
2122
}
22-
}*/
23+
}
2324

2425
Column {
2526
property int bits: page.bits
@@ -37,6 +38,18 @@ Page {
3738
title: qsTr("Binary Fun")
3839
}
3940

41+
function submit(start_time, end_time, difficulty, level) {
42+
var key = "RmMwQ0ptT1FlSkpIeEdzNDB3a1B5OVk1ZE8wYkRjSzI=";
43+
var xhr = new XMLHttpRequest();
44+
xhr.open("POST", "https://marvinborner.de/lead/binaryfun1/add", true);
45+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
46+
var query = "writeKey=" + Qt.atob(key) + "&win=true&board=default&start_time=" + start_time
47+
+ "&end_time=" + end_time + "&difficulty=" + difficulty
48+
+ "&level=" + level + "&cheats=" + (root.help ? "true" : "false")
49+
+ "&name="+ username.value + "&mods=0" + "&time=" + (end_time - start_time);
50+
xhr.send(query);
51+
}
52+
4053
function nearest(number) {
4154
if (number % (bits + 1) === 0) {
4255
return number
@@ -63,10 +76,12 @@ Page {
6376

6477
if (correct.filter(function(i) { return i === 1 }).length === bits) {
6578
if (timer.running) { // aka still playing
79+
var end_time = (new Date()).getTime();
6680
info_label.text = "Yeeehaaw!";
67-
timer_label.text = ((new Date().getTime() - start_time) / 1000) + "s - " + qsTr("Not bad!");
81+
timer_label.text = ((end_time - start_time) / 1000) + "s - " + qsTr("Not bad!");
6882
timer.running = false;
6983
new_game.visible = true;
84+
submit(start_time, end_time, bits, root.matrix.join(","))
7085
}
7186
}
7287
}
@@ -124,4 +139,10 @@ Page {
124139
}
125140
}
126141
}
142+
143+
ConfigurationValue {
144+
id: username
145+
key: "/com/binaryfun/username"
146+
defaultValue: "anon"
147+
}
127148
}

qml/pages/LeaderBoard.qml

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,114 @@
11
import QtQuick 2.2
22
import Sailfish.Silica 1.0
3+
import org.nemomobile.configuration 1.0
34

45
Page {
56
id: page
67
allowedOrientations: Orientation.Portrait
78

8-
SilicaFlickable {
9+
Column {
910
anchors.fill: parent
10-
contentHeight: column.height
11+
anchors.margins: Theme.paddingMedium
1112

12-
Column {
13-
id: column
13+
PageHeader {
14+
title: qsTr("Leaderboard")
15+
}
16+
17+
TextField {
18+
placeholderText: "Enter username (default: anon)"
19+
text: username.value
20+
label: "Username"
1421
width: page.width
15-
spacing: Theme.paddingLarge
22+
EnterKey.enabled: text.length > 0 && text.length <= 16
23+
EnterKey.iconSource: "image://theme/icon-m-enter-close"
24+
EnterKey.onClicked: {
25+
focus = false
26+
username.value = text
27+
}
28+
}
29+
30+
ComboBox {
31+
id: selector
32+
label: "Difficulty"
1633

17-
PageHeader {
18-
title: qsTr("Under Construction!")
34+
function select(diff) {
35+
var xhr = new XMLHttpRequest()
36+
xhr.open("GET",
37+
"https://marvinborner.de/lead/binaryfun1/list?sort=time&order=asc&count=1000&filter=difficulty,"+diff,
38+
false)
39+
xhr.send()
40+
if (xhr.status !== 0) {
41+
list.model = JSON.parse(xhr.responseText);
42+
internet.visible = false;
43+
} else {
44+
internet.visible = true;
45+
}
1946
}
47+
48+
menu: ContextMenu {
49+
MenuItem {
50+
text: qsTr("Please select")
51+
}
52+
MenuItem {
53+
property int diff: 2
54+
text: qsTr("Very easy (2 Bit)")
55+
onClicked: selector.select(diff)
56+
}
57+
MenuItem {
58+
property int diff: 4
59+
text: qsTr("Easy (4 Bit)")
60+
onClicked: selector.select(diff)
61+
}
62+
MenuItem {
63+
property int diff: 6
64+
text: qsTr("Medium (6 Bit)")
65+
onClicked: selector.select(diff)
66+
}
67+
MenuItem {
68+
property int diff: 8
69+
text: qsTr("Hard (8 Bit)")
70+
onClicked: selector.select(diff)
71+
}
72+
MenuItem {
73+
property int diff: 10
74+
text: qsTr("God-like (10 Bit)")
75+
onClicked: selector.select(diff)
76+
}
77+
}
78+
}
79+
80+
Label {
81+
id: internet
82+
text: qsTr("No internet connection!")
83+
visible: false
2084
}
85+
86+
ListView {
87+
id: list
88+
clip: true
89+
width: page.width
90+
height: page.height - y
91+
model: []
92+
delegate: ListItem {
93+
contentHeight: Theme.itemSizeMedium
94+
95+
Label {
96+
id: name
97+
text: index + 1 + ". " + modelData.name
98+
}
99+
100+
Label {
101+
anchors.top: name.bottom
102+
text: ((modelData.end_time[1] - modelData.start_time[1]) / 1000) + "s - Help: " + modelData.cheats
103+
font.pixelSize: Theme.fontSizeSmall
104+
}
105+
}
106+
}
107+
}
108+
109+
ConfigurationValue {
110+
id: username
111+
key: "/com/binaryfun/username"
112+
defaultValue: "anon"
21113
}
22114
}

qml/pages/Menu.qml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Page {
99
anchors.fill: parent
1010
contentHeight: column.height
1111

12+
PullDownMenu {
13+
MenuItem {
14+
text: qsTr("Leaderboard")
15+
onClicked: pageStack.push(Qt.resolvedUrl("LeaderBoard.qml"))
16+
}
17+
}
18+
1219
Column {
1320
property bool bar: false
1421

rpm/harbour-binaryfun.spec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ Name: harbour-binaryfun
1313
%{!?qtc_make:%define qtc_make make}
1414
%{?qtc_builddir:%define _builddir %qtc_builddir}
1515
Summary: An awesome binary game
16-
Version: 0.2
16+
Version: 1.0
1717
Release: 1
1818
Group: Qt/Qt
1919
License: MIT
2020
URL: https://openrepos.net/content/melvin/binary-fun
2121
Source0: %{name}-%{version}.tar.bz2
2222
Source100: harbour-binaryfun.yaml
2323
Requires: sailfishsilica-qt5 >= 0.10.9
24+
Requires: nemo-qml-plugin-configuration-qt5
2425
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
2526
BuildRequires: pkgconfig(Qt5Core)
2627
BuildRequires: pkgconfig(Qt5Qml)

rpm/harbour-binaryfun.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: harbour-binaryfun
22
Summary: An awesome binary game
3-
Version: 0.2
3+
Version: 1.0
44
Release: 1
55
# The contents of the Group field should be one of the groups listed here:
66
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
@@ -32,7 +32,8 @@ PkgConfigBR:
3232

3333
# Runtime dependencies which are not automatically detected
3434
Requires:
35-
- sailfishsilica-qt5 >= 0.10.9
35+
- sailfishsilica-qt5 >= 0.10.9
36+
- nemo-qml-plugin-configuration-qt5
3637

3738
# All installed files
3839
Files:

translations/harbour-binaryfun-de.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>CoverPage</name>
66
<message>
77
<source>Binary Fun</source>
8-
<translation type="unfinished">Binär-Spaß</translation>
8+
<translation>Binär-Spaß</translation>
99
</message>
1010
</context>
1111
<context>
@@ -22,12 +22,44 @@
2222
<source>Not bad!</source>
2323
<translation>Nicht schlecht!</translation>
2424
</message>
25+
<message>
26+
<source>Leaderboard</source>
27+
<translation>Bestenliste</translation>
28+
</message>
2529
</context>
2630
<context>
2731
<name>LeaderBoard</name>
2832
<message>
29-
<source>Under Construction!</source>
30-
<translation>Im Aufbau!</translation>
33+
<source>Leaderboard</source>
34+
<translation>Bestenliste</translation>
35+
</message>
36+
<message>
37+
<source>Very easy (2 Bit)</source>
38+
<translation>Sehr einfach (2 Bit)</translation>
39+
</message>
40+
<message>
41+
<source>Easy (4 Bit)</source>
42+
<translation>Einfach (4 Bit)</translation>
43+
</message>
44+
<message>
45+
<source>Medium (6 Bit)</source>
46+
<translation>Mittel (6 Bit)</translation>
47+
</message>
48+
<message>
49+
<source>Hard (8 Bit)</source>
50+
<translation>Schwer (8 Bit)</translation>
51+
</message>
52+
<message>
53+
<source>God-like (10 Bit)</source>
54+
<translation>Krass (10 Bit)</translation>
55+
</message>
56+
<message>
57+
<source>Please select</source>
58+
<translation>Bitte auswählen</translation>
59+
</message>
60+
<message>
61+
<source>No internet connection!</source>
62+
<translation>Keine Internetverbindung!</translation>
3163
</message>
3264
</context>
3365
<context>
@@ -58,7 +90,11 @@
5890
</message>
5991
<message>
6092
<source>Help bar</source>
61-
<translation>Legende</translation>
93+
<translation>Hilfs-Legende</translation>
94+
</message>
95+
<message>
96+
<source>Leaderboard</source>
97+
<translation>Bestenliste</translation>
6298
</message>
6399
</context>
64100
</TS>

translations/harbour-binaryfun.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,43 @@
2222
<source>Not bad!</source>
2323
<translation type="unfinished"></translation>
2424
</message>
25+
<message>
26+
<source>Leaderboard</source>
27+
<translation type="unfinished"></translation>
28+
</message>
2529
</context>
2630
<context>
2731
<name>LeaderBoard</name>
2832
<message>
29-
<source>Under Construction!</source>
33+
<source>Leaderboard</source>
34+
<translation type="unfinished"></translation>
35+
</message>
36+
<message>
37+
<source>Very easy (2 Bit)</source>
38+
<translation type="unfinished"></translation>
39+
</message>
40+
<message>
41+
<source>Easy (4 Bit)</source>
42+
<translation type="unfinished"></translation>
43+
</message>
44+
<message>
45+
<source>Medium (6 Bit)</source>
46+
<translation type="unfinished"></translation>
47+
</message>
48+
<message>
49+
<source>Hard (8 Bit)</source>
50+
<translation type="unfinished"></translation>
51+
</message>
52+
<message>
53+
<source>God-like (10 Bit)</source>
54+
<translation type="unfinished"></translation>
55+
</message>
56+
<message>
57+
<source>Please select</source>
58+
<translation type="unfinished"></translation>
59+
</message>
60+
<message>
61+
<source>No internet connection!</source>
3062
<translation type="unfinished"></translation>
3163
</message>
3264
</context>
@@ -60,5 +92,9 @@
6092
<source>Help bar</source>
6193
<translation type="unfinished"></translation>
6294
</message>
95+
<message>
96+
<source>Leaderboard</source>
97+
<translation type="unfinished"></translation>
98+
</message>
6399
</context>
64100
</TS>

0 commit comments

Comments
 (0)