mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: some migration
This commit is contained in:
1 parent
e06aaa4bcf
commit
02aed3e3a5
25 files changed
+637
-73
No files matched your search
@@ -16,7 +16,8 @@
|
||||
"markdown-escape": "^2.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "bun --watch src/main.ts"
|
||||
"dev": "bun --watch src/main.ts",
|
||||
"start": "bun src/main.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/markdown-escape": "^1.1.3"
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import {
|
||||
StatFilters,
|
||||
emblemURL,
|
||||
filterStats,
|
||||
getAccountInfo,
|
||||
getClanAccountInfo,
|
||||
getTierWeights,
|
||||
@@ -13,6 +11,7 @@ import { NoData } from '../components/NoData';
|
||||
import { TierWeights } from '../components/TierWeights';
|
||||
import { TitleBar } from '../components/TitleBar';
|
||||
import { filtersToDescription } from '../core/blitzkit/filtersToDescription';
|
||||
import { filterStats, StatFilters } from '../core/blitzstars/filterStats';
|
||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||
import { getStatsInPeriod } from '../core/blitzstars/getStatsInPeriod';
|
||||
import { addPeriodicFilterOptions } from '../core/discord/addPeriodicFilterOptions';
|
||||
|
||||
@@ -167,29 +167,52 @@ export const researchCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
const trackXps = new Map<number, number>();
|
||||
|
||||
tank.turrets.forEach((turret) => {
|
||||
if (turret.xp !== undefined) {
|
||||
turretXps.set(turret.id, turret.xp);
|
||||
if (
|
||||
turret.research_cost !== undefined &&
|
||||
typeof turret.research_cost.research_cost_type!.value === 'number'
|
||||
) {
|
||||
turretXps.set(
|
||||
turret.id,
|
||||
turret.research_cost.research_cost_type!.value,
|
||||
);
|
||||
}
|
||||
|
||||
turret.guns.forEach((gun) => {
|
||||
if (gun.gunType!.value.base.xp !== undefined) {
|
||||
if (
|
||||
gun.gun_type!.value.base.research_cost !== undefined &&
|
||||
typeof gun.gun_type!.value.base.research_cost
|
||||
.research_cost_type!.value === 'number'
|
||||
) {
|
||||
gunXps.set(
|
||||
gun.gunType!.value.base.id,
|
||||
gun.gunType!.value.base.xp,
|
||||
gun.gun_type!.value.base.id,
|
||||
gun.gun_type!.value.base.research_cost.research_cost_type!
|
||||
.value,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tank.engines.forEach((engine) => {
|
||||
if (engine.xp !== undefined) {
|
||||
engineXps.set(engine.id, engine.xp);
|
||||
if (
|
||||
engine.research_cost !== undefined &&
|
||||
typeof engine.research_cost.research_cost_type!.value === 'number'
|
||||
) {
|
||||
engineXps.set(
|
||||
engine.id,
|
||||
engine.research_cost.research_cost_type!.value,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
tank.tracks.forEach((track) => {
|
||||
if (track.xp !== undefined) {
|
||||
trackXps.set(track.id, track.xp);
|
||||
if (
|
||||
track.research_cost !== undefined &&
|
||||
typeof track.research_cost.research_cost_type!.value === 'number'
|
||||
) {
|
||||
trackXps.set(
|
||||
track.id,
|
||||
track.research_cost.research_cost_type!.value,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -208,7 +231,7 @@ export const researchCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
});
|
||||
|
||||
return {
|
||||
research: tank.xp,
|
||||
research: tank.research_cost!.research_cost_type!.value as number,
|
||||
upgrades: moduleXp,
|
||||
purchase: tank.price.value,
|
||||
equipment: equipmentPriceMatrix[tank.tier].reduce(
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import {
|
||||
StatFilters,
|
||||
emblemURL,
|
||||
filterStats,
|
||||
getAccountInfo,
|
||||
getClanAccountInfo,
|
||||
} from '@blitzkit/core';
|
||||
import { emblemURL, getAccountInfo, getClanAccountInfo } from '@blitzkit/core';
|
||||
import { Locale } from 'discord.js';
|
||||
import { AllStatsOverview } from '../components/AllStatsOverview';
|
||||
import { CommandWrapper } from '../components/CommandWrapper';
|
||||
import { NoData } from '../components/NoData';
|
||||
import { TitleBar } from '../components/TitleBar';
|
||||
import { filtersToDescription } from '../core/blitzkit/filtersToDescription';
|
||||
import { filterStats, StatFilters } from '../core/blitzstars/filterStats';
|
||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||
import { getStatsInPeriod } from '../core/blitzstars/getStatsInPeriod';
|
||||
import { addPeriodicFilterOptions } from '../core/discord/addPeriodicFilterOptions';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { gameDefinitions } from '@blitzkit/core';
|
||||
import { gameDefinitions } from '../core/blitzkit/nonBlockingPromises';
|
||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||
import { addFilterOptions } from '../core/discord/addFilterOptions';
|
||||
import { addUsernameChoices } from '../core/discord/addUsernameChoices';
|
||||
|
||||
@@ -84,7 +84,7 @@ export function Row({
|
||||
displayType === 'tank'
|
||||
? type === TankType.COLLECTOR
|
||||
? theme.textLowContrast_blue
|
||||
: treeType === 'premium'
|
||||
: type === TankType.PREMIUM
|
||||
? theme.textLowContrast_amber
|
||||
: theme.textHighContrast
|
||||
: theme.textLowContrast,
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
import { TankClass, TREE_TYPE_ICONS, TreeType } from '@blitzkit/core';
|
||||
import { TankClass, TankType, TREE_TYPE_ICONS } from '@blitzkit/core';
|
||||
import { theme } from '../../../../stitches.config';
|
||||
|
||||
export interface ItemProps {
|
||||
tankType?: TankClass;
|
||||
tankClass?: TankClass;
|
||||
name: string;
|
||||
treeType: TreeType;
|
||||
tankType: TankType;
|
||||
}
|
||||
|
||||
const TREE_TYPE_COLOR = {
|
||||
researchable: '',
|
||||
premium: '_amber',
|
||||
collector: '_blue',
|
||||
[TankType.RESEARCHABLE]: '',
|
||||
[TankType.PREMIUM]: '_amber',
|
||||
[TankType.COLLECTOR]: '_blue',
|
||||
} as const;
|
||||
|
||||
export function Item({ tankType, name, treeType }: ItemProps) {
|
||||
export function Item({
|
||||
tankClass: tankType,
|
||||
name,
|
||||
tankType: treeType,
|
||||
}: ItemProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
@@ -40,7 +44,7 @@ export function Item({ tankType, name, treeType }: ItemProps) {
|
||||
>
|
||||
{tankType && (
|
||||
<img
|
||||
alt={tankType}
|
||||
alt={TankType[tankType]}
|
||||
src={TREE_TYPE_ICONS[treeType][tankType]}
|
||||
style={{ width: 14, height: 14 }}
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { tankNames } from '../blitzkit/nonBlockingPromises';
|
||||
import { tankDefinitions, tankNames } from '../blitzkit/nonBlockingPromises';
|
||||
import { UserError } from '../blitzkit/userError';
|
||||
import { tankNamesTechTreeOnly } from '../discord/autocompleteTanks';
|
||||
import { translator } from '../localization/translator';
|
||||
@@ -34,7 +34,9 @@ export async function resolveTankId(
|
||||
return searchResult[0].obj.id;
|
||||
}
|
||||
} else {
|
||||
if ((await tankDefinitions)[number]) {
|
||||
const awaitedTankDefinitions = await tankDefinitions;
|
||||
|
||||
if (awaitedTankDefinitions.tanks[number]) {
|
||||
return number;
|
||||
} else {
|
||||
throw new UserError(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { flagUserActivity, idToRegion, usersDatabase } from '@blitzkit/core';
|
||||
import { idToRegion, usersDatabase } from '@blitzkit/core';
|
||||
import { flagUserActivity } from '@blitzkit/core/src/blitzkit/flagUserActivity';
|
||||
|
||||
export async function getBlitzFromDiscord(discordId: bigint) {
|
||||
const unique = await usersDatabase.discordUser.findUnique({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TankClass, TankType } from '@blitzkit/core';
|
||||
import { TankClass, TankType, Tier } from '@blitzkit/core';
|
||||
import { SupplementaryStats } from '@blitzkit/core/src/blitz/getAccountInfo';
|
||||
import { calculateWN8 } from '@blitzkit/core/src/statistics/calculateWN8';
|
||||
import { BlitzStats } from '@blitzkit/core/src/statistics/compositeStats';
|
||||
@@ -8,7 +8,7 @@ import { blitzStarsTankAverages } from './tankAverages';
|
||||
|
||||
export interface StatFilters {
|
||||
nation?: string;
|
||||
tier?: number;
|
||||
tier?: Tier;
|
||||
class?: TankClass;
|
||||
type?: TankType;
|
||||
tank?: number;
|
||||
|
||||
@@ -62,7 +62,7 @@ export function addFilterOptions<
|
||||
...TANK_CLASSES.map(
|
||||
(tankType) =>
|
||||
({
|
||||
value: tankType,
|
||||
value: `${tankType}`,
|
||||
name: translate(`common.tank_class_short.${tankType}`),
|
||||
name_localizations: localizationObject(
|
||||
`common.tank_class_short.${tankType}`,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { gameDefinitions } from '@blitzkit/core';
|
||||
import {
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { gameDefinitions } from '../blitzkit/nonBlockingPromises';
|
||||
import { addFilterOptions } from './addFilterOptions';
|
||||
import { addPeriodSubCommands } from './addPeriodSubCommands';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { StatFilters, TreeType } from '@blitzkit/core';
|
||||
import { TankClass, TankType } from '@blitzkit/core';
|
||||
import { ButtonInteraction } from 'discord.js';
|
||||
import { StatFilters } from '../blitzstars/filterStats';
|
||||
|
||||
export function getFiltersFromButton(interaction: ButtonInteraction) {
|
||||
const url = new URL(`https://example.com/${interaction.customId}`);
|
||||
@@ -7,9 +8,12 @@ export function getFiltersFromButton(interaction: ButtonInteraction) {
|
||||
return {
|
||||
nation: url.searchParams.get('nation') ?? undefined,
|
||||
tank: parseInt(url.searchParams.get('tank') ?? '0') || undefined,
|
||||
tankType: url.searchParams.get('tank-class') ?? undefined,
|
||||
treeType:
|
||||
(url.searchParams.get('tree-type') as TreeType | undefined) ?? undefined,
|
||||
class:
|
||||
(Number(url.searchParams.get('class')) as TankClass | undefined) ??
|
||||
undefined,
|
||||
type:
|
||||
(Number(url.searchParams.get('type')) as TankType | undefined) ??
|
||||
undefined,
|
||||
tier: parseInt(url.searchParams.get('tier') ?? '0') || undefined,
|
||||
} satisfies StatFilters;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { StatFilters, TreeType } from '@blitzkit/core';
|
||||
import { TankClass, TankType } from '@blitzkit/core';
|
||||
import { ChatInputCommandInteraction } from 'discord.js';
|
||||
import { resolveTankId } from '../blitz/resolveTankId';
|
||||
import { StatFilters } from '../blitzstars/filterStats';
|
||||
|
||||
export async function getFiltersFromCommand(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
@@ -9,10 +10,13 @@ export async function getFiltersFromCommand(
|
||||
|
||||
return {
|
||||
nation: interaction.options.getString('nation') ?? undefined,
|
||||
tier: parseInt(interaction.options.getString('tier') ?? '0') || undefined,
|
||||
tankType: interaction.options.getString('tank-class') ?? undefined,
|
||||
treeType:
|
||||
(interaction.options.getString('tree-type') as TreeType | undefined) ??
|
||||
tier: Number(interaction.options.getString('tier')),
|
||||
class:
|
||||
(Number(interaction.options.getString('class')) as
|
||||
| TankClass
|
||||
| undefined) ?? undefined,
|
||||
type:
|
||||
(Number(interaction.options.getString('type')) as TankType | undefined) ??
|
||||
undefined,
|
||||
tank:
|
||||
tankRaw === null
|
||||
|
||||
Reference in new issue
Block a user