Skip to content

Commit 4353ec3

Browse files
author
Patrick Sachs
authored
Merge pull request #81 from PatrickSachs/onlineLeaderboard
Online leaderboard
2 parents 01b2062 + 0f87922 commit 4353ec3

File tree

8 files changed

+174
-3
lines changed

8 files changed

+174
-3
lines changed

README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Je mehr Konfetti man erzeugt desto bessere Upgrades können für den eigenen Loc
2020
#### Verwenden
2121

2222
Der Leaderboard REST Server ist unter https://sim-locher.herokuapp.com/ erreichbar.
23+
Es zeigt im Moment ein Leaderboard an. Richtig Nice.
2324

2425
Folgende HTTP Requests können verwendet werden(Alle Requests verwenden XML als Payload Format):
2526

server/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const mongoose = require("mongoose");
44
const bodyParser = require("express-xml-bodyparser");
55
const BadWordFilter = require("bad-words");
66
const xml2js = require("xml2js");
7+
const path = require("path");
78

89
const js2xml = new xml2js.Builder();
910

@@ -51,6 +52,7 @@ mongoose.connection.once("open", () => {
5152
console.log(`Datenbank verbunden`);
5253
express()
5354
.use(bodyParser({ trim: true }))
55+
.use(express.static(path.join(__dirname, "static")))
5456
.use((req, res, next) => {
5557
res.xml = payload => res
5658
.contentType("text/xml")
@@ -59,8 +61,8 @@ mongoose.connection.once("open", () => {
5961
})
6062

6163
// Weiterleitung auf GitHub für index Dokument
62-
.get("/", (req, res) => {
63-
return res.redirect("https://github.com/PatrickSachs/sim-locher/");
64+
.get("/github", (req, res) => {
65+
return res.redirect("https://github.com/PatrickSachs/sim-locher/releases/latest");
6466
})
6567

6668
// Score per POST speichern. (POST /ap/leaderboard { "name": "Spielername", "punkte": 3431 })

server/static/index.html

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!DOCTYPE html>
2+
<html lang="de">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>sim-locher Leaderboard</title>
9+
<link rel="icon" type="img" href="./public/img/locher_icon.ico" />
10+
<link rel="stylesheet" type="text/css" href="./resources/css/style.css" />
11+
<link href="https://fonts.googleapis.com/css?family=Sedgwick+Ave" rel="stylesheet">
12+
</head>
13+
14+
<body>
15+
<h1>👑Leaderboard:👑</h1>
16+
<img src="./public/img/locher_animated.gif" alt="Cooler Locher" style="left: 20px; position: fixed"/>
17+
<img src="./public/img/locher_animated.gif" alt="Cooler Locher" style="right: 20px; position: fixed; transform: rotateY(180deg);"/>
18+
<script>
19+
function getLeaderboard() {
20+
//request the leaderboard
21+
fetch("/api/leaderboard")
22+
.then(response => response.text())
23+
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
24+
.then(data => {
25+
var children_1 = data.children[0];
26+
var counter = 0;
27+
for (i = 0; i < children_1.children.length; i++) {
28+
var children_2 = children_1.children[i];
29+
30+
var children_3_name = children_2.children[0];
31+
var children_3_value = children_2.children[1];
32+
33+
counter++;
34+
var counter_text = document.createTextNode(counter + ". ")
35+
var name = document.createTextNode(children_3_name.innerHTML + ": ");
36+
var score = document.createTextNode(children_3_value.innerHTML);
37+
38+
39+
40+
var para = document.createElement("P");
41+
42+
para.appendChild(counter_text);
43+
para.appendChild(name);
44+
para.appendChild(score);
45+
46+
47+
if (counter == 1) {
48+
para.setAttribute("id", "number1");
49+
}
50+
else if (counter == 2) {
51+
para.setAttribute("id", "number2");
52+
}
53+
else if (counter == 3) {
54+
para.setAttribute("id", "number3");
55+
}
56+
57+
document.body.appendChild(para);
58+
59+
}
60+
61+
var urlAddition = window.location.search;
62+
if (urlAddition == "?nobutton") {
63+
var footer = document.getElementsByClassName("footer");
64+
footer[0].classList.add("notShow");
65+
}
66+
67+
})
68+
69+
}
70+
getLeaderboard();
71+
</script>
72+
</body>
73+
74+
<div class="footer">
75+
<a href="/github">Download des Spiels</a>
76+
</div>
77+
78+
</html>
425 KB
Loading
61.7 KB
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
body {
2+
background-color: gray;
3+
font-family: 'Sedgwick Ave', cursive;
4+
}
5+
6+
p {
7+
color: white;
8+
text-align: center;
9+
text-shadow: 2px 2px 4px black;
10+
font-size: 15px;
11+
}
12+
13+
h1 {
14+
text-align: center;
15+
font-style: italic;
16+
}
17+
18+
@media all and (max-width: 850px) {
19+
img {
20+
display: none;
21+
}
22+
}
23+
24+
img {
25+
height: 50%;
26+
z-index: -1;
27+
}
28+
29+
#number1 {
30+
color: gold;
31+
font-size: 21px;
32+
}
33+
34+
#number2 {
35+
color: silver;
36+
font-size: 19px;
37+
}
38+
39+
#number3 {
40+
color: #9b2903;
41+
font-size: 17px;
42+
}
43+
44+
.footer {
45+
position: absolute;
46+
right: 0;
47+
bottom: 0;
48+
left: 0;
49+
padding: 1rem;
50+
background-color: darkgray;
51+
text-align: center;
52+
}
53+
54+
.notShow {
55+
display: none;
56+
}
57+
58+
a {
59+
color: black;
60+
text-decoration: none;
61+
}

src/main/java/de/wolc/gui/ItemShopMenu.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ private Node guiButtons() {
139139
});
140140
Button leaderboardButton = new Button("🏅 Leaderboard 🏅");
141141
leaderboardButton.addEventHandler(ActionEvent.ACTION, (ActionEvent actionEvent) -> {
142-
this.leaderboard();
142+
Stage stageLeaderboard = new Stage();
143+
LeaderboardMenu sm = new LeaderboardMenu();
144+
stageLeaderboard.setScene(sm.LeaderboardScene(stageLeaderboard));
145+
stageLeaderboard.centerOnScreen();
146+
stageLeaderboard.show();
143147
});
144148
grid.add(backButton, 0, 0);
145149
grid.add(continueButton, 1, 0);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.wolc.gui;
2+
3+
import javafx.stage.Stage;
4+
import javafx.scene.Scene;
5+
import javafx.scene.web.WebView;
6+
7+
public class LeaderboardMenu {
8+
private final String windowTitle = "LEADERBOARD von World of Lochercraft";
9+
10+
public Scene LeaderboardScene(Stage stage) {
11+
final WebView webview = new WebView();
12+
webview.getEngine().load("https://sim-locher.herokuapp.com/?nobutton");
13+
webview.setPrefSize(640, 390);
14+
15+
Scene sceneMainWindow = new Scene(webview);
16+
17+
// Updating the Title
18+
stage.setTitle(windowTitle);
19+
stage.setOnCloseRequest(e -> {
20+
webview.getEngine().load(null);
21+
});
22+
23+
return sceneMainWindow;
24+
}
25+
}

0 commit comments

Comments
 (0)