From 4fedaf1cea8ddd7b90eee216667b035e64579837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 8 Mar 2024 20:43:30 -0600 Subject: [PATCH] feat: removed search tanks --- .../components/Model/components/TankModel.tsx | 10 +-- src/commands/playerInfo.ts | 40 ++++++--- src/commands/ratings.tsx | 4 +- src/commands/searchTanks.ts | 87 ++++++++++--------- src/core/blitz/applyPitchYawLimits.ts | 8 +- ...malizeAngle180.ts => normalizeAngleRad.ts} | 2 +- src/events/interactionCreate/index.ts | 4 - src/lang/en-US.json | 15 ++++ 8 files changed, 101 insertions(+), 69 deletions(-) rename src/core/math/{normalizeAngle180.ts => normalizeAngleRad.ts} (77%) diff --git a/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx b/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx index 472675451..e5253be2e 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx @@ -10,7 +10,7 @@ import { ModelTransformEventData, modelTransformEvent, } from '../../../../../../../core/blitzkrieg/modelTransform'; -import { normalizeAnglePI } from '../../../../../../../core/math/normalizeAngle180'; +import { normalizeAngleRad } from '../../../../../../../core/math/normalizeAngleRad'; import { useAwait } from '../../../../../../../hooks/useAwait'; import { useModel } from '../../../../../../../hooks/useModel'; import { mutateDuel, useDuel } from '../../../../../../../stores/duel'; @@ -172,8 +172,8 @@ export const TankModel = memo(() => { } function handlePointerUp() { mutateDuel((draft) => { - draft.protagonist!.pitch = normalizeAnglePI(pitch); - draft.protagonist!.yaw = normalizeAnglePI(yaw); + draft.protagonist!.pitch = normalizeAngleRad(pitch); + draft.protagonist!.yaw = normalizeAngleRad(yaw); }); mutateTankopediaPersistent((draft) => { draft.model.visual.controlsEnabled = true; @@ -234,8 +234,8 @@ export const TankModel = memo(() => { draft.model.visual.controlsEnabled = true; }); mutateDuel((draft) => { - draft.protagonist!.pitch = normalizeAnglePI(pitch); - draft.protagonist!.yaw = normalizeAnglePI(yaw); + draft.protagonist!.pitch = normalizeAngleRad(pitch); + draft.protagonist!.yaw = normalizeAngleRad(yaw); }); window.removeEventListener('pointermove', handlePointerMove); window.removeEventListener('pointerup', handlePointerUp); diff --git a/src/commands/playerInfo.ts b/src/commands/playerInfo.ts index 69a628be9..f9db1c97f 100644 --- a/src/commands/playerInfo.ts +++ b/src/commands/playerInfo.ts @@ -1,11 +1,12 @@ -import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { getAccountInfo } from '../core/blitz/getAccountInfo'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; +import { createLocalizedCommand } from '../core/discord/createLocalizedCommand'; import embedInfo from '../core/discord/embedInfo'; import markdownTable from '../core/discord/markdownTable'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; +import { translator } from '../core/localization/translator'; import { CommandRegistry } from '../events/interactionCreate'; export const playerInfoCommand = new Promise((resolve) => { @@ -13,24 +14,28 @@ export const playerInfoCommand = new Promise((resolve) => { inProduction: true, inPublic: true, - command: new SlashCommandBuilder() - .setName('player-info') - .setDescription('Basic information about a player') - .addStringOption(addUsernameChoices), + command: + createLocalizedCommand('player-info').addStringOption(addUsernameChoices), async handler(interaction) { + const { t, translate } = translator(interaction.locale); const account = await resolvePlayerFromCommand(interaction); const { id, region: region } = account; const accountInfo = await getAccountInfo(region, id); return embedInfo( - `${markdownEscape(accountInfo.nickname)}'s information`, + translate('bot.command.player_info.body.title', [ + markdownEscape(accountInfo.nickname), + ]), markdownTable([ - ['Nickname', `${accountInfo.nickname}`], - ['Battles', `${accountInfo.statistics.all.battles}`], + [t`bot.command.player_info.body.nickname`, `${accountInfo.nickname}`], [ - 'Winrate', + t`bot.command.player_info.body.battles`, + `${accountInfo.statistics.all.battles}`, + ], + [ + t`bot.command.player_info.body.winrate`, `${( 100 * (accountInfo.statistics.all.wins / @@ -38,14 +43,21 @@ export const playerInfoCommand = new Promise((resolve) => { ).toFixed(2)}%`, ], [], - ['Account ID', `${accountInfo.account_id}`], [ - 'Created', - `${new Date(accountInfo.created_at * 1000).toDateString()}`, + t`bot.command.player_info.body.account_id`, + `${accountInfo.account_id}`, ], [ - 'Last battle', - `${new Date(accountInfo.last_battle_time * 1000).toDateString()}`, + t`bot.command.player_info.body.created`, + new Date(accountInfo.created_at * 1000).toLocaleDateString( + interaction.locale, + ), + ], + [ + t`bot.command.player_info.body.last_battle`, + new Date(accountInfo.last_battle_time * 1000).toLocaleDateString( + interaction.locale, + ), ], ]), ); diff --git a/src/commands/ratings.tsx b/src/commands/ratings.tsx index 6496eb572..485d4e43e 100644 --- a/src/commands/ratings.tsx +++ b/src/commands/ratings.tsx @@ -351,7 +351,9 @@ export const ratingsCommand = new Promise(async (resolve) => { playersAfter = regionRatingsInfo.count - result[result.length - 1].position; titleName = `${ - leagueInfo ? leagueInfo.title : '' + leagueInfo + ? translate(`common.leagues.${LEAGUES[leagueInfo.index].name}`) + : '' } - ${translate(`common.regions.short.${region}`)}`; titleImage = leagueInfo.big_icon.startsWith('http') ? leagueInfo.big_icon diff --git a/src/commands/searchTanks.ts b/src/commands/searchTanks.ts index 86dfa42ab..aae81e883 100644 --- a/src/commands/searchTanks.ts +++ b/src/commands/searchTanks.ts @@ -1,44 +1,51 @@ -import { SlashCommandBuilder } from 'discord.js'; -import { go } from 'fuzzysort'; -import markdownEscape from 'markdown-escape'; -import { tankNames } from '../core/blitzkrieg/tankDefinitions'; -import addTankChoices from '../core/discord/addTankChoices'; -import embedInfo from '../core/discord/embedInfo'; -import { CommandRegistry } from '../events/interactionCreate'; +// _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __ +// |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ / +// | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' / +// | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | < +// _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \ +// |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\ -export const searchTanksCommand = new Promise((resolve) => { - resolve({ - inProduction: true, - inPublic: true, +// import { SlashCommandBuilder } from 'discord.js'; +// import { go } from 'fuzzysort'; +// import markdownEscape from 'markdown-escape'; +// import { tankNames } from '../core/blitzkrieg/tankDefinitions'; +// import addTankChoices from '../core/discord/addTankChoices'; +// import embedInfo from '../core/discord/embedInfo'; +// import { CommandRegistry } from '../events/interactionCreate'; - command: new SlashCommandBuilder() - .setName('search-tanks') - .setDescription('Search tanks') - .addStringOption((option) => - addTankChoices(option).setAutocomplete(false), - ) - .addIntegerOption((option) => - option - .setName('limit') - .setDescription('The size of the search result (default: 25)') - .setMinValue(1) - .setMaxValue(100), - ), +// export const searchTanksCommand = new Promise((resolve) => { +// resolve({ +// inProduction: true, +// inPublic: true, - async handler(interaction) { - const tank = interaction.options.getString('tank')!; - const limit = interaction.options.getInteger('limit') ?? 25; - const results = go(tank, await tankNames, { - limit, - keys: ['combined'], - }).map((result) => result.obj.original); +// command: new SlashCommandBuilder() +// .setName('search-tanks') +// .setDescription('Search tanks') +// .addStringOption((option) => +// addTankChoices(option).setAutocomplete(false), +// ) +// .addIntegerOption((option) => +// option +// .setName('limit') +// .setDescription('The size of the search result (default: 25)') +// .setMinValue(1) +// .setMaxValue(100), +// ), - return embedInfo( - `Tank search for "${markdownEscape(tank)}"`, - results.length === 0 - ? 'No tanks found.' - : `\`\`\`\n${results.join('\n')}\n\`\`\``, - ); - }, - }); -}); +// async handler(interaction) { +// const tank = interaction.options.getString('tank')!; +// const limit = interaction.options.getInteger('limit') ?? 25; +// const results = go(tank, await tankNames, { +// limit, +// keys: ['combined'], +// }).map((result) => result.obj.original); + +// return embedInfo( +// `Tank search for "${markdownEscape(tank)}"`, +// results.length === 0 +// ? 'No tanks found.' +// : `\`\`\`\n${results.join('\n')}\n\`\`\``, +// ); +// }, +// }); +// }); diff --git a/src/core/blitz/applyPitchYawLimits.ts b/src/core/blitz/applyPitchYawLimits.ts index 06994d837..7565ac3bf 100644 --- a/src/core/blitz/applyPitchYawLimits.ts +++ b/src/core/blitz/applyPitchYawLimits.ts @@ -1,6 +1,6 @@ import { clamp } from 'lodash'; import { PitchLimits, YawLimits } from '../blitzkrieg/modelDefinitions'; -import { normalizeAnglePI } from '../math/normalizeAngle180'; +import { normalizeAngleRad } from '../math/normalizeAngleRad'; export function applyPitchYawLimits( pitch: number, // rad @@ -12,7 +12,7 @@ export function applyPitchYawLimits( let newYaw = yaw; if (yawLimits) { - newYaw = normalizeAnglePI( + newYaw = normalizeAngleRad( clamp( newYaw, -yawLimits.max * (Math.PI / 180), @@ -27,7 +27,7 @@ export function applyPitchYawLimits( if (pitchLimits.back) { const range = pitchLimits.back.range * (Math.PI / 180); - const yawRotatedAbs = Math.abs(normalizeAnglePI(newYaw - Math.PI)); + const yawRotatedAbs = Math.abs(normalizeAngleRad(newYaw - Math.PI)); if (yawRotatedAbs <= range + transition) { if (yawRotatedAbs <= range) { @@ -52,7 +52,7 @@ export function applyPitchYawLimits( if (pitchLimits.front) { const range = pitchLimits.front.range * (Math.PI / 180); - const yawAbs = Math.abs(normalizeAnglePI(newYaw)); + const yawAbs = Math.abs(normalizeAngleRad(newYaw)); if (yawAbs <= range + transition) { if (yawAbs <= range) { diff --git a/src/core/math/normalizeAngle180.ts b/src/core/math/normalizeAngleRad.ts similarity index 77% rename from src/core/math/normalizeAngle180.ts rename to src/core/math/normalizeAngleRad.ts index 264995e05..b62b23a10 100644 --- a/src/core/math/normalizeAngle180.ts +++ b/src/core/math/normalizeAngleRad.ts @@ -1,4 +1,4 @@ -export function normalizeAnglePI(angle: number) { +export function normalizeAngleRad(angle: number) { const newAngle = angle % (2 * Math.PI); if (newAngle > Math.PI) return newAngle - 2 * Math.PI; if (newAngle < -Math.PI) return newAngle + 2 * Math.PI; diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index 3f21ef942..3b3e8293e 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -24,12 +24,10 @@ import { verifyCommand } from '../../commands/link'; import { ownedTanksCommand } from '../../commands/ownedTanks'; import { permissionsCommand } from '../../commands/permissions'; import { pingCommand } from '../../commands/ping'; -import { playerAchievementsCommand } from '../../commands/playerAchievements'; import { playerInfoCommand } from '../../commands/playerInfo'; import { ratingsCommand } from '../../commands/ratings'; import { searchClansCommand } from '../../commands/searchClans'; import { searchPlayersCommand } from '../../commands/searchPlayers'; -import { searchTanksCommand } from '../../commands/searchTanks'; import { statsCommand } from '../../commands/stats'; import { todayCommand } from '../../commands/today'; import getClientId from '../../core/blitzkrieg/getClientId'; @@ -84,11 +82,9 @@ export const COMMANDS_RAW: Promise[] = [ aboutCommand, inactiveCommand, ownedTanksCommand, - playerAchievementsCommand, playerInfoCommand, searchClansCommand, searchPlayersCommand, - searchTanksCommand, fullStatsCommand, breakdownCommand, verifyCommand, diff --git a/src/lang/en-US.json b/src/lang/en-US.json index e33d38a45..c438702a2 100644 --- a/src/lang/en-US.json +++ b/src/lang/en-US.json @@ -471,6 +471,21 @@ "description": "Ping World of Tanks Blitz" } } + }, + + "player_info": { + "$": "player-info", + "description": "Basic information about a player", + + "body": { + "title": "%'s information", + "nickname": "Nickname", + "battles": "Battles", + "winrate": "Winrate", + "account_id": "Account ID", + "created": "Created", + "last_battle": "Last battle" + } } } },