mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
consumable icons
This commit is contained in:
1 parent
f58d06b3c3
commit
0cb4aadec3
6 files changed
+96
-19
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import type { BlitzStaticAssetsDiscoveryComponent } from "@protos/blitz_static_assets_discovery_component";
|
||||
|
||||
export function assertDiscoveryTag(discovery: BlitzStaticAssetsDiscoveryComponent) {
|
||||
if (
|
||||
discovery.blocked_tags !== undefined ||
|
||||
discovery.required_tags === undefined ||
|
||||
discovery.required_tags.tags.length !== 1
|
||||
) {
|
||||
throw new TypeError("Unexpected discovery tag format");
|
||||
}
|
||||
|
||||
return discovery.required_tags.tags[0].value;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { APIContext } from "astro";
|
||||
import { api } from "../../../api/dynamic";
|
||||
import { mixStaticPaths } from "../../../astro/mixStaticPaths";
|
||||
import { game } from "../../../game/game";
|
||||
import { getStaticPaths as _getStaticPaths } from "../_index";
|
||||
import { assertDiscoveryTag } from "../../../game/assertDiscoveryTag";
|
||||
|
||||
export const getStaticPaths = mixStaticPaths(_getStaticPaths, () => {
|
||||
return api.metadata
|
||||
.group("ConsumableEntity")
|
||||
.map(({ id }) => ({ params: { id } }));
|
||||
});
|
||||
|
||||
|
||||
export function GET({ params }: APIContext<never, { id: string }>) {
|
||||
const item = api.metadata.item(params.id);
|
||||
const assetsDiscovery = item.BlitzStaticAssetsDiscovery();
|
||||
const tag = assertDiscoveryTag(assetsDiscovery);
|
||||
const icon = game!.consumableIcon(tag);
|
||||
const array = new Uint8Array(icon);
|
||||
|
||||
return new Response(array);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { notFoundResponse } from "../../../api/responses";
|
||||
import { mixStaticPaths } from "../../../astro/mixStaticPaths";
|
||||
import { game } from "../../../game/game";
|
||||
import { getStaticPaths as _getStaticPaths } from "../_index";
|
||||
import { assetsDiscovery } from "../../../game/assetsDiscovery";
|
||||
|
||||
export const getStaticPaths = mixStaticPaths(_getStaticPaths, () => {
|
||||
return api.metadata
|
||||
@@ -17,17 +18,7 @@ const HACK_nameMap: Record<string, string> = {
|
||||
|
||||
export function GET({ params }: APIContext<never, { id: string }>) {
|
||||
const item = api.metadata.item(params.id);
|
||||
const assetDiscovery = item.BlitzStaticAssetsDiscovery();
|
||||
const names = assetDiscovery.required_tags!.tags.map(
|
||||
(tag) => tag.value.split(".").at(-1)!,
|
||||
);
|
||||
|
||||
for (const name of names) {
|
||||
if (name in HACK_nameMap) {
|
||||
names.push(HACK_nameMap[name]);
|
||||
}
|
||||
}
|
||||
|
||||
const names = assetsDiscovery(item, HACK_nameMap);
|
||||
const icon = game!.equipmentIcon(names);
|
||||
|
||||
if (icon.length === 0) {
|
||||
|
||||
Reference in new issue
Block a user