Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion apps/discord-bot/src/commands/tntgames/tntgames.command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { BaseHypixelCommand, BaseProfileProps } from "../base.hypixel-command";
import { Command } from "@statsify/discord";
import { TNTGamesModes, TNT_GAMES_MODES } from "@statsify/schemas";
import { GameMode, Player, TNTGamesModes, TNT_GAMES_MODES } from "@statsify/schemas";
import { TNTGamesProfile } from "./tntgames.profile";

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

public filterModes(
player: Player,
modes: GameMode<TNTGamesModes>[]
): GameMode<TNTGamesModes>[] {
const [overall] = modes;

return [overall];
}

public getProfile(base: BaseProfileProps): JSX.Element {
return <TNTGamesProfile {...base} />;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/schemas/src/game/game-modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import { prettify } from "@statsify/util";

interface StatsifyGameMode<T extends string> {
export interface StatsifyGameMode<T> {
hypixel?: string;
api: T;
formatted?: string;
}

interface HypixelGameMode {
export interface HypixelGameMode {
hypixel: string;
formatted: string;
}
Expand All @@ -37,7 +37,7 @@ export class GameModes<K extends string> {

this.hypixelModes = Object.fromEntries(
modes
.filter((m) => "hypixel" in m)
.filter((m) => m.hypixel)
.map((m) => [m.hypixel, m.formatted ?? prettify((m as GameMode<any>).api)])
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/schemas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* https://github.com/Statsify/statsify/blob/main/LICENSE
*/

export { METADATA_KEY } from "./metadata/constants";
export { FIELD_METADATA_KEY as METADATA_KEY } from "./metadata/constants";
export * from "./color";
export * from "./commands";
export * from "./friends";
Expand Down
75 changes: 75 additions & 0 deletions packages/schemas/src/metadata/GameType/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) Statsify
*
* This source code is licensed under the GNU GPL v3 license found in the
* LICENSE file in the root directory of this source tree.
* https://github.com/Statsify/statsify/blob/main/LICENSE
*/

import { ChallengesBedWars } from "../../player";
import { Constructor } from "@statsify/util";
import { HypixelGameMode, StatsifyGameMode } from "../../game";
import { Progression } from "../../progression";

const GAMETYPE_METADATA_KEY = "statsify:gametype";

export interface HypixelGameMetadata {
gameModes?: StatsifyGameMode<string>[];
}

type ignoredTypes = string | boolean | number | Progression | ChallengesBedWars;
type OptionalString<K = void> = K extends string ? K : never;

export type StatsifyApiModes<T, K = void> =
| OptionalString<K>
| keyof Pick<
T,
{
[Key in keyof T]: T[Key] extends ignoredTypes ? never : Key;
}[keyof T]
>;

export function Mode(hypixel?: string, formatted?: string): PropertyDecorator {
return (target, propertyKey) => {
const { gameModes = [] } = (Reflect.getMetadata(GAMETYPE_METADATA_KEY, target) ??
{}) as HypixelGameMetadata;

hypixel = hypixel === "" ? undefined : hypixel;
formatted = formatted === "" ? undefined : formatted;

Reflect.defineMetadata(
GAMETYPE_METADATA_KEY,
{
gameModes: [...gameModes, { hypixel, api: propertyKey, formatted }],
},
target
);
};
}

export function GameType(
baseName?: string,
hypixel?: string,
formatted?: string
): ClassDecorator {
return (target: any) => {
if (!baseName) return;
const { gameModes = [] } = (Reflect.getMetadata(GAMETYPE_METADATA_KEY, target) ??
{}) as HypixelGameMetadata;

Reflect.defineMetadata(
GAMETYPE_METADATA_KEY,
{
gameModes: [{ api: baseName, hypixel, formatted }, ...gameModes],
},
target
);
};
}

export function GetMetadataModes(target: Constructor) {
const { gameModes = [] } = (Reflect.getMetadata(GAMETYPE_METADATA_KEY, target) ??
{}) as HypixelGameMetadata;

return gameModes as HypixelGameMode[];
}
2 changes: 1 addition & 1 deletion packages/schemas/src/metadata/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Constructor } from "@statsify/util";

export const METADATA_KEY = "statsify";
export const FIELD_METADATA_KEY = "statsify:field";

export const primitiveConstructors = [
String,
Expand Down
7 changes: 4 additions & 3 deletions packages/schemas/src/metadata/field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import { ApiHideProperty, ApiProperty } from "@nestjs/swagger";
import { ClassMetadata } from "../metadata.interface";
import { FIELD_METADATA_KEY } from "../constants";
import { FieldOptions } from "../field.options";
import { METADATA_KEY } from "../constants";
import { getLeaderboardMetadata } from "./get-leaderboard-metadata";
import { getStoreMetadata } from "./get-store-metadata";
import { getTypeMetadata } from "./get-type-metadata";
Expand All @@ -23,7 +23,8 @@ export function Field({
mongo: mongoOptions,
}: FieldOptions = {}): PropertyDecorator {
return (target, propertyKey) => {
const metadata = (Reflect.getMetadata(METADATA_KEY, target) ?? {}) as ClassMetadata;
const metadata = (Reflect.getMetadata(FIELD_METADATA_KEY, target) ??
{}) as ClassMetadata;

const type = getTypeMetadata(typeOptions, target, propertyKey);
const leaderboard = getLeaderboardMetadata(
Expand All @@ -34,7 +35,7 @@ export function Field({
const store = getStoreMetadata(type, leaderboard, storeOptions);

Reflect.defineMetadata(
METADATA_KEY,
FIELD_METADATA_KEY,
{
...metadata,
[propertyKey as string]: {
Expand Down
1 change: 1 addition & 0 deletions packages/schemas/src/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

export * from "./field";
export * from "./GameType";
export * from "./metadata-scanner";
export * from "./serialize";
export * from "./field.options";
4 changes: 2 additions & 2 deletions packages/schemas/src/metadata/metadata-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import { ClassMetadata, FieldMetadata } from "./metadata.interface";
import { Constructor } from "@statsify/util";
import { FIELD_METADATA_KEY } from "./constants";
import { LEADERBOARD_RATIO_KEYS } from "../ratios";
import { METADATA_KEY } from "./constants";

export type MetadataEntry = [string, FieldMetadata];

Expand All @@ -32,7 +32,7 @@ export class MetadataScanner {
baseName = ""
): MetadataEntry[] {
const classMetadata = Reflect.getMetadata(
METADATA_KEY,
FIELD_METADATA_KEY,
constructor.prototype
) as ClassMetadata;

Expand Down
56 changes: 30 additions & 26 deletions packages/schemas/src/player/gamemodes/arcade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,94 +29,95 @@ import {
Zombies,
} from "./mode";
import { Field } from "../../../metadata";
import { GameModes, IGameModes } from "../../../game";

export const ARCADE_MODES = new GameModes([
{ api: "overall" },
{ api: "blockingDead", hypixel: "DAYONE" },
{ api: "bountyHunters", hypixel: "ONEINTHEQUIVER" },
{ api: "captureTheWool", hypixel: "PVP_CTW" },
{ api: "creeperAttack", hypixel: "DEFENDER" },
{ api: "dragonWars", hypixel: "DRAGONWARS2" },
{ api: "enderSpleef", hypixel: "ENDER" },
{ api: "farmHunt", hypixel: "FARM_HUNT" },
{ api: "football", hypixel: "SOCCER" },
{ api: "galaxyWars", hypixel: "STARWARS" },
{ api: "hideAndSeek" },
{ api: "holeInTheWall", hypixel: "HOLE_IN_THE_WALL" },
{ api: "hypixelSays", hypixel: "SIMON_SAYS" },
{ api: "miniWalls", hypixel: "MINI_WALLS" },
{ api: "partyGames", hypixel: "PARTY" },
{ api: "pixelPainters", hypixel: "DRAW_THEIR_THING" },
{ api: "pixelParty", hypixel: "PIXEL_PARTY" },
{ api: "seasonal" },
{ api: "throwOut", hypixel: "THROW_OUT" },
{ api: "zombies" },
]);

export type ArcadeModes = IGameModes<typeof ARCADE_MODES>;
import { GameModes } from "../../../game";
import {
GameType,
GetMetadataModes,
Mode,
StatsifyApiModes,
} from "../../../metadata/GameType";

@GameType("overall")
export class Arcade {
@Field()
public coins: number;

@Field()
public wins: number;

@Mode("DAYONE")
@Field()
public blockingDead: BlockingDead;

@Mode("ONEINTHEQUIVER")
@Field()
public bountyHunters: BountyHunters;

@Mode("PVP_CTW")
@Field()
public captureTheWool: CaptureTheWool;

@Mode("DEFENDER")
@Field()
public creeperAttack: CreeperAttack;

@Mode("DRAGONWARS2")
@Field()
public dragonWars: DragonWars;

@Mode("ENDER")
@Field()
public enderSpleef: EnderSpleef;

@Mode("FARM_HUNT")
@Field()
public farmHunt: FarmHunt;

@Mode("SOCCER")
@Field()
public football: Football;

@Mode("STARWARS")
@Field()
public galaxyWars: GalaxyWars;

@Mode()
@Field()
public hideAndSeek: HideAndSeek;

@Mode("HOLE_IN_THE_WALL")
@Field()
public holeInTheWall: HoleInTheWall;

@Mode("SIMON_SAYS")
@Field()
public hypixelSays: HypixelSays;

@Mode("MINI_WALLS")
@Field()
public miniWalls: MiniWalls;

@Mode("PARTY")
@Field()
public partyGames: PartyGames;

@Mode("DRAW_THEIR_THING")
@Field()
public pixelPainters: PixelPainters;

@Mode("PIXEL_PARTY")
@Field()
public pixelParty: PixelParty;

@Mode()
@Field()
public seasonal: Seasonal;

@Mode("THROW_OUT")
@Field()
public throwOut: ThrowOut;

@Mode()
@Field()
public zombies: Zombies;

Expand Down Expand Up @@ -145,5 +146,8 @@ export class Arcade {
}
}

export type ArcadeModes = StatsifyApiModes<Arcade, "overall">;
export const ARCADE_MODES = new GameModes<ArcadeModes>(GetMetadataModes(Arcade));

export * from "./mode";
export * from "./seasonal-mode";
Loading