mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: types
This commit is contained in:
1 parent
71481f5971
commit
cb101da8a8
5 files changed
+24
-53
No files matched your search
+3
-8
@@ -16,12 +16,12 @@ Header {
|
||||
}
|
||||
|
||||
Format enum<uint8> {
|
||||
Minimal,
|
||||
Base,
|
||||
Superset1,
|
||||
}
|
||||
|
||||
Body<Header header> match<header.format> {
|
||||
Minimal {
|
||||
Base {
|
||||
primary {
|
||||
uint32 id;
|
||||
uint16 score;
|
||||
@@ -37,12 +37,7 @@ Body<Header header> match<header.format> {
|
||||
uint32 wins;
|
||||
uint32 survived;
|
||||
|
||||
uint32 damageDealt;
|
||||
uint32 damageReceived;
|
||||
|
||||
uint32 shots;
|
||||
uint32 hits;
|
||||
|
||||
uint32 damage;
|
||||
uint32 kills;
|
||||
}[header.count] entries;
|
||||
};
|
||||
|
||||
@@ -13,9 +13,9 @@ import { FileChange } from '../src/core/blitzkrieg/commitMultipleFiles.js';
|
||||
import { patientFetchJSON } from '../src/core/blitzkrieg/patientFetchJSON';
|
||||
import { superCompress } from '../src/core/blitzkrieg/superCompress';
|
||||
import {
|
||||
BkrlComprehensive1Entry,
|
||||
BkrlBaseEntry,
|
||||
BkrlFormat,
|
||||
BkrlMinimalEntry,
|
||||
BkrlSuperset1Entry,
|
||||
BkrlWriteStream,
|
||||
} from '../src/core/streams/bkrl';
|
||||
import { CdonValue, CdonWriteStream } from '../src/core/streams/cdon';
|
||||
@@ -49,7 +49,7 @@ if (PLAYERS === undefined) {
|
||||
}
|
||||
|
||||
const players: Record<number, RatingPlayer> = {};
|
||||
const leaderboard: BkrlMinimalEntry[] = [];
|
||||
const leaderboard: BkrlBaseEntry[] = [];
|
||||
let registered = 0;
|
||||
|
||||
async function branchFromPlayer(id: number) {
|
||||
@@ -118,7 +118,7 @@ for (let index = 0; index < PLAYERS; index++) {
|
||||
}
|
||||
|
||||
console.log('Requesting further stats...');
|
||||
const comprehensiveLeaderboard: BkrlComprehensive1Entry[] = [];
|
||||
const comprehensiveLeaderboard: BkrlSuperset1Entry[] = [];
|
||||
let chunkIndex = 0;
|
||||
for (const leaderboardChunk of chunk(leaderboard, 100)) {
|
||||
console.log(
|
||||
@@ -137,13 +137,10 @@ for (const leaderboardChunk of chunk(leaderboard, 100)) {
|
||||
leaderboardChunk[index].id === 0
|
||||
? {
|
||||
battles: 0,
|
||||
damageDealt: 0,
|
||||
damageReceived: 0,
|
||||
hits: 0,
|
||||
damage: 0,
|
||||
id: 0,
|
||||
kills: 0,
|
||||
score: 0,
|
||||
shots: 0,
|
||||
survived: 0,
|
||||
wins: 0,
|
||||
}
|
||||
@@ -151,11 +148,8 @@ for (const leaderboardChunk of chunk(leaderboard, 100)) {
|
||||
id: leaderboardChunk[index].id,
|
||||
score: leaderboardChunk[index].score,
|
||||
battles: stat.statistics.rating!.battles,
|
||||
damageDealt: stat.statistics.rating!.damage_dealt,
|
||||
damageReceived: stat.statistics.rating!.damage_received,
|
||||
hits: stat.statistics.rating!.hits,
|
||||
damage: stat.statistics.rating!.damage_dealt,
|
||||
kills: stat.statistics.rating!.frags,
|
||||
shots: stat.statistics.rating!.shots,
|
||||
survived: stat.statistics.rating!.survived_battles,
|
||||
wins: stat.statistics.rating!.wins,
|
||||
};
|
||||
@@ -174,7 +168,7 @@ const infoContent = new CdonWriteStream().cdon(
|
||||
const leaderboardWriteStream = new BkrlWriteStream();
|
||||
|
||||
leaderboardWriteStream.bkrl({
|
||||
format: BkrlFormat.Comprehensive1,
|
||||
format: BkrlFormat.Superset1,
|
||||
entries: comprehensiveLeaderboard,
|
||||
});
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export const ratingCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
const clanImage = clan ? emblemURL(clan.emblem_set_id) : undefined;
|
||||
const leaderboard = await getArchivedRatingLeaderboard(region, 53);
|
||||
|
||||
if (leaderboard.format === BkrlFormat.Minimal) {
|
||||
if (leaderboard.format === BkrlFormat.Base) {
|
||||
throw new Error(
|
||||
'Encountered bkrl minimal format in latest season. Wait till next cron?',
|
||||
);
|
||||
@@ -412,7 +412,7 @@ export const ratingCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
fontWeight: 'bold',
|
||||
}}
|
||||
>
|
||||
{Math.round(delta.damageDealt / delta.battles).toLocaleString(
|
||||
{Math.round(delta.damage / delta.battles).toLocaleString(
|
||||
interaction.locale,
|
||||
)}
|
||||
</span>
|
||||
|
||||
@@ -9,11 +9,8 @@ export function deltaBkrlBlitzStats(
|
||||
) {
|
||||
return {
|
||||
battles: b1.battles - a.battles,
|
||||
damageDealt: b1.damage_dealt - a.damageDealt,
|
||||
damageReceived: b1.damage_received - a.damageReceived,
|
||||
hits: b1.hits - a.hits,
|
||||
damage: b1.damage_dealt - a.damage,
|
||||
kills: b1.frags - a.kills,
|
||||
shots: b1.shots - a.shots,
|
||||
survived: b1.survived_battles - a.survived,
|
||||
wins: b1.wins - a.wins,
|
||||
score: b2.score - a.score,
|
||||
|
||||
+11
-26
@@ -2,11 +2,11 @@ import { times } from 'lodash';
|
||||
import { ReadStream, WriteStream } from './buffer';
|
||||
|
||||
export enum BkrlFormat {
|
||||
Minimal,
|
||||
Base,
|
||||
Superset1,
|
||||
}
|
||||
|
||||
export interface BkrlMinimalEntry {
|
||||
export interface BkrlBaseEntry {
|
||||
id: number;
|
||||
score: number;
|
||||
}
|
||||
@@ -19,19 +19,14 @@ export interface BkrlSuperset1Entry {
|
||||
wins: number;
|
||||
survived: number;
|
||||
|
||||
damageDealt: number;
|
||||
damageReceived: number;
|
||||
|
||||
shots: number;
|
||||
hits: number;
|
||||
|
||||
damage: number;
|
||||
kills: number;
|
||||
}
|
||||
|
||||
export type BkrlDiscriminatedEntries =
|
||||
| {
|
||||
format: BkrlFormat.Minimal;
|
||||
entries: BkrlMinimalEntry[];
|
||||
format: BkrlFormat.Base;
|
||||
entries: BkrlBaseEntry[];
|
||||
}
|
||||
| {
|
||||
format: BkrlFormat.Superset1;
|
||||
@@ -47,16 +42,16 @@ export class BkrlReadStream extends ReadStream {
|
||||
|
||||
body(header: ReturnType<typeof this.header>): BkrlDiscriminatedEntries {
|
||||
switch (header.format) {
|
||||
case BkrlFormat.Minimal: {
|
||||
case BkrlFormat.Base: {
|
||||
return {
|
||||
format: BkrlFormat.Minimal,
|
||||
format: BkrlFormat.Base,
|
||||
entries: times(
|
||||
header.count,
|
||||
() =>
|
||||
({
|
||||
id: this.uint32(),
|
||||
score: this.uint16(),
|
||||
}) satisfies BkrlMinimalEntry,
|
||||
}) satisfies BkrlBaseEntry,
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -75,12 +70,7 @@ export class BkrlReadStream extends ReadStream {
|
||||
wins: this.uint32(),
|
||||
survived: this.uint32(),
|
||||
|
||||
damageDealt: this.uint32(),
|
||||
damageReceived: this.uint32(),
|
||||
|
||||
shots: this.uint32(),
|
||||
hits: this.uint32(),
|
||||
|
||||
damage: this.uint32(),
|
||||
kills: this.uint32(),
|
||||
}) satisfies BkrlSuperset1Entry,
|
||||
),
|
||||
@@ -115,7 +105,7 @@ export class BkrlWriteStream extends WriteStream {
|
||||
|
||||
body(discriminatedEntries: BkrlDiscriminatedEntries) {
|
||||
switch (discriminatedEntries.format) {
|
||||
case BkrlFormat.Minimal: {
|
||||
case BkrlFormat.Base: {
|
||||
discriminatedEntries.entries.forEach((entry) => {
|
||||
this.uint32(entry.id);
|
||||
this.uint16(entry.score);
|
||||
@@ -132,12 +122,7 @@ export class BkrlWriteStream extends WriteStream {
|
||||
this.uint32(entry.wins);
|
||||
this.uint32(entry.survived);
|
||||
|
||||
this.uint32(entry.damageDealt);
|
||||
this.uint32(entry.damageReceived);
|
||||
|
||||
this.uint32(entry.shots);
|
||||
this.uint32(entry.hits);
|
||||
|
||||
this.uint32(entry.damage);
|
||||
this.uint32(entry.kills);
|
||||
});
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user