Skip to content

Commit

Permalink
feat: revamp /tntgames and add more stats for each mode (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobk999 authored Aug 19, 2024
1 parent ce9567f commit 8cf975f
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class SessionCommand {

@SubCommand({ description: (t) => t("commands.session-tntgames"), args: [PlayerArgument] })
public tntgames(context: CommandContext) {
return this.run(context, TNT_GAMES_MODES, (base) => <TNTGamesProfile {...base} />);
return this.run(context, TNT_GAMES_MODES, (base, mode) => <TNTGamesProfile {...base} mode={mode} />);
}

@SubCommand({
Expand Down
8 changes: 4 additions & 4 deletions apps/discord-bot/src/commands/tntgames/tntgames.command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* https://github.com/Statsify/statsify/blob/main/LICENSE
*/

import { BaseHypixelCommand, BaseProfileProps } from "#commands/base.hypixel-command";
import { BaseHypixelCommand, type BaseProfileProps, type ProfileData } from "#commands/base.hypixel-command";
import { Command } from "@statsify/discord";
import { TNTGamesModes, TNT_GAMES_MODES } from "@statsify/schemas";
import { type TNTGamesModes, TNT_GAMES_MODES } from "@statsify/schemas";
import { TNTGamesProfile } from "./tntgames.profile.js";

@Command({ description: (t) => t("commands.tntgames") })
Expand All @@ -17,7 +17,7 @@ export class TNTGamesCommand extends BaseHypixelCommand<TNTGamesModes> {
super(TNT_GAMES_MODES);
}

public getProfile(base: BaseProfileProps): JSX.Element {
return <TNTGamesProfile {...base} />;
public getProfile(base: BaseProfileProps, { mode }: ProfileData<TNTGamesModes>): JSX.Element {
return <TNTGamesProfile {...base} mode={mode} />;
}
}
198 changes: 127 additions & 71 deletions apps/discord-bot/src/commands/tntgames/tntgames.profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,15 @@
* https://github.com/Statsify/statsify/blob/main/LICENSE
*/

import { Container, Footer, Header, SidebarItem, Table } from "#components";
import { FormattedGame } from "@statsify/schemas";
import { formatTime } from "@statsify/util";
import { Container, Footer, Header, Historical, SidebarItem, Table, formatProgression } from "#components";
import { FormattedGame, type GameMode, type TNTGamesModes } from "@statsify/schemas";
import { formatTime, prettify } from "@statsify/util";
import type { BaseProfileProps } from "#commands/base.hypixel-command";

interface TNTGamesModeColumnProps {
title: string;
stats: [string, string][];
export interface TNTGamesProfileProps extends BaseProfileProps {
mode: GameMode<TNTGamesModes>;
}

const TNTGamesModeColumn = ({ title, stats }: TNTGamesModeColumnProps) => {
const colors = ["§a", "§c", "§6"];

return (
<Table.ts title={`§6${title}`}>
{stats.map(([title, value], index) => (
<Table.td title={title} value={value} color={colors[index]} size="small" />
))}
</Table.ts>
);
};

export const TNTGamesProfile = ({
player,
background,
Expand All @@ -36,77 +23,146 @@ export const TNTGamesProfile = ({
t,
badge,
user,
mode,
time,
}: BaseProfileProps) => {
}: TNTGamesProfileProps) => {
const { tntgames } = player.stats;

const sidebar: SidebarItem[] = [
[t("stats.coins"), t(tntgames.coins), "§6"],
[t("stats.overallWins"), t(tntgames.wins), "§e"],
[t("stats.blocksRan"), t(tntgames.blocksRan), "§7"],
];

let table;

switch (mode.api) {
case "tntRun":
table = (
<>
<Table.tr>
<Table.td title={t("stats.wins")} value={t(tntgames.tntRun.wins)} color="§a" />
<Table.td title={t("stats.losses")} value={t(tntgames.tntRun.losses)} color="§c" />
<Table.td title={t("stats.wlr")} value={t(tntgames.tntRun.wlr)} color="§6" />
</Table.tr>
<Table.tr>
<Table.td title={t("stats.potionsSplashed")} value={t(tntgames.tntRun.potionsSplashed)} color="§5" />
<Table.td title={t("stats.blocksRan")} value={t(tntgames.tntRun.blocksRan)} color="§b" />
<Historical.exclude time={time}>
<Table.td title={t("stats.bestTime")} value={formatTime(tntgames.tntRun.record)} color="§e" />
</Historical.exclude>
</Table.tr>
</>
);
break;
case "pvpRun":
table = (
<>
<Table.tr>
<Table.td title={t("stats.kills")} value={t(tntgames.pvpRun.kills)} color="§a" />
<Table.td title={t("stats.deaths")} value={t(tntgames.pvpRun.deaths)} color="§c" />
<Table.td title={t("stats.kdr")} value={t(tntgames.pvpRun.kdr)} color="§6" />
<Historical.include time={time}>
<Table.td title={t("stats.wins")} value={t(tntgames.pvpRun.wins)} color="§e" />
</Historical.include>
</Table.tr>
<Historical.exclude time={time}>
<Table.tr>
<Table.td title={t("stats.wins")} value={t(tntgames.pvpRun.wins)} color="§a" />
<Table.td title={t("stats.bestTime")} value={formatTime(tntgames.pvpRun.record)} color="§e" />
</Table.tr>
</Historical.exclude>
</>
);
break;
case "bowSpleef":
table = (
<Table.tr>
<Table.td title={t("stats.wins")} value={t(tntgames.bowSpleef.wins)} color="§a" />
<Table.td title={t("stats.losses")} value={t(tntgames.bowSpleef.losses)} color="§c" />
<Table.td title={t("stats.wlr")} value={t(tntgames.bowSpleef.wlr)} color="§6" />
<Table.td title={t("stats.shotsFired")} value={t(tntgames.bowSpleef.hits)} color="§e" />
</Table.tr>
);
break;

case "tntTag":
sidebar.push([t("stats.powerups"), t(tntgames.tntTag.powerups), "§d"]);
table = (
<>
<Table.tr>
<Table.td title={t("stats.kills")} value={t(tntgames.tntTag.kills)} color="§a" />
<Table.td title={t("stats.deaths")} value={t(tntgames.tntTag.deaths)} color="§c" />
<Table.td title={t("stats.kdr")} value={t(tntgames.tntTag.kdr)} color="§6" />
</Table.tr>
<Table.tr>
<Table.td title={t("stats.wins")} value={t(tntgames.tntTag.wins)} color="§a" />
<Table.td title={t("stats.tags")} value={t(tntgames.tntTag.tags)} color="§e" />
</Table.tr>
</>
);
break;
case "wizards":
switch (mode.submode.api) {
case "overall":
sidebar.push(
[t("stats.class"), prettify(tntgames.wizards.class), "§2"],
[t("stats.powerOrbs"), t(tntgames.wizards.powerOrbs), "§a"]
);

table = (
<>
<Table.tr>
<Table.td title={t("stats.kills")} value={t(tntgames.wizards.kills)} color="§a" />
<Table.td title={t("stats.deaths")} value={t(tntgames.wizards.deaths)} color="§c" />
<Table.td title={t("stats.kdr")} value={t(tntgames.wizards.kdr)} color="§6" />
<Table.td title={t("stats.assists")} value={t(tntgames.wizards.assists)} color="§e" />
</Table.tr>
<Table.tr>
<Table.td title={t("stats.wins")} value={t(tntgames.wizards.wins)} color="§a" />
<Table.td title={t("stats.points")} value={t(tntgames.wizards.points)} color="§5" />
<Table.td title={t("stats.airTime")} value={formatTime(tntgames.wizards.airTime)} color="§b" />
</Table.tr>
</>
);
break;
default: {
const stats = tntgames.wizards[mode.submode.api];

table = (
<Table.tr>
<Table.td title={t("stats.kills")} value={t(stats.kills)} color="§a" />
<Table.td title={t("stats.deaths")} value={t(stats.deaths)} color="§c" />
<Table.td title={t("stats.kdr")} value={t(stats.kdr)} color="§6" />
<Table.td title={t("stats.assists")} value={t(stats.assists)} color="§e" />
</Table.tr>
);
break;
}
}
break;
}

return (
<Container background={background}>
<Header
skin={skin}
name={player.prefixName}
badge={badge}
sidebar={sidebar}
title={`§l${FormattedGame.TNT_GAMES} §fStats`}
title={`§l${FormattedGame.TNT_GAMES} §fStats §r(${mode.formatted}${mode.submode ? ` ${mode.submode.formatted}` : ""})`}
description={`§7${t("stats.prefix")}: ${
tntgames[mode.api].naturalPrefix
}\n${formatProgression({
t,
label: t("stats.progression.win"),
progression: tntgames[mode.api].progression,
currentLevel: tntgames[mode.api].currentPrefix,
nextLevel: tntgames[mode.api].nextPrefix,
})}`}
time={time}
/>
<Table.table>
<Table.tr>
<TNTGamesModeColumn
title="PVP Run"
stats={[
[t("stats.wins"), t(tntgames.pvpRun.wins)],
[t("stats.kills"), t(tntgames.pvpRun.kills)],
[t("stats.kdr"), t(tntgames.pvpRun.kdr)],
]}
/>
<TNTGamesModeColumn
title="TNT Run"
stats={
time === "LIVE" ?
[
[t("stats.wins"), t(tntgames.tntRun.wins)],
[t("stats.wlr"), t(tntgames.tntRun.wlr)],
[t("stats.bestTime"), formatTime(tntgames.tntRun.record)],
] :
[
[t("stats.wins"), t(tntgames.tntRun.wins)],
[t("stats.losses"), t(tntgames.tntRun.losses)],
[t("stats.wlr"), t(tntgames.tntRun.wlr)],
]
}
/>
<TNTGamesModeColumn
title="Wizards"
stats={[
[t("stats.wins"), t(tntgames.wizards.wins)],
[t("stats.kills"), t(tntgames.wizards.kills)],
[t("stats.kdr"), t(tntgames.wizards.kdr)],
]}
/>
<TNTGamesModeColumn
title="TNT Tag"
stats={[
[t("stats.wins"), t(tntgames.tntTag.wins)],
[t("stats.kills"), t(tntgames.tntTag.kills)],
[t("stats.tags"), t(tntgames.tntTag.tags)],
]}
/>
<TNTGamesModeColumn
title="Bow Spleef"
stats={[
[t("stats.wins"), t(tntgames.bowSpleef.wins)],
[t("stats.shotsFired"), t(tntgames.bowSpleef.hits)],
[t("stats.wlr"), t(tntgames.bowSpleef.wlr)],
]}
/>
</Table.tr>
{table}
</Table.table>
<Footer logo={logo} user={user} />
</Container>
Expand Down
6 changes: 3 additions & 3 deletions apps/discord-bot/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const mapBackground = <T extends GamesWithBackgrounds>(
return mapBackground(SPEED_UHC_MODES, getDefaultApiMode(SPEED_UHC_MODES));

case "TNT_GAMES":
return mapBackground(TNT_GAMES_MODES, getDefaultApiMode(TNT_GAMES_MODES));
return ["tntgames", "overall"];

case "TURBO_KART_RACERS":
return mapBackground(
Expand All @@ -278,7 +278,7 @@ export const mapBackground = <T extends GamesWithBackgrounds>(
return mapBackground(WARLORDS_MODES, getDefaultApiMode(WARLORDS_MODES));

case "WOOLGAMES":
return mapBackground(WOOLGAMES_MODES, getDefaultApiMode(WOOLGAMES_MODES));
return ["woolgames", "overall"];
}

throw new Error(`Missing background for mode: ${mode}`);
Expand Down Expand Up @@ -322,7 +322,7 @@ export const mapBackground = <T extends GamesWithBackgrounds>(
return ["smashheroes", "overall"];

case TNT_GAMES_MODES:
return ["tntgames", "overall"];
return ["tntgames", mode];

case TURBO_KART_RACERS_MODES:
return ["turbokartracers", "overall"];
Expand Down
5 changes: 4 additions & 1 deletion locales/en-US/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,11 @@
"arcadeWins": "Arcade Wins",
"draws": "Draws",
"sheepThrown": "Sheep Thrown",
"sheepKilled": "Sheep Killed",
"magicWool": "Magic Wool",
"sheepKilled": "Sheep Killed"
"airTime": "Air Time",
"potionsSplashed": "Potions Splashed",
"powerOrbs": "Power Orbs"
},
"tips": {
"discord": "$t(emojis:socials.discord) Join our **$t(socials.discord)** and get **20% lower cooldowns** $t(emojis:heart)",
Expand Down
1 change: 0 additions & 1 deletion packages/discord/src/services/paginate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class PaginateService {
}

if (index !== currentIndex) {
// [TODO]: remove all hooks for sub pages
subController?.unregister(listener);
mainController.switchPage(index);

Expand Down
10 changes: 8 additions & 2 deletions packages/schemas/src/player/gamemodes/prefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ export const defaultPrefix = <T extends unknown[] = []>(
) => getFormattedPrefix({ prefixes, score: prefixes[0].req, ...options });

const RAINBOW_COLORS = ["c", "6", "e", "a", "b", "d", "9"];
const ALT_RAINBOW_COLORS = ["c", "6", "e", "a", "b", "d", "5"];

export const rainbow = (text: string) =>
[...text].map((l, i) => ${RAINBOW_COLORS[i % RAINBOW_COLORS.length]}${l}`).join("");
export const rainbow = (text: string, useAltPalette = false) => {
const colors = useAltPalette ? ALT_RAINBOW_COLORS : RAINBOW_COLORS;

return [...text]
.map((l, i) => ${colors[i % colors.length]}${l}`)
.join("");
};
Loading

0 comments on commit 8cf975f

Please sign in to comment.