feat: start of all tanks

This commit is contained in:
TrèsAbhi committed 2025-12-26 14:59:09 -06:00
1 parent 53d05e73a6
commit fcfc97b964
14 files changed
+174 -58

No files matched your search

@@ -1,9 +1,12 @@
import type { Tank } from "../../protos/tank";
import type { TankList } from "../../protos/tank_list";
import type { Tanks } from "../../protos/tanks";
export abstract class AbstractAPI {
abstract tanks(): Promise<Tanks>;
abstract tankList(): Promise<TankList>;
abstract strings(
locale: string,
prefix?: string
+12 -5
View File
@@ -1,12 +1,19 @@
import { fetchPB } from "@blitzkit/core";
import { Tank } from "../../protos/tank";
import { TankList } from "../../protos/tank_list";
import { Tanks } from "../../protos/tanks";
import { AbstractAPI } from "./abstract";
export class ClientAPI extends AbstractAPI {
async tank(id: string) {
const response = await fetch(`/api/tanks/${id}.pb`);
const buffer = await response.arrayBuffer();
const array = new Uint8Array(buffer);
tanks() {
return fetchPB("/api/tanks.pb", Tanks);
}
return Tank.decode(array);
tankList() {
return fetchPB("/api/tanks/list.pb", TankList);
}
tank(id: string) {
return fetchPB(`/api/tanks/${id}.pb`, Tank);
}
}
+27 -6
View File
@@ -3,7 +3,8 @@ import { sluggify } from "@blitzkit/core";
import type { RemoteStorageComponent } from "@protos/blitz_static_remote_storage_component";
import { parse } from "yaml";
import type { Tank } from "../../protos/tank";
import type { TanksEntry } from "../../protos/tanks";
import type { TankListEntry } from "../../protos/tank_list";
import type { Tanks } from "../../protos/tanks";
import { AbstractAPI } from "./abstract";
if (typeof window !== "undefined") {
@@ -91,9 +92,9 @@ export class ServerAPI extends AbstractAPI {
return strings;
}
async tanks() {
async tankList() {
const group = this.metadata.group("TankEntity");
const tanks: TanksEntry[] = [];
const list: TankListEntry[] = [];
const strings = await this.strings("en");
for (const item of group) {
@@ -108,17 +109,37 @@ export class ServerAPI extends AbstractAPI {
const id = item.name;
const slug = sluggify(name);
tanks.push({ id, slug });
list.push({ id, slug });
}
return { tanks };
return { list };
}
async tanks() {
const tankList = await this.tankList();
const data: Tanks = { tanks: {} };
for (const { id } of tankList.list) {
console.log(id);
data.tanks[id] = await this.tank(id);
}
return data;
}
async tank(id: string) {
const tankList = await this.tankList();
const tankListEntry = tankList.list.find((tank) => tank.id === id);
if (!tankListEntry) {
throw new Error(`Tank with id ${id} not found`);
}
const { slug } = tankListEntry;
const item = this.metadata.item(`TankEntity.${id}`);
const tank = item.TankCatalog();
const compensation = item.Compensation();
return { tank, compensation } satisfies Tank;
return { tank, compensation, slug } satisfies Tank;
}
}