mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: remote and socket metadata and gallery
This commit is contained in:
1 parent
5e9aa99755
commit
f48c5d246d
18 files changed
+213
-23
No files matched your search
@@ -1,5 +1,4 @@
|
||||
export * from './canSplash';
|
||||
export * from './catalogAccessor';
|
||||
export * from './clans';
|
||||
export * from './classes';
|
||||
export * from './constants';
|
||||
@@ -19,6 +18,9 @@ export * from './getTankStats';
|
||||
export * from './idToRegion';
|
||||
export * from './isOnGoingRatingSeason';
|
||||
export * from './isValidBlitzId';
|
||||
export * from './metadata';
|
||||
export * from './metadata.remote';
|
||||
export * from './metadata.socket';
|
||||
export * from './nations';
|
||||
export * from './normalizeExtra';
|
||||
export * from './normalizeIds';
|
||||
|
||||
+4
-8
@@ -1,10 +1,5 @@
|
||||
import { CatalogItem } from '@protos/blitz_items';
|
||||
import { CatalogItemsComponent } from '@protos/blitz_static_catalog_items_group_component';
|
||||
import { BlitzkitAllTanksComponent } from '@protos/blitzkit_static_all_tanks_component';
|
||||
import { BlitzKitTankCatalogComponent } from '@protos/blitzkit_static_tank_component';
|
||||
import { CatalogItemAccessor } from './catalogItemAccessor';
|
||||
|
||||
export class CatalogAccessor {
|
||||
/*
|
||||
export class SocketMetadataAccessor {
|
||||
items: Record<string, CatalogItemAccessor> = {};
|
||||
|
||||
constructor(catalogItems: CatalogItem[]) {
|
||||
@@ -77,7 +72,7 @@ export class CatalogAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
export class RemoteCatalogAccessor {
|
||||
export class RemoteMetadataAccessor {
|
||||
constructor(private base: string) {}
|
||||
|
||||
async get(item: string) {
|
||||
@@ -91,3 +86,4 @@ export class RemoteCatalogAccessor {
|
||||
return new CatalogItemAccessor(catalogItem);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,30 @@
|
||||
import { CatalogItem } from '@protos/blitz_items';
|
||||
import { CatalogItemAccessor } from './catalogItemAccessor';
|
||||
import { MetadataAccessor } from './metadata';
|
||||
|
||||
export class RemoteMetadataAccessor extends MetadataAccessor {
|
||||
constructor(private base: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
async get(item: string) {
|
||||
const response = await fetch(`${this.base}/${item}.pb`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Item ${item} does not exist in remote metadata`);
|
||||
}
|
||||
|
||||
const buffer = new Uint8Array(await response.arrayBuffer());
|
||||
const catalogItem = CatalogItem.decode(buffer);
|
||||
|
||||
return new CatalogItemAccessor(catalogItem);
|
||||
}
|
||||
|
||||
add() {
|
||||
throw new Error('Cannot add items to remote metadata');
|
||||
}
|
||||
|
||||
filter(): CatalogItemAccessor[] {
|
||||
throw new Error('Cannot filter remote metadata');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { CatalogItem } from '@protos/blitz_items';
|
||||
import { Metadata } from '@protos/blitz_metadata';
|
||||
import { CatalogItemAccessor } from './catalogItemAccessor';
|
||||
import { MetadataAccessor } from './metadata';
|
||||
|
||||
export class SocketMetadataAccessor extends MetadataAccessor {
|
||||
private items: Record<string, CatalogItem> = {};
|
||||
|
||||
constructor(metadata: Metadata) {
|
||||
super();
|
||||
|
||||
for (const item of metadata.catalog_items) {
|
||||
this.items[item.catalog_id] = item;
|
||||
}
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
add(item: CatalogItemAccessor) {
|
||||
this.items[item.id] = item.pack();
|
||||
}
|
||||
|
||||
filter(predicate: (item: string) => boolean) {
|
||||
const items: CatalogItemAccessor[] = [];
|
||||
|
||||
for (const item in this.items) {
|
||||
if (predicate(item)) {
|
||||
items.push(new CatalogItemAccessor(this.items[item]));
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { BlitzkitAllAvatarsComponent } from '@protos/blitzkit_static_all_avatars_component';
|
||||
import { CatalogItemAccessor } from './catalogItemAccessor';
|
||||
|
||||
export abstract class MetadataAccessor {
|
||||
abstract get(item: string): Promise<CatalogItemAccessor>;
|
||||
|
||||
abstract add(item: CatalogItemAccessor): void;
|
||||
|
||||
abstract filter(predicate: (item: string) => boolean): CatalogItemAccessor[];
|
||||
|
||||
injectBlitzkit() {
|
||||
this.injectBlitzkitProfileAvatars();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
injectBlitzkitProfileAvatars() {
|
||||
const allAvatars: BlitzkitAllAvatarsComponent = {
|
||||
avatars: this.filter((item) =>
|
||||
item.startsWith('ProfileAvatarEntity.'),
|
||||
).map((avatar) => avatar.pack()),
|
||||
};
|
||||
|
||||
this.add(
|
||||
CatalogItemAccessor.fromComponent(
|
||||
'BlitzkitAllAvatarsEntity.blitzkit_all_avatars',
|
||||
{
|
||||
type_url:
|
||||
'./blitzkit_static_all_avatars_component.BlitzkitAllAvatarsComponent',
|
||||
value: BlitzkitAllAvatarsComponent.encode(allAvatars).finish(),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user