diff --git a/packages/core/src/blitzkit/index.ts b/packages/core/src/blitzkit/index.ts index defe13e5a..6c69eefc2 100644 --- a/packages/core/src/blitzkit/index.ts +++ b/packages/core/src/blitzkit/index.ts @@ -46,5 +46,6 @@ export * from './votes'; export * from './createDefaultProvisions'; export * from './metaSortTank'; export * from './romanize'; +export * from './tank'; export * from './tanks'; export * from './youtubers'; diff --git a/packages/core/src/blitzkit/tank.ts b/packages/core/src/blitzkit/tank.ts new file mode 100644 index 000000000..2b6296304 --- /dev/null +++ b/packages/core/src/blitzkit/tank.ts @@ -0,0 +1,7 @@ +import { fetchPB } from '../protobuf'; +import { Tank } from '../protos'; +import { asset } from './asset'; + +export function fetchTank(id: string) { + return fetchPB(asset(`tanks/${id}/meta.pb`), Tank); +} diff --git a/packages/core/src/protos/i18n.ts b/packages/core/src/protos/i18n.ts index 56812cce5..9b699ceac 100644 --- a/packages/core/src/protos/i18n.ts +++ b/packages/core/src/protos/i18n.ts @@ -5,9 +5,9 @@ // source: packages/core/src/protos/i18n.proto /* eslint-disable */ -import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; +import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire'; -export const protobufPackage = "blitzkit"; +export const protobufPackage = 'blitzkit'; export interface I18n { locales: { [key: string]: string }; @@ -18,20 +18,27 @@ export interface I18n_LocalesEntry { value: string; } -function createBaseI18n(): I18n { +export function createBaseI18n(): I18n { return { locales: {} }; } export const I18n: MessageFns = { - encode(message: I18n, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + encode( + message: I18n, + writer: BinaryWriter = new BinaryWriter(), + ): BinaryWriter { Object.entries(message.locales).forEach(([key, value]) => { - I18n_LocalesEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); + I18n_LocalesEntry.encode( + { key: key as any, value }, + writer.uint32(10).fork(), + ).join(); }); return writer; }, decode(input: BinaryReader | Uint8Array, length?: number): I18n { - const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const reader = + input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseI18n(); while (reader.pos < end) { @@ -60,10 +67,13 @@ export const I18n: MessageFns = { fromJSON(object: any): I18n { return { locales: isObject(object.locales) - ? Object.entries(object.locales).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) + ? Object.entries(object.locales).reduce<{ [key: string]: string }>( + (acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, + {}, + ) : {}, }; }, @@ -87,7 +97,9 @@ export const I18n: MessageFns = { }, fromPartial, I>>(object: I): I18n { const message = createBaseI18n(); - message.locales = Object.entries(object.locales ?? {}).reduce<{ [key: string]: string }>((acc, [key, value]) => { + message.locales = Object.entries(object.locales ?? {}).reduce<{ + [key: string]: string; + }>((acc, [key, value]) => { if (value !== undefined) { acc[key] = globalThis.String(value); } @@ -98,11 +110,14 @@ export const I18n: MessageFns = { }; function createBaseI18n_LocalesEntry(): I18n_LocalesEntry { - return { key: "", value: "" }; + return { key: '', value: '' }; } export const I18n_LocalesEntry: MessageFns = { - encode(message: I18n_LocalesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + encode( + message: I18n_LocalesEntry, + writer: BinaryWriter = new BinaryWriter(), + ): BinaryWriter { if (message.key !== undefined) { writer.uint32(10).string(message.key); } @@ -113,7 +128,8 @@ export const I18n_LocalesEntry: MessageFns = { }, decode(input: BinaryReader | Uint8Array, length?: number): I18n_LocalesEntry { - const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const reader = + input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseI18n_LocalesEntry(); while (reader.pos < end) { @@ -146,8 +162,10 @@ export const I18n_LocalesEntry: MessageFns = { fromJSON(object: any): I18n_LocalesEntry { return { - key: globalThis.String(assertSet("I18n_LocalesEntry.key", object.key)), - value: globalThis.String(assertSet("I18n_LocalesEntry.value", object.value)), + key: globalThis.String(assertSet('I18n_LocalesEntry.key', object.key)), + value: globalThis.String( + assertSet('I18n_LocalesEntry.value', object.value), + ), }; }, @@ -162,32 +180,51 @@ export const I18n_LocalesEntry: MessageFns = { return obj; }, - create, I>>(base?: I): I18n_LocalesEntry { + create, I>>( + base?: I, + ): I18n_LocalesEntry { return I18n_LocalesEntry.fromPartial(base ?? ({} as any)); }, - fromPartial, I>>(object: I): I18n_LocalesEntry { + fromPartial, I>>( + object: I, + ): I18n_LocalesEntry { const message = createBaseI18n_LocalesEntry(); - message.key = object.key ?? ""; - message.value = object.value ?? ""; + message.key = object.key ?? ''; + message.value = object.value ?? ''; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined; -export type DeepPartial = T extends Builtin ? T - : T extends globalThis.Array ? globalThis.Array> - : T extends ReadonlyArray ? ReadonlyArray> - : T extends { $case: string; value: unknown } ? { $case: T["$case"]; value?: DeepPartial } - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; +export type DeepPartial = T extends Builtin + ? T + : T extends globalThis.Array + ? globalThis.Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends { $case: string; value: unknown } + ? { $case: T['$case']; value?: DeepPartial } + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; type KeysOfUnion = T extends T ? keyof T : never; -export type Exact = P extends Builtin ? P - : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never; + }; function isObject(value: any): boolean { - return typeof value === "object" && value !== null; + return typeof value === 'object' && value !== null; } function isSet(value: any): boolean { diff --git a/packages/core/src/protos/tank.ts b/packages/core/src/protos/tank.ts index b5043f5e8..3291251a3 100644 --- a/packages/core/src/protos/tank.ts +++ b/packages/core/src/protos/tank.ts @@ -5,10 +5,10 @@ // source: packages/core/src/protos/tank.proto /* eslint-disable */ -import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; -import { I18n } from "./i18n"; +import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire'; +import { I18n, createBaseI18n } from './i18n'; -export const protobufPackage = "blitzkit"; +export const protobufPackage = 'blitzkit'; export interface Tank { id: string; @@ -17,15 +17,18 @@ export interface Tank { } function createBaseTank(): Tank { - return { id: "", slug: "", name: createBaseI18n() }; + return { id: '', slug: '', name: createBaseI18n() }; } export const Tank: MessageFns = { - encode(message: Tank, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.id !== "") { + encode( + message: Tank, + writer: BinaryWriter = new BinaryWriter(), + ): BinaryWriter { + if (message.id !== '') { writer.uint32(10).string(message.id); } - if (message.slug !== "") { + if (message.slug !== '') { writer.uint32(18).string(message.slug); } if (message.name !== undefined) { @@ -35,7 +38,8 @@ export const Tank: MessageFns = { }, decode(input: BinaryReader | Uint8Array, length?: number): Tank { - const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const reader = + input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseTank(); while (reader.pos < end) { @@ -76,18 +80,18 @@ export const Tank: MessageFns = { fromJSON(object: any): Tank { return { - id: globalThis.String(assertSet("Tank.id", object.id)), - slug: globalThis.String(assertSet("Tank.slug", object.slug)), - name: I18n.fromJSON(assertSet("Tank.name", object.name)), + id: globalThis.String(assertSet('Tank.id', object.id)), + slug: globalThis.String(assertSet('Tank.slug', object.slug)), + name: I18n.fromJSON(assertSet('Tank.name', object.name)), }; }, toJSON(message: Tank): unknown { const obj: any = {}; - if (message.id !== "") { + if (message.id !== '') { obj.id = message.id; } - if (message.slug !== "") { + if (message.slug !== '') { obj.slug = message.slug; } if (message.name !== undefined) { @@ -101,27 +105,43 @@ export const Tank: MessageFns = { }, fromPartial, I>>(object: I): Tank { const message = createBaseTank(); - message.id = object.id ?? ""; - message.slug = object.slug ?? ""; - message.name = (object.name !== undefined && object.name !== null) - ? I18n.fromPartial(object.name) - : createBaseI18n(); + message.id = object.id ?? ''; + message.slug = object.slug ?? ''; + message.name = + object.name !== undefined && object.name !== null + ? I18n.fromPartial(object.name) + : createBaseI18n(); return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined; -export type DeepPartial = T extends Builtin ? T - : T extends globalThis.Array ? globalThis.Array> - : T extends ReadonlyArray ? ReadonlyArray> - : T extends { $case: string; value: unknown } ? { $case: T["$case"]; value?: DeepPartial } - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; +export type DeepPartial = T extends Builtin + ? T + : T extends globalThis.Array + ? globalThis.Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends { $case: string; value: unknown } + ? { $case: T['$case']; value?: DeepPartial } + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; type KeysOfUnion = T extends T ? keyof T : never; -export type Exact = P extends Builtin ? P - : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never; + }; function isSet(value: any): boolean { return value !== null && value !== undefined; diff --git a/packages/website/src/pages/[...locale]/tanks/index.astro b/packages/website/src/pages/[...locale]/tanks/index.astro index 157b5432f..b8d94a67c 100644 --- a/packages/website/src/pages/[...locale]/tanks/index.astro +++ b/packages/website/src/pages/[...locale]/tanks/index.astro @@ -1,4 +1,6 @@ --- +import { asset, fetchTank } from '@blitzkit/core'; +import { Box, Flex, Text } from '@radix-ui/themes'; import { LinkI18n } from '../../../components/LinkI18n'; import { PageWrapper } from '../../../components/PageWrapper'; import { tanksTool } from '../../../constants/tools'; @@ -10,18 +12,32 @@ export { getStaticPaths } from '../index.astro'; const locale = Astro.params.locale; const tanks = await awaitableTanks; +const fullTanks = await Promise.all(tanks.tanks.map(({ id }) => fetchTank(id))); --- { - tanks.tanks + fullTanks .sort((a, b) => a.slug.localeCompare(b.slug)) - .map((tank) => ( - - {tank.slug} - - )) + .map((tank) => { + return ( + + + + {tank.name.locales.en} + + + ); + }) }