Files
blitzkit/packages/website/src/pages/[...chunk_api]/gamemodes/[id]/banner.webp.ts
T

54 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-08-04 19:45:20 -05:00
import type { SquadBattleTypeStylesYaml } from "@blitzkit/core";
import type { APIContext, GetStaticPathsItem } from "astro";
2025-10-23 21:22:21 -05:00
import sharp from "sharp";
2026-08-04 19:45:20 -05:00
import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths";
import { vfs } from "../../../../core/blitzkit/vfs";
import { getStaticPaths as _getStaticPaths } from "../../_index";
2024-08-15 13:35:09 -05:00
2026-08-04 19:45:20 -05:00
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
const paths: GetStaticPathsItem[] = [];
2024-08-16 12:52:29 -05:00
2026-07-31 20:48:33 -05:00
const gameTypeSelectorStyles = await vfs.yaml<SquadBattleTypeStylesYaml>(
2026-04-01 21:40:15 -05:00
`Data/UI/Screens/Lobby/Hangar/GameTypeSelector.yaml`,
2024-08-15 21:08:02 -05:00
);
2026-07-31 20:48:33 -05:00
const squadBattleTypeStyles = await vfs.yaml<SquadBattleTypeStylesYaml>(
2026-04-01 21:40:15 -05:00
`Data/UI/Screens3/Lobby/Hangar/Squad/SquadBattleType.yaml`,
2024-08-15 13:35:09 -05:00
);
2024-08-15 21:08:02 -05:00
const bannerMatches: { name: string; path: string }[] = [];
2024-08-15 13:35:09 -05:00
2024-08-15 21:08:02 -05:00
for (const match of gameTypeSelectorStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll(
2026-04-01 21:40:15 -05:00
/eGameMode\.([a-zA-Z]+) -> "~res:([^"]+)"/g,
2024-08-15 21:08:02 -05:00
)) {
bannerMatches.push({ name: match[1], path: match[2] });
}
for (const match of squadBattleTypeStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll(
2026-04-01 21:40:15 -05:00
/"(\d+)" -> "battleType\/([a-zA-Z]+)"/g,
2024-08-15 13:35:09 -05:00
)) {
const id = Number(match[1]);
2024-08-15 21:08:02 -05:00
const name = match[2];
let path = bannerMatches.find(
2026-04-01 21:40:15 -05:00
(bannerMatch) => bannerMatch.name.toLowerCase() === name.toLowerCase(),
2024-08-15 21:08:02 -05:00
)?.path;
2024-08-15 13:35:09 -05:00
2024-08-15 21:08:02 -05:00
if (path === undefined) {
path = `/Gfx/UI/Hangar/GameTypes/battle-type_${name.toLowerCase()}`;
}
2026-08-04 19:45:20 -05:00
paths.push({
params: { id },
props: { path: `Data${path}.packed.webp` },
2024-08-15 21:08:02 -05:00
});
2024-08-15 13:35:09 -05:00
}
2024-08-15 21:08:02 -05:00
2026-08-04 19:45:20 -05:00
return paths;
});
export async function GET({ props }: APIContext<{ path: string }>) {
const buffer = await sharp(await vfs.file(props.path))
.trim({ background: { r: 0, g: 0, b: 0, alpha: 0 } })
.toBuffer();
const bytes = new Uint8Array(buffer);
return new Response(bytes);
2024-08-15 13:35:09 -05:00
}