mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: further progress on embeds
This commit is contained in:
1 parent
33cd556c45
commit
d35ed8a212
4 files changed
+84
-24
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
import { GunDefinition, ProvisionDefinitions, TankDefinition } from '../protos';
|
||||||
|
import { availableProvisions } from './availableProvisions';
|
||||||
|
|
||||||
|
const PROVISION_PREFERENCES = [
|
||||||
|
19, // improved fuel
|
||||||
|
18, // standard fuel
|
||||||
|
22, // protective kit
|
||||||
|
];
|
||||||
|
|
||||||
|
function infinityFallback(value: number) {
|
||||||
|
return value === -1 ? Infinity : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createDefaultProvisions(
|
||||||
|
tank: TankDefinition,
|
||||||
|
gun: GunDefinition,
|
||||||
|
provisionDefinitions: ProvisionDefinitions,
|
||||||
|
) {
|
||||||
|
const provisionsList = availableProvisions(tank, gun, provisionDefinitions);
|
||||||
|
|
||||||
|
return provisionsList
|
||||||
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
infinityFallback(PROVISION_PREFERENCES.indexOf(a.id)) -
|
||||||
|
infinityFallback(PROVISION_PREFERENCES.indexOf(b.id)),
|
||||||
|
)
|
||||||
|
.sort((a, b) => (b.crew ?? 0) - (a.crew ?? 0))
|
||||||
|
.slice(0, tank.max_provisions)
|
||||||
|
.map(({ id }) => id);
|
||||||
|
}
|
||||||
@@ -43,6 +43,7 @@ export * from './uniqueGuns';
|
|||||||
export * from './unwrapBlitzkitResponse';
|
export * from './unwrapBlitzkitResponse';
|
||||||
export * from './votes';
|
export * from './votes';
|
||||||
// export * from './withCORSProxy';
|
// export * from './withCORSProxy';
|
||||||
|
export * from './createDefaultProvisions';
|
||||||
export * from './metaSortTank';
|
export * from './metaSortTank';
|
||||||
export * from './romanize';
|
export * from './romanize';
|
||||||
export * from './youtubers';
|
export * from './youtubers';
|
||||||
@@ -1,43 +1,24 @@
|
|||||||
import {
|
import {
|
||||||
availableProvisions,
|
createDefaultProvisions,
|
||||||
type ProvisionDefinitions,
|
type ProvisionDefinitions,
|
||||||
type TankDefinition,
|
type TankDefinition,
|
||||||
} from '@blitzkit/core';
|
} from '@blitzkit/core';
|
||||||
import type { DuelMember } from '../../stores/duel';
|
import type { DuelMember } from '../../stores/duel';
|
||||||
import { genericDefaultEquipmentMatrix } from '../../stores/duel/constants';
|
import { genericDefaultEquipmentMatrix } from '../../stores/duel/constants';
|
||||||
|
|
||||||
const PROVISION_PREFERENCES = [
|
|
||||||
19, // improved fuel
|
|
||||||
18, // standard fuel
|
|
||||||
22, // protective kit
|
|
||||||
];
|
|
||||||
|
|
||||||
function infinityFallback(value: number) {
|
|
||||||
return value === -1 ? Infinity : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tankToDuelMember(
|
export function tankToDuelMember(
|
||||||
tank: TankDefinition,
|
tank: TankDefinition,
|
||||||
provisionDefinitions: ProvisionDefinitions,
|
provisionDefinitions: ProvisionDefinitions,
|
||||||
) {
|
) {
|
||||||
const turret = tank.turrets.at(-1)!;
|
const turret = tank.turrets.at(-1)!;
|
||||||
const gun = turret.guns.at(-1)!;
|
const gun = turret.guns.at(-1)!;
|
||||||
const provisionsList = availableProvisions(tank, gun, provisionDefinitions);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
camouflage: true,
|
camouflage: true,
|
||||||
consumables: [],
|
consumables: [],
|
||||||
equipmentMatrix: genericDefaultEquipmentMatrix,
|
equipmentMatrix: genericDefaultEquipmentMatrix,
|
||||||
cooldownBooster: 0,
|
cooldownBooster: 0,
|
||||||
provisions: provisionsList
|
provisions: createDefaultProvisions(tank, gun, provisionDefinitions),
|
||||||
.sort(
|
|
||||||
(a, b) =>
|
|
||||||
infinityFallback(PROVISION_PREFERENCES.indexOf(a.id)) -
|
|
||||||
infinityFallback(PROVISION_PREFERENCES.indexOf(b.id)),
|
|
||||||
)
|
|
||||||
.sort((a, b) => (b.crew ?? 0) - (a.crew ?? 0))
|
|
||||||
.slice(0, tank.max_provisions)
|
|
||||||
.map(({ id }) => id),
|
|
||||||
engine: tank.engines.at(-1)!,
|
engine: tank.engines.at(-1)!,
|
||||||
gun,
|
gun,
|
||||||
shell: tank.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0],
|
shell: tank.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0],
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
---
|
---
|
||||||
import {
|
import {
|
||||||
asset,
|
asset,
|
||||||
|
createDefaultProvisions,
|
||||||
|
createDefaultSkills,
|
||||||
|
fetchEquipmentDefinitions,
|
||||||
|
fetchModelDefinitions,
|
||||||
|
fetchProvisionDefinitions,
|
||||||
|
fetchSkillDefinitions,
|
||||||
fetchTankDefinitions,
|
fetchTankDefinitions,
|
||||||
TIER_ROMAN_NUMERALS,
|
TIER_ROMAN_NUMERALS,
|
||||||
} from '@blitzkit/core';
|
} from '@blitzkit/core';
|
||||||
import strings from '@blitzkit/core/lang/en-US.json';
|
import strings from '@blitzkit/core/lang/en-US.json';
|
||||||
import type { GetStaticPaths } from 'astro';
|
import type { GetStaticPaths } from 'astro';
|
||||||
|
import { tankCharacteristics } from '../../../../core/blitzkit/tankCharacteristics';
|
||||||
import BaseLayout from '../../../../layouts/BaseLayout.astro';
|
import BaseLayout from '../../../../layouts/BaseLayout.astro';
|
||||||
|
import { genericDefaultEquipmentMatrix } from '../../../../stores/duel/constants';
|
||||||
import { Page } from './_index';
|
import { Page } from './_index';
|
||||||
|
|
||||||
export const getStaticPaths = (async () => {
|
export const getStaticPaths = (async () => {
|
||||||
@@ -20,16 +28,52 @@ export const getStaticPaths = (async () => {
|
|||||||
const { id } = Astro.params;
|
const { id } = Astro.params;
|
||||||
|
|
||||||
const tankDefinitions = await fetchTankDefinitions();
|
const tankDefinitions = await fetchTankDefinitions();
|
||||||
|
const skillDefinitions = await fetchSkillDefinitions();
|
||||||
|
const provisionDefinitions = await fetchProvisionDefinitions();
|
||||||
|
const equipmentDefinitions = await fetchEquipmentDefinitions();
|
||||||
|
const tankModelDefinitions = await fetchModelDefinitions();
|
||||||
const tank = tankDefinitions.tanks[id];
|
const tank = tankDefinitions.tanks[id];
|
||||||
|
const tankModelDefinition = tankModelDefinitions.models[tank.id];
|
||||||
const name = tank.name_full ?? tank.name;
|
const name = tank.name_full ?? tank.name;
|
||||||
const title = `${name} - Tier ${TIER_ROMAN_NUMERALS[tank.tier]} ${
|
const title = `${name}, Tier ${TIER_ROMAN_NUMERALS[tank.tier]} ${
|
||||||
strings.common.nations_adjectives[
|
strings.common.nations_adjectives[
|
||||||
tank.nation as keyof typeof strings.common.nations_adjectives
|
tank.nation as keyof typeof strings.common.nations_adjectives
|
||||||
]
|
]
|
||||||
} ${strings.common.tank_class_short[tank.class]}`;
|
} ${strings.common.tank_class_short[tank.class]} | BlitzKit Tankopedia | World of Tanks Blitz (WoTB)`;
|
||||||
const url = import.meta.env.SITE + Astro.url.pathname;
|
const url = import.meta.env.SITE + Astro.url.pathname;
|
||||||
const description = `${name} armor, statistics, equipment, provisions, and more.`;
|
|
||||||
const icon = asset(`icons/tanks/big/${id}.webp`);
|
const icon = asset(`icons/tanks/big/${id}.webp`);
|
||||||
|
const turret = tank.turrets.at(-1)!;
|
||||||
|
const gun = turret.guns.at(-1)!;
|
||||||
|
const characteristics = tankCharacteristics(
|
||||||
|
{
|
||||||
|
tank,
|
||||||
|
applyDynamicArmor: false,
|
||||||
|
applyReactiveArmor: false,
|
||||||
|
applySpallLiner: false,
|
||||||
|
camouflage: true,
|
||||||
|
consumables: [],
|
||||||
|
crewSkills: createDefaultSkills(skillDefinitions),
|
||||||
|
engine: tank.engines.at(-1)!,
|
||||||
|
equipmentMatrix: genericDefaultEquipmentMatrix,
|
||||||
|
turret,
|
||||||
|
gun,
|
||||||
|
provisions: createDefaultProvisions(tank, gun, provisionDefinitions),
|
||||||
|
shell: gun.gun_type!.value.base.shells[0],
|
||||||
|
stockEngine: tank.engines[0],
|
||||||
|
stockGun: tank.turrets[0].guns[0],
|
||||||
|
stockTurret: tank.turrets[0],
|
||||||
|
stockTrack: tank.tracks[0],
|
||||||
|
track: tank.tracks.at(-1)!,
|
||||||
|
},
|
||||||
|
{ equipmentDefinitions, provisionDefinitions, tankModelDefinition },
|
||||||
|
);
|
||||||
|
const description = `${
|
||||||
|
name
|
||||||
|
} armor, statistics, equipment, provisions, and more. ${Math.round(
|
||||||
|
characteristics.dpm,
|
||||||
|
).toLocaleString()} DPM, ${characteristics.damage}hp damage, ${
|
||||||
|
characteristics.speedForwards
|
||||||
|
}kph top speed, ${characteristics.health}hp health.`;
|
||||||
---
|
---
|
||||||
|
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
@@ -38,6 +82,10 @@ const icon = asset(`icons/tanks/big/${id}.webp`);
|
|||||||
<meta property="og:description" content={description} />
|
<meta property="og:description" content={description} />
|
||||||
<meta property="og:image" content={icon} />
|
<meta property="og:image" content={icon} />
|
||||||
<meta property="og:url" content={url} />
|
<meta property="og:url" content={url} />
|
||||||
|
<meta name="twitter:title" content={title} />
|
||||||
|
<meta name="twitter:description" content={description} />
|
||||||
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
|
<meta name="twitter:image:src" content={icon} />
|
||||||
|
|
||||||
<BaseLayout>
|
<BaseLayout>
|
||||||
<Page id={id} client:only="react">
|
<Page id={id} client:only="react">
|
||||||
|
|||||||
Reference in new issue
Block a user