mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: more compression
This commit is contained in:
1 parent
afe041f969
commit
1575b803c0
11 files changed
+135
-59
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { asset } from './asset';
|
||||
import { fetchBkonLz4 } from './fetchBkonLz4';
|
||||
|
||||
export type TankFilterDefinitionCategory = 'clip';
|
||||
|
||||
@@ -33,9 +34,6 @@ export interface ConsumableDefinitions {
|
||||
[key: string]: ConsumableEntry;
|
||||
}
|
||||
|
||||
export const consumableDefinitions = fetch(
|
||||
asset('definitions/consumables.json'),
|
||||
{
|
||||
cache: 'no-cache',
|
||||
},
|
||||
).then(async (response) => response.json() as Promise<ConsumableDefinitions>);
|
||||
export const consumableDefinitions = fetchBkonLz4<ConsumableDefinitions>(
|
||||
asset('definitions/consumables.bkon.lz4'),
|
||||
);
|
||||
@@ -1,4 +1,5 @@
|
||||
import { asset } from './asset';
|
||||
import { fetchBkonLz4 } from './fetchBkonLz4';
|
||||
|
||||
type EquipmentOptions = [number, number];
|
||||
|
||||
@@ -21,6 +22,6 @@ export interface EquipmentDefinitions {
|
||||
};
|
||||
}
|
||||
|
||||
export const equipmentDefinitions = fetch(asset('definitions/equipment.json'), {
|
||||
cache: 'no-cache',
|
||||
}).then(async (response) => response.json() as Promise<EquipmentDefinitions>);
|
||||
export const equipmentDefinitions = fetchBkonLz4<EquipmentDefinitions>(
|
||||
asset('definitions/equipment.bkon.lz4'),
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
import { superDecompress } from './superDecompress';
|
||||
|
||||
export async function fetchBkonLz4<Type>(url: string) {
|
||||
return await fetch(url, {
|
||||
cache: 'no-cache',
|
||||
}).then(async (response) => {
|
||||
return superDecompress(Buffer.from(await response.arrayBuffer())) as Type;
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Vector3Tuple } from 'three';
|
||||
import { asset } from './asset';
|
||||
import { fetchBkonLz4 } from './fetchBkonLz4';
|
||||
|
||||
export type ModelDefinitions = Record<number, ModelDefinition>;
|
||||
|
||||
@@ -53,6 +54,6 @@ export interface PitchLimits {
|
||||
transition?: number;
|
||||
}
|
||||
|
||||
export const modelDefinitions = fetch(asset('definitions/models.json'), {
|
||||
cache: 'no-cache',
|
||||
}).then(async (response) => response.json() as Promise<ModelDefinitions>);
|
||||
export const modelDefinitions = fetchBkonLz4<ModelDefinitions>(
|
||||
asset('definitions/models.bkon.lz4'),
|
||||
);
|
||||
@@ -1,5 +1,6 @@
|
||||
import { asset } from './asset';
|
||||
import { TankFilterDefinition } from './consumableDefinitions';
|
||||
import { fetchBkonLz4 } from './fetchBkonLz4';
|
||||
|
||||
export interface ProvisionEntry {
|
||||
id: number;
|
||||
@@ -13,9 +14,6 @@ export interface ProvisionDefinitions {
|
||||
[key: string]: ProvisionEntry;
|
||||
}
|
||||
|
||||
export const provisionDefinitions = fetch(
|
||||
asset('definitions/provisions.json'),
|
||||
{
|
||||
cache: 'no-cache',
|
||||
},
|
||||
).then(async (response) => response.json() as Promise<ProvisionDefinitions>);
|
||||
export const provisionDefinitions = fetchBkonLz4<ProvisionDefinitions>(
|
||||
asset('definitions/provisions.bkon.lz4'),
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
import { encode } from 'lz4';
|
||||
import { BkonWriteStream } from '../streams/bkon';
|
||||
|
||||
export function superCompress(object: any) {
|
||||
const write = new BkonWriteStream().bkon(object);
|
||||
const compressed = encode(write.buffer);
|
||||
return compressed.toString('base64');
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { decode } from 'lz4';
|
||||
import { BkonReadStream } from '../streams/bkon';
|
||||
|
||||
export function superDecompress<Type>(buffer: Buffer) {
|
||||
const decompressed = decode(buffer);
|
||||
const read = new BkonReadStream(decompressed);
|
||||
return read.bkon() as Type;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { deburr } from 'lodash';
|
||||
import { Vector2Tuple } from 'three';
|
||||
import { TankType, TreeType } from '../../components/Tanks';
|
||||
import { asset } from './asset';
|
||||
import { fetchBkonLz4 } from './fetchBkonLz4';
|
||||
|
||||
export type ShellType = 'ap' | 'ap_cr' | 'hc' | 'he';
|
||||
|
||||
@@ -117,9 +118,9 @@ export const GUN_TYPE_NAMES: Record<GunDefinition['type'], string> = {
|
||||
autoReloader: 'Auto reloader',
|
||||
};
|
||||
|
||||
export const tankDefinitions = fetch(asset('definitions/tanks.json'), {
|
||||
cache: 'no-cache',
|
||||
}).then(async (response) => response.json() as Promise<TankDefinitions>);
|
||||
export const tankDefinitions = fetchBkonLz4<TankDefinitions>(
|
||||
asset('definitions/tanks.bkon.lz4'),
|
||||
);
|
||||
|
||||
const entries = new Promise<TankDefinition[]>(async (resolve) => {
|
||||
resolve(Object.entries(await tankDefinitions).map(([, entry]) => entry));
|
||||
|
||||
Reference in new issue
Block a user