mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: start migration to proto for popular tanks
This commit is contained in:
1 parent
001709c25c
commit
ccb86ae824
8 files changed
+68
-66
No files matched your search
@@ -15,19 +15,9 @@ interface Props {
|
|||||||
const { locale } = Astro.props;
|
const { locale } = Astro.props;
|
||||||
|
|
||||||
const strings = await api.strings(locale);
|
const strings = await api.strings(locale);
|
||||||
|
const popular = (await api.popularTanks()).tanks.slice(0, 8);
|
||||||
|
|
||||||
const popular = [
|
console.log(popular.length);
|
||||||
"Concept 1B",
|
|
||||||
"Obj. 268",
|
|
||||||
"Grille 15",
|
|
||||||
"Kpz 70 Missile",
|
|
||||||
"Concept 1B",
|
|
||||||
"Concept 1B",
|
|
||||||
"Concept 1B",
|
|
||||||
"Concept 1B",
|
|
||||||
"Concept 1B",
|
|
||||||
"Concept 1B",
|
|
||||||
];
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -51,7 +41,7 @@ const popular = [
|
|||||||
|
|
||||||
<Scroller client:load className="tanks">
|
<Scroller client:load className="tanks">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{popular.map((tank) => <TankCard {tank} />)}
|
{popular.map((tank) => <TankCard {...tank} />)}
|
||||||
</div>
|
</div>
|
||||||
</Scroller>
|
</Scroller>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
|
import type { PopularTank } from "../../protos/popular_tanks";
|
||||||
import { Text } from "../Text";
|
import { Text } from "../Text";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
interface TankCard {
|
export function TankCard({ id }: PopularTank) {
|
||||||
tank: string;
|
const tanks = useAwait(api.tanks, "tanks");
|
||||||
}
|
|
||||||
|
|
||||||
export function TankCard({ tank }: TankCard) {
|
|
||||||
return (
|
return (
|
||||||
<div className={styles["tank-card"]}>
|
<div className={styles["tank-card"]}>
|
||||||
<div className={styles["icon-wrapper"]}>
|
<div className={styles["icon-wrapper"]}>
|
||||||
@@ -19,12 +18,12 @@ export function TankCard({ tank }: TankCard) {
|
|||||||
<div
|
<div
|
||||||
className={styles.icon}
|
className={styles.icon}
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: "url(https://i.imgur.com/HrkTwHc.png)",
|
backgroundImage: `url(/api/tanks/${id}.webp)`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Text className={styles.name}>{tank}</Text>
|
<Text className={styles.name}>{id}</Text>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ import type { Avatar } from "../../protos/avatar";
|
|||||||
import type { Avatars } from "../../protos/avatars";
|
import type { Avatars } from "../../protos/avatars";
|
||||||
import type { Background } from "../../protos/background";
|
import type { Background } from "../../protos/background";
|
||||||
import type { Backgrounds } from "../../protos/backgrounds";
|
import type { Backgrounds } from "../../protos/backgrounds";
|
||||||
|
import type { PopularTanks } from "../../protos/popular_tanks";
|
||||||
import type { Tank } from "../../protos/tank";
|
import type { Tank } from "../../protos/tank";
|
||||||
import type { TankList } from "../../protos/tank_list";
|
import type { TankList } from "../../protos/tank_list";
|
||||||
import type { Tanks } from "../../protos/tanks";
|
import type { Tanks } from "../../protos/tanks";
|
||||||
import type { PopularTanks } from "../../types/popularTanks";
|
|
||||||
|
|
||||||
export abstract class AbstractAPI {
|
export abstract class AbstractAPI {
|
||||||
private _tankListCache: TankList | undefined;
|
private _tankListCache: TankList | undefined;
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import { merge } from "lodash-es";
|
|||||||
import { parse } from "yaml";
|
import { parse } from "yaml";
|
||||||
import type { Avatar } from "../../protos/avatar";
|
import type { Avatar } from "../../protos/avatar";
|
||||||
import type { Background } from "../../protos/background";
|
import type { Background } from "../../protos/background";
|
||||||
|
import type { PopularTanks } from "../../protos/popular_tanks";
|
||||||
import type { Tank } from "../../protos/tank";
|
import type { Tank } from "../../protos/tank";
|
||||||
import type { TankListEntry } from "../../protos/tank_list";
|
import type { TankListEntry } from "../../protos/tank_list";
|
||||||
import type { Tanks } from "../../protos/tanks";
|
import type { Tanks } from "../../protos/tanks";
|
||||||
import type { PopularTanks } from "../../types/popularTanks";
|
|
||||||
import { AbstractAPI } from "./abstract";
|
import { AbstractAPI } from "./abstract";
|
||||||
|
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
@@ -302,9 +302,17 @@ export class ServerAPI extends AbstractAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const popularTanks: PopularTanks = Object.entries(views)
|
for (const id in tanks) {
|
||||||
.sort(([, a], [, b]) => b - a)
|
if (!(id in views)) {
|
||||||
.map(([id, views]) => ({ id, views }));
|
views[id] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const popularTanks = {
|
||||||
|
tanks: Object.entries(views)
|
||||||
|
.sort(([, a], [, b]) => b - a)
|
||||||
|
.map(([id, views]) => ({ id, views })),
|
||||||
|
} satisfies PopularTanks;
|
||||||
|
|
||||||
await mkdir("../../temp", { recursive: true });
|
await mkdir("../../temp", { recursive: true });
|
||||||
await writeFile("../../temp/popular.json", JSON.stringify(popularTanks));
|
await writeFile("../../temp/popular.json", JSON.stringify(popularTanks));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { TankClass } from "@blitzkit/core";
|
import { TankClass } from "@protos/blitz_static_tank_component";
|
||||||
import {
|
import {
|
||||||
ShellUpgrageSingleChange_AttributeName,
|
ShellUpgrageSingleChange_AttributeName,
|
||||||
StageParameters,
|
StageParameters,
|
||||||
@@ -40,7 +40,7 @@ export const characteristics = {
|
|||||||
if (isPump === 1) return GunType.AutoReloader;
|
if (isPump === 1) return GunType.AutoReloader;
|
||||||
|
|
||||||
const clipSize = attribute(
|
const clipSize = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (clipSize === 1) return GunType.Regular;
|
if (clipSize === 1) return GunType.Regular;
|
||||||
@@ -54,25 +54,25 @@ export const characteristics = {
|
|||||||
if (gunType === GunType.Regular) return null;
|
if (gunType === GunType.Regular) return null;
|
||||||
|
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
damage({ shell }) {
|
damage({ shell }) {
|
||||||
return shell(
|
return shell(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
module_damage({ shell }) {
|
module_damage({ shell }) {
|
||||||
return shell(
|
return shell(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MODULE_DAMAGE
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MODULE_DAMAGE,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
penetration({ shell }) {
|
penetration({ shell }) {
|
||||||
return shell(
|
return shell(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_PIERCING_POWER
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_PIERCING_POWER,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ export const characteristics = {
|
|||||||
if (gunType === GunType.AutoReloader) return null;
|
if (gunType === GunType.AutoReloader) return null;
|
||||||
|
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_RELOAD_TIME
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_RELOAD_TIME,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ export const characteristics = {
|
|||||||
if (gunType === GunType.Regular) return null;
|
if (gunType === GunType.Regular) return null;
|
||||||
|
|
||||||
const clipRate = attribute(
|
const clipRate = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_RATE
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_RATE,
|
||||||
);
|
);
|
||||||
|
|
||||||
return 60 / clipRate;
|
return 60 / clipRate;
|
||||||
@@ -173,13 +173,13 @@ export const characteristics = {
|
|||||||
|
|
||||||
normalization({ shellSafe }) {
|
normalization({ shellSafe }) {
|
||||||
return shellSafe(
|
return shellSafe(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_NORMALIZATION
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_NORMALIZATION,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
ricochet({ shell }) {
|
ricochet({ shell }) {
|
||||||
return shell(
|
return shell(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_RICOCHET_ANGLE
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_RICOCHET_ANGLE,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -191,54 +191,54 @@ export const characteristics = {
|
|||||||
|
|
||||||
shell_range({ shellSafe }) {
|
shell_range({ shellSafe }) {
|
||||||
const maxDistance = shellSafe(
|
const maxDistance = shellSafe(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_DISTANCE
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_DISTANCE,
|
||||||
);
|
);
|
||||||
return maxDistance === null ? Infinity : maxDistance / 100;
|
return maxDistance === null ? Infinity : maxDistance / 100;
|
||||||
},
|
},
|
||||||
|
|
||||||
shell_capacity({ shellSafe }) {
|
shell_capacity({ shellSafe }) {
|
||||||
const count = shellSafe(
|
const count = shellSafe(
|
||||||
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_COUNT
|
ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_COUNT,
|
||||||
);
|
);
|
||||||
return count === -1 || count === null ? Infinity : count;
|
return count === -1 || count === null ? Infinity : count;
|
||||||
},
|
},
|
||||||
|
|
||||||
aim_time({ attribute }) {
|
aim_time({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_AIMING_TIME
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_AIMING_TIME,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
speed_forward({ attribute }) {
|
speed_forward({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FORWARD_MAX_SPEED
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FORWARD_MAX_SPEED,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
speed_backward({ attribute }) {
|
speed_backward({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_BACKWARD_MAX_SPEED
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_BACKWARD_MAX_SPEED,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
dispersion({ attribute, characteristic, state }) {
|
dispersion({ attribute, characteristic, state }) {
|
||||||
const base = attribute(
|
const base = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_ANGLE
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_ANGLE,
|
||||||
);
|
);
|
||||||
const movement = attribute(
|
const movement = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_MOVEMENT
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_MOVEMENT,
|
||||||
);
|
);
|
||||||
const vehicleRotation = attribute(
|
const vehicleRotation = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_ROTATION
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_ROTATION,
|
||||||
);
|
);
|
||||||
const turretRotation = attribute(
|
const turretRotation = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_TURRET_ROTATION
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_TURRET_ROTATION,
|
||||||
);
|
);
|
||||||
const afterShot = attribute(
|
const afterShot = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_AFTER_SHOT
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_AFTER_SHOT,
|
||||||
);
|
);
|
||||||
const gunDamaged = attribute(
|
const gunDamaged = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_WHILE_GUN_DAMAGED
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_WHILE_GUN_DAMAGED,
|
||||||
);
|
);
|
||||||
const maxSpeed = characteristic("speed_forward") as number;
|
const maxSpeed = characteristic("speed_forward") as number;
|
||||||
|
|
||||||
@@ -258,8 +258,8 @@ export const characteristics = {
|
|||||||
-Math.PI / 2,
|
-Math.PI / 2,
|
||||||
0,
|
0,
|
||||||
parameters.pitch_limits_up,
|
parameters.pitch_limits_up,
|
||||||
parameters.pitch_limits_down
|
parameters.pitch_limits_down,
|
||||||
).pitch
|
).pitch,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -269,14 +269,14 @@ export const characteristics = {
|
|||||||
Math.PI / 2,
|
Math.PI / 2,
|
||||||
0,
|
0,
|
||||||
parameters.pitch_limits_up,
|
parameters.pitch_limits_up,
|
||||||
parameters.pitch_limits_down
|
parameters.pitch_limits_down,
|
||||||
).pitch
|
).pitch,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
engine_power({ attribute }) {
|
engine_power({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_ENGINE_POWER
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_ENGINE_POWER,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -316,7 +316,7 @@ export const characteristics = {
|
|||||||
|
|
||||||
turret_traverse_speed({ attribute }) {
|
turret_traverse_speed({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TURRET_ROTATION_SPEED
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_TURRET_ROTATION_SPEED,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -326,14 +326,14 @@ export const characteristics = {
|
|||||||
|
|
||||||
health({ attribute }) {
|
health({ attribute }) {
|
||||||
return attribute(
|
return attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_MAX_HEALTH
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_MAX_HEALTH,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
fire_chance({ attribute }) {
|
fire_chance({ attribute }) {
|
||||||
return (
|
return (
|
||||||
attribute(
|
attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FIRE_START_CHANCE
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FIRE_START_CHANCE,
|
||||||
) * 100
|
) * 100
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -341,7 +341,7 @@ export const characteristics = {
|
|||||||
view_range({ attribute }) {
|
view_range({ attribute }) {
|
||||||
return (
|
return (
|
||||||
attribute(
|
attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CIRCULAR_VISION_RADIUS
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CIRCULAR_VISION_RADIUS,
|
||||||
) / 100
|
) / 100
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -353,21 +353,21 @@ export const characteristics = {
|
|||||||
camouflage({ attribute, characteristic, attributeSafe, state }) {
|
camouflage({ attribute, characteristic, attributeSafe, state }) {
|
||||||
const tankClass = characteristic("class");
|
const tankClass = characteristic("class");
|
||||||
const base = attribute(
|
const base = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_STILL
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_STILL,
|
||||||
);
|
);
|
||||||
const moving =
|
const moving =
|
||||||
tankClass === TankClass.LIGHT
|
tankClass === TankClass.TANK_CLASS_LIGHT
|
||||||
? 0
|
? 0
|
||||||
: attribute(
|
: attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_MOVING
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_MOVING,
|
||||||
);
|
);
|
||||||
const shooting = attribute(
|
const shooting = attribute(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_FACTOR_AT_SHOT
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_FACTOR_AT_SHOT,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
attributeSafe(
|
attributeSafe(
|
||||||
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_FIRE_PENALTY
|
TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CONCEALMENT_FIRE_PENALTY,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
throw new Error("Fire penalty implemented! Code it in!!");
|
throw new Error("Fire penalty implemented! Code it in!!");
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { api } from "../../../core/api/dynamic";
|
import { api } from "../../../core/api/dynamic";
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
throw new Error(
|
|
||||||
"MAKE THIS A PROTO AND ADD LAST UPDATED TIME OH AND ADD 0's FOR TANKS WITH NO ENTRIES",
|
|
||||||
);
|
|
||||||
const popular = await api.popularTanks();
|
const popular = await api.popularTanks();
|
||||||
return Response.json(popular);
|
return Response.json(popular);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package blitzkit;
|
||||||
|
|
||||||
|
message PopularTanks {
|
||||||
|
repeated PopularTank tanks = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message PopularTank {
|
||||||
|
string id = 1;
|
||||||
|
int32 views = 2;
|
||||||
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
export type PopularTanks = {
|
|
||||||
id: string;
|
|
||||||
views: number;
|
|
||||||
}[];
|
|
||||||
Reference in new issue
Block a user