mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: download
This commit is contained in:
1 parent
354aca5057
commit
2dc4f12246
17 files changed
+203
-66
No files matched your search
Vendored
+1
@@ -192,6 +192,7 @@
|
||||
"TYPELESS",
|
||||
"ubjson",
|
||||
"Uncompiled",
|
||||
"undiscriminated",
|
||||
"Unicum",
|
||||
"UNLOCALIZED",
|
||||
"UNORM",
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
"satori": "^0.10.14",
|
||||
"@resvg/resvg-js": "^2.6.2",
|
||||
"discord.js": "^14.16.3",
|
||||
"fuzzysort": "^2.0.4",
|
||||
"bepaint": "^0.1.0-beta.3",
|
||||
"markdown-escape": "^2.0.0",
|
||||
"@types/markdown-escape": "^1.1.3",
|
||||
|
||||
@@ -22,6 +22,10 @@ export class CatalogItemAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
undiscriminatedId() {
|
||||
return this.id.split('.').slice(1).join('.');
|
||||
}
|
||||
|
||||
static fromComponent(id: string, component: Any) {
|
||||
return this.fromComponents(id, [component]);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { LocalizationResourcesComponent } from '@protos/blitz_static_localization_resources_component';
|
||||
import { ProfileAvatarComponent } from '@protos/blitz_static_profile_avatar_component';
|
||||
import { RemoteStorageComponent } from '@protos/blitz_static_remote_storage_component';
|
||||
import { SellableComponent } from '@protos/blitz_static_sellable_component';
|
||||
import { StuffUIComponent } from '@protos/blitz_static_stuff_ui_component';
|
||||
import { BlitzkitAllAvatarsComponent } from '@protos/blitzkit_static_all_avatars_component';
|
||||
import { load } from 'js-yaml';
|
||||
import { minimatch } from 'minimatch';
|
||||
import { CatalogItemAccessor } from '../catalogItemAccessor';
|
||||
import { CatalogItemAccessor } from 'packages/core/src/blitz/catalogItemAccessor';
|
||||
|
||||
interface LocalizationConfig {
|
||||
namespaces: string[];
|
||||
@@ -102,11 +105,26 @@ export abstract class MetadataAccessor {
|
||||
}
|
||||
|
||||
injectBlitzkitProfileAvatars() {
|
||||
const allAvatars: BlitzkitAllAvatarsComponent = {
|
||||
avatars: this.filter((item) =>
|
||||
item.startsWith('ProfileAvatarEntity.'),
|
||||
).map((avatar) => avatar.pack()),
|
||||
};
|
||||
const allAvatars: BlitzkitAllAvatarsComponent = { avatars: [] };
|
||||
|
||||
for (const item of this.filter((item) =>
|
||||
item.startsWith('ProfileAvatarEntity.'),
|
||||
)) {
|
||||
const stuff = item.get(StuffUIComponent, 'UIComponent');
|
||||
const avatar = item.get(ProfileAvatarComponent, 'profileAvatarComponent');
|
||||
const sellable = item.getOptional(SellableComponent, 'sellableComponent');
|
||||
|
||||
allAvatars.avatars.push({
|
||||
id: item.undiscriminatedId(),
|
||||
name: stuff.display_name,
|
||||
obtaining: stuff.obtaining_methods,
|
||||
description: stuff.description,
|
||||
grade: stuff.grade,
|
||||
category: avatar.category,
|
||||
hidden_if_not_obtained: avatar.hidden_if_not_obtained,
|
||||
sale: sellable?.reward,
|
||||
});
|
||||
}
|
||||
|
||||
this.add(
|
||||
CatalogItemAccessor.fromComponent(
|
||||
|
||||
@@ -16,7 +16,6 @@ export class SocketMetadataAccessor extends MetadataAccessor {
|
||||
|
||||
async get(item: string) {
|
||||
if (item in this.items) return new CatalogItemAccessor(this.items[item]);
|
||||
|
||||
throw new Error(`Item ${item} does not exist in socket metadata`);
|
||||
}
|
||||
|
||||
|
||||
@@ -1270,14 +1270,16 @@
|
||||
|
||||
"no_description": "This avatar has no description.",
|
||||
"download": "Download",
|
||||
"enlarge": "Enlarge",
|
||||
"hidden": "Hidden",
|
||||
"unnamed_avatars": "Unnamed avatars",
|
||||
"search": {
|
||||
"hint": "Search avatars...",
|
||||
"results": "%s1 avatars"
|
||||
},
|
||||
|
||||
"categories": {
|
||||
"0": "Unspecified category",
|
||||
"0": "Unspecified",
|
||||
"1": "Premium",
|
||||
"2": "Special",
|
||||
"3": "Accumulative",
|
||||
|
||||
@@ -26,12 +26,14 @@
|
||||
"@types/semver": "^7.7.0",
|
||||
"@types/three": "^0.160.0",
|
||||
"astro": "^5.8.0",
|
||||
"fuzzysort": "^3.1.0",
|
||||
"immer": "^10.1.1",
|
||||
"lodash-es": "^4.17.21",
|
||||
"minimatch": "^10.0.1",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"semver": "^7.7.2",
|
||||
"sharp": "^0.34.2",
|
||||
"three": "^0.169.0",
|
||||
"zustand": "^4.5.5"
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -1,6 +1,4 @@
|
||||
import { type ProfileAvatarComponent } from '@protos/blitz_static_profile_avatar_component';
|
||||
import type { SellableComponent } from '@protos/blitz_static_sellable_component';
|
||||
import type { StuffUIComponent } from '@protos/blitz_static_stuff_ui_component';
|
||||
import type { BlitzKitAvatar } from '@protos/blitzkit_static_all_avatars_component';
|
||||
import { Dialog } from '@radix-ui/themes';
|
||||
import type { MaybeSkeletonComponentProps } from '../../types/maybeSkeletonComponentProps';
|
||||
import { Content } from './Content';
|
||||
@@ -8,11 +6,7 @@ import { Popup } from './Popup';
|
||||
|
||||
export interface AvatarGroupProps {
|
||||
name?: string;
|
||||
avatars: {
|
||||
stuff: StuffUIComponent;
|
||||
avatar: ProfileAvatarComponent;
|
||||
sellable?: SellableComponent;
|
||||
}[];
|
||||
avatars: { avatar: BlitzKitAvatar }[];
|
||||
}
|
||||
|
||||
export function AvatarGroup(
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { Grade } from '@protos/blitz_static_standard_grades_enum';
|
||||
import { DownloadIcon, StarFilledIcon } from '@radix-ui/react-icons';
|
||||
import { Badge, Box, Button, Dialog, Flex, Text } from '@radix-ui/themes';
|
||||
import {
|
||||
CardStackIcon,
|
||||
DownloadIcon,
|
||||
ExternalLinkIcon,
|
||||
EyeNoneIcon,
|
||||
StarFilledIcon,
|
||||
} from '@radix-ui/react-icons';
|
||||
import { Badge, Box, Button, Dialog, Flex, Link, Text } from '@radix-ui/themes';
|
||||
import { Var } from '../../core/radix/var';
|
||||
import { useLocale } from '../../hooks/useLocale';
|
||||
import { GRADE_COLORS } from './Colors';
|
||||
@@ -13,8 +19,8 @@ export function Popup({ name, avatars }: AvatarGroupProps) {
|
||||
<>
|
||||
<Dialog.Title>{name}</Dialog.Title>
|
||||
|
||||
<Flex direction="column" gap="3" mt="5">
|
||||
{avatars.map(({ avatar, stuff }, index) => (
|
||||
<Flex direction="column" gap="5" mt="5">
|
||||
{[...avatars].reverse().map(({ avatar }, index) => (
|
||||
<Flex key={index} gap="5">
|
||||
<Box
|
||||
m="1"
|
||||
@@ -23,16 +29,27 @@ export function Popup({ name, avatars }: AvatarGroupProps) {
|
||||
style={{
|
||||
aspectRatio: '7 / 8',
|
||||
borderRadius: Var('radius-4'),
|
||||
outline: `${Var('space-1')} solid ${Var(`${GRADE_COLORS[stuff.grade]}-9`)}`,
|
||||
outline: `${Var('space-1')} solid ${Var(`${GRADE_COLORS[avatar.grade]}-9`)}`,
|
||||
boxShadow: `0 0 ${
|
||||
1.5 * (stuff.grade / Grade.GRADE_LEGENDARY)
|
||||
}rem ${Var(`${GRADE_COLORS[stuff.grade]}-9`)}`,
|
||||
backgroundImage: `url(${avatar.avatar})`,
|
||||
backgroundSize: 'cover',
|
||||
1.5 * (avatar.grade / Grade.GRADE_LEGENDARY)
|
||||
}rem ${Var(`${GRADE_COLORS[avatar.grade]}-9`)}`,
|
||||
backgroundImage: 'url(/assets/sad-ghost.png)',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
backgroundPosition: 'center',
|
||||
backgroundSize: '3rem',
|
||||
}}
|
||||
position="relative"
|
||||
>
|
||||
<Box
|
||||
width="100%"
|
||||
height="100%"
|
||||
style={{
|
||||
backgroundImage: `url(/api/avatars/${avatar.id}.webp)`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
}}
|
||||
/>
|
||||
|
||||
<Badge
|
||||
mt="1"
|
||||
style={{
|
||||
@@ -42,25 +59,54 @@ export function Popup({ name, avatars }: AvatarGroupProps) {
|
||||
transform: 'translate(-50%, -50%)',
|
||||
}}
|
||||
variant="solid"
|
||||
color={GRADE_COLORS[stuff.grade]}
|
||||
color={GRADE_COLORS[avatar.grade]}
|
||||
>
|
||||
<StarFilledIcon /> {strings.common.grades[stuff.grade]}
|
||||
<StarFilledIcon /> {strings.common.grades[avatar.grade]}
|
||||
</Badge>
|
||||
</Box>
|
||||
|
||||
<Flex direction="column" gap="3" justify="center">
|
||||
<Flex gap="1">
|
||||
<Badge color="gray" variant="surface">
|
||||
<CardStackIcon />
|
||||
{strings.website.tools.avatars.categories[avatar.category]}
|
||||
</Badge>
|
||||
|
||||
{avatar.hidden_if_not_obtained && (
|
||||
<Badge color="gray" variant="surface">
|
||||
<EyeNoneIcon /> {strings.website.tools.avatars.hidden}
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
{avatar.sale && (
|
||||
<Badge>
|
||||
{JSON.stringify(
|
||||
avatar.sale.reward_list[0].currency_reward?.amount,
|
||||
)}
|
||||
</Badge>
|
||||
)}
|
||||
</Flex>
|
||||
|
||||
<Text>
|
||||
{gameStrings[stuff.description] ??
|
||||
(gameStrings[stuff.obtaining_methods]
|
||||
{gameStrings[avatar.description] ??
|
||||
(gameStrings[avatar.obtaining]
|
||||
? undefined
|
||||
: strings.website.tools.avatars.no_description)}{' '}
|
||||
{gameStrings[stuff.obtaining_methods]}
|
||||
{gameStrings[avatar.obtaining]}
|
||||
</Text>
|
||||
|
||||
<Flex>
|
||||
<Button variant="outline">
|
||||
<DownloadIcon /> {strings.website.tools.avatars.download}
|
||||
</Button>
|
||||
<Flex gap="2">
|
||||
<Link href={`/api/avatars/${avatar.id}.webp`} download>
|
||||
<Button variant="solid">
|
||||
<DownloadIcon /> {strings.website.tools.avatars.download}
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<Link href={`/api/avatars/${avatar.id}.webp`} target="_blank">
|
||||
<Button variant="outline">
|
||||
<ExternalLinkIcon /> {strings.website.tools.avatars.enlarge}
|
||||
</Button>
|
||||
</Link>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
@@ -11,7 +11,7 @@ export function Stack({ avatars }: { avatars: AvatarGroupProps['avatars'] }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
{avatars.map((avatar, index) => (
|
||||
{avatars.map(({ avatar }, index) => (
|
||||
<Box
|
||||
key={index}
|
||||
position="absolute"
|
||||
@@ -23,12 +23,24 @@ export function Stack({ avatars }: { avatars: AvatarGroupProps['avatars'] }) {
|
||||
filter: `brightness(${(index + 1) / avatars.length})`,
|
||||
borderRadius: Var('radius-4'),
|
||||
boxShadow: Var('shadow-2'),
|
||||
backgroundImage: `url(${avatar.avatar.avatar})`,
|
||||
backgroundSize: 'cover',
|
||||
overflow: 'hidden',
|
||||
backgroundImage: 'url(/assets/sad-ghost.png)',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
backgroundPosition: 'center',
|
||||
backgroundSize: '3rem',
|
||||
}}
|
||||
>
|
||||
{avatars.length > 1 && (
|
||||
<Box
|
||||
width="100%"
|
||||
height="100%"
|
||||
style={{
|
||||
backgroundImage: `url(/api/avatars/${avatar.id}.webp)`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
}}
|
||||
/>
|
||||
|
||||
{avatars.length > 1 && index === avatars.length - 1 && (
|
||||
<Box
|
||||
width="100%"
|
||||
height="100%"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { RemoteMetadataAccessor } from 'packages/core/src';
|
||||
|
||||
export const remoteMetadata = new RemoteMetadataAccessor(
|
||||
'/api/metadata/catalog',
|
||||
'/api/internal/catalog',
|
||||
);
|
||||
@@ -1,10 +1,8 @@
|
||||
import { ProfileAvatarComponent } from '@protos/blitz_static_profile_avatar_component';
|
||||
import { SellableComponent } from '@protos/blitz_static_sellable_component';
|
||||
import { StuffUIComponent } from '@protos/blitz_static_stuff_ui_component';
|
||||
import { BlitzkitAllAvatarsComponent } from '@protos/blitzkit_static_all_avatars_component';
|
||||
import { Grid } from '@radix-ui/themes';
|
||||
import { times } from 'lodash-es';
|
||||
import { CatalogItemAccessor } from 'packages/core/src/blitz/catalogItemAccessor';
|
||||
import { MagnifyingGlassIcon } from '@radix-ui/react-icons';
|
||||
import { Flex, Grid, Spinner, TextField } from '@radix-ui/themes';
|
||||
import fuzzysort from 'fuzzysort';
|
||||
import { debounce, times } from 'lodash-es';
|
||||
import { AvatarGroup } from 'packages/website-ue/src/components/Avatars/Group';
|
||||
import { PageWrapper } from 'packages/website-ue/src/components/PageWrapper';
|
||||
import { metadata } from 'packages/website-ue/src/core/blitz/metadata';
|
||||
@@ -14,7 +12,7 @@ import {
|
||||
type LocaleAcceptorProps,
|
||||
} from 'packages/website-ue/src/hooks/useLocale';
|
||||
import type { MaybeSkeletonComponentProps } from 'packages/website-ue/src/types/maybeSkeletonComponentProps';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useCallback, useMemo, useRef, useState } from 'react';
|
||||
|
||||
const allAvatars = await metadata
|
||||
.get('BlitzkitAllAvatarsEntity.blitzkit_all_avatars')
|
||||
@@ -36,25 +34,17 @@ const DEFAULT_LOADED = 42;
|
||||
const PREVIEW_COUNT = 28;
|
||||
|
||||
function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
const { gameStrings } = useLocale();
|
||||
const { strings, gameStrings } = useLocale();
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const [search, setSearch] = useState<string | null>(null);
|
||||
const [searching, setSearching] = useState(false);
|
||||
const groups = useMemo(() => {
|
||||
const avatars = allAvatars
|
||||
.map((id) => {
|
||||
const item = new CatalogItemAccessor(id);
|
||||
const stuff = item.get(StuffUIComponent, 'UIComponent');
|
||||
const avatar = item.get(
|
||||
ProfileAvatarComponent,
|
||||
'profileAvatarComponent',
|
||||
);
|
||||
const sellable = item.getOptional(
|
||||
SellableComponent,
|
||||
'sellableComponent',
|
||||
);
|
||||
const name = gameStrings[stuff.display_name] as string | undefined;
|
||||
|
||||
return { avatar, name, stuff, sellable };
|
||||
})
|
||||
.sort((a, b) => a.stuff.grade - b.stuff.grade)
|
||||
.map((avatar) => ({
|
||||
avatar,
|
||||
name: gameStrings[avatar.name] as string | undefined,
|
||||
}))
|
||||
.sort((a, b) => a.avatar.grade - b.avatar.grade)
|
||||
.sort((a, b) =>
|
||||
a.name === undefined
|
||||
? 1
|
||||
@@ -75,10 +65,50 @@ function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
return [...groups].map(([name, avatars]) => ({ name, avatars }));
|
||||
}, []);
|
||||
const [loadedAvatars, setLoadedAvatars] = useState(DEFAULT_LOADED);
|
||||
const filtered = useMemo(() => groups, []);
|
||||
const filtered = useMemo(() => {
|
||||
setSearching(false);
|
||||
|
||||
if (search === null || search.trim().length === 0) return groups;
|
||||
|
||||
return fuzzysort
|
||||
.go(search, groups, { key: 'name' })
|
||||
.map((result) => result.obj);
|
||||
}, [search]);
|
||||
const requestSearch = useCallback(
|
||||
debounce(() => {
|
||||
if (!input.current) return;
|
||||
setSearch(input.current.value);
|
||||
}, 500),
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<PageWrapper color="amber">
|
||||
<Flex justify="center">
|
||||
<TextField.Root
|
||||
ref={input}
|
||||
my="7"
|
||||
placeholder={strings.website.tools.avatars.search.hint}
|
||||
style={{
|
||||
flex: 1,
|
||||
maxWidth: '30rem',
|
||||
}}
|
||||
onChange={(event) => {
|
||||
if (event.target.value.trim().length === 0) {
|
||||
setSearching(false);
|
||||
return;
|
||||
}
|
||||
|
||||
requestSearch();
|
||||
setSearching(true);
|
||||
}}
|
||||
>
|
||||
<TextField.Slot>
|
||||
{searching ? <Spinner /> : <MagnifyingGlassIcon />}
|
||||
</TextField.Slot>
|
||||
</TextField.Root>
|
||||
</Flex>
|
||||
|
||||
<Grid
|
||||
columns={{
|
||||
initial: 'repeat(auto-fill, minmax(6rem, 1fr))',
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ProfileAvatarComponent } from '@protos/blitz_static_profile_avatar_component';
|
||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem } from 'astro';
|
||||
import { socketMetadata } from 'packages/website-ue/src/core/blitz/metadata.socket';
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
for (const item in socketMetadata.items) {
|
||||
if (!item.startsWith('ProfileAvatarEntity.')) continue;
|
||||
|
||||
const id = await socketMetadata
|
||||
.get(item)
|
||||
.then((item) => item.undiscriminatedId());
|
||||
|
||||
paths.push({ params: { id } });
|
||||
}
|
||||
|
||||
return paths;
|
||||
};
|
||||
|
||||
export const GET: APIRoute<{}, { id: string }> = async ({ params }) => {
|
||||
const item = await socketMetadata.get(`ProfileAvatarEntity.${params.id}`);
|
||||
const avatar = item.get(ProfileAvatarComponent, 'profileAvatarComponent');
|
||||
|
||||
try {
|
||||
return await fetch(avatar.avatar);
|
||||
} catch {
|
||||
return new Response(null, { status: 404 });
|
||||
}
|
||||
};
|
||||
File renamed without changes.
Submodule submodules/blitzkit-closed updated: c390ed62f3...7f4ec5f5bc.
Reference in new issue
Block a user