feat: remote catalog

This commit is contained in:
TrèsAbhi committed 2025-05-28 18:32:04 -05:00
1 parent e7386ff766
commit 5e9aa99755
17 files changed
+109 -67

No files matched your search

@@ -1,15 +1,14 @@
import { CatalogItem } from '@protos/blitz_items';
import { Metadata } from '@protos/blitz_metadata';
import { CatalogItemsComponent } from '@protos/blitz_static_catalog_items_group_component';
import { BlitzKitAllTankEntities } from '@protos/blitzkit_static_all_tank_entities';
import { BlitzkitAllTanksComponent } from '@protos/blitzkit_static_all_tanks_component';
import { BlitzKitTankCatalogComponent } from '@protos/blitzkit_static_tank_component';
import { CatalogItemAccessor } from './catalogItemAccessor';
export class UnpackedMetadataAccessor {
export class CatalogAccessor {
items: Record<string, CatalogItemAccessor> = {};
constructor(metadata: Metadata) {
for (const item of metadata.catalog_items) {
constructor(catalogItems: CatalogItem[]) {
for (const item of catalogItems) {
if (item.catalog_id in this.items) {
throw new Error(`Duplicate catalog ID: ${item.catalog_id}`);
}
@@ -20,29 +19,14 @@ export class UnpackedMetadataAccessor {
get(item: string) {
if (item in this.items) return this.items[item];
throw new Error(`Unknown catalog ID: ${item}`);
}
addCatalogItem(item: CatalogItemAccessor) {
add(item: CatalogItemAccessor) {
this.items[item.id] = item;
return this;
}
addCatalogItemWithComponent(
catalogId: string,
componentId: string,
url: string,
value: Uint8Array,
) {
this.addCatalogItem(
new CatalogItemAccessor({
catalog_id: catalogId,
components: [],
}).addComponent(componentId, { type_url: url, value }),
);
}
getAllTanks() {
return this.get('CatalogItemsGroupEntity.all_tanks').get(
CatalogItemsComponent,
@@ -52,7 +36,7 @@ export class UnpackedMetadataAccessor {
injectBlitzkit() {
this.injectBlitzKitTankComponents();
this.injectBlitzKitAllTankEntities();
this.injectBlitzKitAllTanksEntity();
return this;
}
@@ -73,23 +57,27 @@ export class UnpackedMetadataAccessor {
}
}
injectBlitzKitAllTankEntities() {
const allTanksEntities: BlitzKitAllTankEntities = { tanks: [] };
injectBlitzKitAllTanksEntity() {
const allTanksEntities: BlitzkitAllTanksComponent = { tanks: [] };
for (const item of this.getAllTanks().catalog_items) {
allTanksEntities.tanks.push(this.get(item).pack());
}
this.addCatalogItemWithComponent(
'BlitzKitAllTankEntities.all_tanks',
'blitzkitAllTankEntitiesComponent',
'./blitzkit_static_all_tank_entities.BlitzKitAllTankEntities',
BlitzKitAllTankEntities.encode(allTanksEntities).finish(),
this.add(
CatalogItemAccessor.fromComponent(
'BlitzKitAllTanksEntity.blitzkit_all_tanks',
{
type_url:
'./blitzkit_static_all_tanks_component.BlitzkitAllTanksComponent',
value: BlitzkitAllTanksComponent.encode(allTanksEntities).finish(),
},
),
);
}
}
export class DiscreteMetadataAccessor {
export class RemoteCatalogAccessor {
constructor(private base: string) {}
async get(item: string) {
@@ -1,5 +1,6 @@
import { CatalogItem } from '@protos/blitz_items';
import { Any } from '@protos/google/protobuf/any';
import { lowerFirst } from 'lodash-es';
import { MessageFns } from '../protos';
export class CatalogItemAccessor {
@@ -21,6 +22,22 @@ export class CatalogItemAccessor {
}
}
static fromComponent(id: string, component: Any) {
return this.fromComponents(id, [component]);
}
static fromComponents(id: string, components: Any[]) {
return new CatalogItemAccessor({
catalog_id: id,
components: components.map((component) => ({
key: lowerFirst(
component.type_url.slice(2).split('.').slice(1).join('.'),
),
value: { type_url: component.type_url, component },
})),
});
}
addComponent(key: string, value: Any) {
this.components[key] = value;
return this;
@@ -48,4 +65,8 @@ export class CatalogItemAccessor {
return item;
}
encode() {
return CatalogItem.encode(this.pack()).finish();
}
}
+1 -2
View File
@@ -1,5 +1,5 @@
export * from './canSplash';
export * from './catalogItemAccessor';
export * from './catalogAccessor';
export * from './clans';
export * from './classes';
export * from './constants';
@@ -19,7 +19,6 @@ export * from './getTankStats';
export * from './idToRegion';
export * from './isOnGoingRatingSeason';
export * from './isValidBlitzId';
export * from './metadataAccessor';
export * from './nations';
export * from './normalizeExtra';
export * from './normalizeIds';
+1 -1
View File
@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*", "../i18n/src/strings.ts"],
"include": ["src/**/*"],
"compilerOptions": {
"baseUrl": "../../"
}