Skip to content

Commit

Permalink
Add gold on NBQ leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tombertrand committed Jul 19, 2023
1 parent 1890a18 commit 3325a9a
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 50 deletions.
Binary file added public/nanobrowserquest/gold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 29 additions & 16 deletions server/cron/nanobrowserquestStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,40 @@ const getNanoBrowserQuestLeaderboard = async () => {
const playersChunks = chunk(players, PER_PAGES);

for (let i = 0; i < playersChunks.length; i++) {
if (playersChunks[i] === "u:running-coder") continue;

const rawPlayerData = await Promise.all(
playersChunks[i].map(
player =>
new Promise(resolve => {
client.hmget(player, "hash", "network", "exp", (_err, reply) => {
const network = reply[1];
const exp = parseInt(reply[2] || 0);
if (player === "u:running-coder") {
resolve(undefined);
}

client.hmget(
player,
"hash",
"network",
"exp",
"gold",
"goldStash",
(_err, reply) => {
const network = reply[1];
const exp = Number(reply[2] || 0);
const gold = Number(reply[3] || 0);
const goldStash = Number(reply[4] || 0);

if (network === "ban" || !exp) {
resolve(undefined);
} else {
resolve({
player: player.replace("u:", ""),
isCompleted: !!reply[0],
network,
exp: parseInt(reply[2] || 0),
});
}
});
if (network === "ban" || !exp) {
resolve(undefined);
} else {
resolve({
player: player.replace("u:", ""),
isCompleted: !!reply[0],
network,
exp: parseInt(reply[2] || 0),
gold: gold + goldStash,
});
}
},
);
}),
),
);
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "دليل NanoBrowserQuest"
},
"playerGuide": "دليل اللاعب"
"playerGuide": "دليل اللاعب",
"gold": "ذهب"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "NanoBrowserQuest-Spielanleitung"
},
"playerGuide": "Anleitung für Spieler"
"playerGuide": "Anleitung für Spieler",
"gold": "Gold"
},
"statistics": {
"social": {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
"rank": "Rank",
"player": "Player",
"exp": "Experience",
"gold": "Gold",
"nanoPotions": "NANO Potions",
"level": "Level",
"howToPlay": "How to play",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "Guía de NanoBrowserQuest"
},
"playerGuide": "Guía del jugador"
"playerGuide": "Guía del jugador",
"gold": "Oro"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "راهنمای NanoBrowserQuest"
},
"playerGuide": "راهنمای بازیکن"
"playerGuide": "راهنمای بازیکن",
"gold": "طلا"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "Guide NanoBrowserQuest"
},
"playerGuide": "Guide du joueur"
"playerGuide": "Guide du joueur",
"gold": "Or"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "नैनोब्राउज़रक्वेस्ट गाइड"
},
"playerGuide": "प्लेयर्स गाइड"
"playerGuide": "प्लेयर्स गाइड",
"gold": "सोना"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "Guida di NanoBrowserQuest"
},
"playerGuide": "Guida del giocatore"
"playerGuide": "Guida del giocatore",
"gold": "Oro"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "NanoBrowserQuestガイド"
},
"playerGuide": "プレイヤーズガイド"
"playerGuide": "プレイヤーズガイド",
"gold": ""
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "NanoBrowserQuest 가이드"
},
"playerGuide": "플레이어 가이드"
"playerGuide": "플레이어 가이드",
"gold": ""
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "NanoBrowserQuest-gids"
},
"playerGuide": "Spelersgids"
"playerGuide": "Spelersgids",
"gold": "Goud"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@
"guide": {
"title": "Przewodnik po NanoBrowserQu"
},
"playerGuide": "Przewodnik gracza"
"playerGuide": "Przewodnik gracza",
"gold": "Złoto"
}
}
}
3 changes: 2 additions & 1 deletion src/i18n/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "Guia do NanoBrowserQuest"
},
"playerGuide": "Guia do jogador"
"playerGuide": "Guia do jogador",
"gold": "Ouro"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "Руководство NanoBrowserQuest"
},
"playerGuide": "Руководство игрока"
"playerGuide": "Руководство игрока",
"gold": "Золото"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "NanoBrowserQuest Kılavuzu"
},
"playerGuide": "Oyuncu Kılavuzu"
"playerGuide": "Oyuncu Kılavuzu",
"gold": "Altın"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "Hướng dẫn NanoBrowserQuest"
},
"playerGuide": "Hướng dẫn người chơi"
"playerGuide": "Hướng dẫn người chơi",
"gold": "Vàng"
},
"statistics": {
"social": {
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
"guide": {
"title": "NanoBrowserQuest 指南"
},
"playerGuide": "玩家指南"
"playerGuide": "玩家指南",
"gold": "金子"
},
"statistics": {
"social": {
Expand Down
36 changes: 22 additions & 14 deletions src/pages/NanoBrowserQuest/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";
import { Card, Col, Pagination, Row, Skeleton, Typography } from "antd";
import chunk from "lodash/chunk";

import Trophy, { fontSizeToRankMap } from "components/Trophy";
import Trophy from "components/Trophy";

import useNanoBrowserQuestLeaderboard from "./hooks/use-nanobrowserquest-leaderboard";
import { getLevel } from "./utils";
Expand All @@ -28,46 +28,54 @@ const Leaderboard: React.FC = () => {
<Card size="small" className="detail-layout">
<Row gutter={12}>
<Col xs={3}>{t("pages.nanobrowserquest.rank")}</Col>
<Col xs={12}>{t("pages.nanobrowserquest.player")}</Col>
<Col xs={8}>{t("pages.nanobrowserquest.player")}</Col>
<Col xs={3}>{t("pages.nanobrowserquest.level")}</Col>
<Col xs={6}>{t("pages.nanobrowserquest.exp")}</Col>
<Col xs={5}>{t("pages.nanobrowserquest.exp")}</Col>
<Col xs={5}>
{t("pages.nanobrowserquest.gold")}{" "}
<img alt="Gold" src={`/nanobrowserquest/gold.png`} style={{ marginLeft: "3px" }} />
</Col>
</Row>
{isLoading ? (
Array.from(Array(5).keys()).map(index => (
<Row gutter={12} key={index}>
<Col xs={3}>
<Skeleton loading={true} paragraph={false} active />
</Col>
<Col xs={12}>
<Col xs={8}>
<Skeleton loading={true} paragraph={false} active />
</Col>
<Col xs={3}>
<Skeleton loading={true} paragraph={false} active />
</Col>
<Col xs={6}>
<Col xs={5}>
<Skeleton loading={true} paragraph={false} active />
</Col>
<Col xs={5}>
<Skeleton loading={true} paragraph={false} active />
</Col>
</Row>
))
) : (
<>
{paginatedTopScores[currentPage - 1]?.map(({ rank, player, exp, nanoPotions }) => (
{paginatedTopScores[currentPage - 1]?.map(({ rank, player, exp, gold }) => (
<Row gutter={12} key={rank}>
<Col xs={3}>
<Text style={{ fontSize: fontSizeToRankMap[rank] ?? "auto" }}>
<Text>
#{rank} <Trophy rank={rank} />
</Text>
</Col>
<Col xs={12}>
<Text style={{ fontSize: fontSizeToRankMap[rank] ?? "auto" }}>{player}</Text>
<Col xs={8}>
<Text>{player}</Text>
</Col>
<Col xs={3}>
<Text style={{ fontSize: fontSizeToRankMap[rank] ?? "auto" }}>
{getLevel(exp)}
</Text>
<Text>{getLevel(exp)}</Text>
</Col>
<Col xs={5}>
<Text>{new Intl.NumberFormat("en-EN", {}).format(exp)}</Text>
</Col>
<Col xs={6}>
<Text style={{ fontSize: fontSizeToRankMap[rank] ?? "auto" }}>{exp}</Text>
<Col xs={5}>
<Text>{new Intl.NumberFormat("en-EN", {}).format(gold)}</Text>
</Col>
</Row>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ const useNanoBrowserQuestPlayers = () => {
});
const json = (await res.json()) as Player[];

const mappedLeaderboard = orderBy(json, ["exp"], ["desc"]).map((player, index) => ({
...player,
rank: index + 1,
}));
const mappedLeaderboard = orderBy(json, ["exp", "gold"], ["desc", "desc"]).map(
(player, index) => ({
...player,
rank: index + 1,
}),
);

setLeaderboard(mappedLeaderboard);
} catch (err) {
Expand Down

0 comments on commit 3325a9a

Please sign in to comment.