From a6bab7c44937adc09fc32b1b8b04b57fc1d2f52e Mon Sep 17 00:00:00 2001
From: Anay
Date: Thu, 15 Feb 2024 16:42:15 +0800
Subject: [PATCH] added leaderboard pagination to go through entire leaderboard
---
app/backend/api.py | 3 +-
app/backend/database.py | 2 +-
app/frontend/index.html | 46 +++++-----
app/frontend/results.html | 176 ++++++++++++++++++++++++++++++++++---
app/frontend/tutorial.html | 8 ++
5 files changed, 200 insertions(+), 35 deletions(-)
diff --git a/app/backend/api.py b/app/backend/api.py
index 7555a89..2f9f8c3 100644
--- a/app/backend/api.py
+++ b/app/backend/api.py
@@ -26,8 +26,9 @@ async def discoveries_leaderboard():
@router.get("/all")
async def discoveries_leaderboard():
leaderboard = get_leaderboard('city', 'all')
- response = {i + 1: list(val) for i, val in enumerate(leaderboard)}
+ response = [{'pos': i + 1, 'score': val[0], 'usern': val[1]} for i, val in enumerate(leaderboard)]
return JSONResponse(content=response)
+
'''
NOTICE:
DO NOT REFACTOR/MERGE THESE APIS; IF WE DYNAMICALLY SELECT LEADERBORADS VIA DYNAMIC USER INPUT - THIS MEANS WE NEED TO VALIDATE/SANITISE SUCH INPUT, THIS IS NOT DONE VIA THESE FUNCTIONS THAT INTERACT WITH THE DB
diff --git a/app/backend/database.py b/app/backend/database.py
index 40013bb..4a23129 100644
--- a/app/backend/database.py
+++ b/app/backend/database.py
@@ -119,4 +119,4 @@ def update_game(game_mode, username, totalscore):
if newmax:
return {"score":"complete", "alert":"new high score"}
else:
- return {"score":"complete", "alert":"no new high score"}
+ return {"score":"complete", "alert":"no new high score"}
\ No newline at end of file
diff --git a/app/frontend/index.html b/app/frontend/index.html
index 7de9170..0138b61 100644
--- a/app/frontend/index.html
+++ b/app/frontend/index.html
@@ -90,21 +90,14 @@
function enterMainPage(selectedMode) {
const username = document.getElementById('username').value;
- // const matcher = new RegExpMatcher({
- // ...englishDataset.build(),
- // ...englishRecommendedTransformers,
- // });
- // const hasMatch = matcher.hasMatch(username);
-
- const usernameRegex = new RegExp('^[a-zA-Z0-9._ ]+$', 'i');
+ const usernameRegex = new RegExp('^[a-zA-Z0-9._]{1,15}$', 'i');
+
if (!usernameRegex.test(username)) {
notValidUsername();
return;
}
- // if (hasMatch) {
- // profaneUsername();
- // return;
- // }
+
+
localStorage.setItem("game_mode", selectedMode);
localStorage.setItem("username", username);
if (selectedMode === "city") {
@@ -129,6 +122,17 @@
}
}
+
+ @media screen and (max-width: 600px){
+
+ .game-modes {
+
+ margin-left: 2vw;
+ margin-right: 2vw;
+
+ }
+
+ }
@@ -156,11 +160,10 @@
<
if you get a top score.
-
The username must contain only:
+
The username must be less than 15 characters long and contain only:
Letters
Numbers
-
Spaces
Underscores (_)
Periods (.)
@@ -185,7 +188,7 @@
<
Select a Game Mode
-
+
Select a game mode to play. Each game mode has a different objective and different rules.
Visit the tutorial page to learn more about each game mode.
@@ -209,8 +212,7 @@
<
Street Sleuth
- Find the location of the street you are playing in.
- The closer you are to the location, the more points you get.
+ Find the streets presented to you, and locate them on a satellite map.
@@ -222,8 +224,8 @@
<
Local Landmark
- Find the location of the landmark you are playing in.
- The closer you are to the location, the more points you get.
+ Find the different locations and landmarks presented to you.
+ You must nagivate the Street View and use your own knowledge to find the locations.