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

Commit

Permalink
v1.0 - Added awesome leaderboard!
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marvinborner committed Apr 5, 2020
1 parent bfb99fe commit bf800f3
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 18 deletions.
27 changes: 24 additions & 3 deletions qml/pages/Game.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
import org.nemomobile.configuration 1.0
import ".."

Page {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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(","))
}
}
}
Expand Down Expand Up @@ -124,4 +139,10 @@ Page {
}
}
}

ConfigurationValue {
id: username
key: "/com/binaryfun/username"
defaultValue: "anon"
}
}
106 changes: 99 additions & 7 deletions qml/pages/LeaderBoard.qml
Original file line number Diff line number Diff line change
@@ -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"
}
}
7 changes: 7 additions & 0 deletions qml/pages/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion rpm/harbour-binaryfun.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ 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
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)
Expand Down
5 changes: 3 additions & 2 deletions rpm/harbour-binaryfun.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
44 changes: 40 additions & 4 deletions translations/harbour-binaryfun-de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
38 changes: 37 additions & 1 deletion translations/harbour-binaryfun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -60,5 +92,9 @@
<source>Help bar</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Leaderboard</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

0 comments on commit bf800f3

Please sign in to comment.