Compare commits

...
21 Commits
Author SHA1 Message Date
TrèsAbhi 0929825555 fix: glob and cache 2025-09-27 19:13:29 -05:00
TrèsAbhi 4de0fc5ec1 feat: concurrency 2025-09-27 18:37:51 -05:00
TrèsAbhi e66610f86e fix: side and out 2025-09-27 18:32:18 -05:00
TrèsAbhi 674abc4923 fix: dead code 2025-09-27 18:28:35 -05:00
TrèsAbhi 25cee8a36b fix: icons 2025-09-27 18:26:37 -05:00
TrèsAbhi dcbac5e017 fix: missing package 2025-09-27 18:16:05 -05:00
TrèsAbhi 0c94d42f3f fix: missing package 2025-09-27 18:15:00 -05:00
TrèsAbhi 7ab5e94323 fix: missing package 2025-09-27 18:13:59 -05:00
TrèsAbhi f9ea5ba74a fix: missing package 2025-09-27 18:13:00 -05:00
TrèsAbhi 1e7162d2da fix: missing package 2025-09-27 18:11:49 -05:00
TrèsAbhi cfba53a655 fix: missing package 2025-09-27 18:10:20 -05:00
TrèsAbhi 77a85641f0 fix: missing package 2025-09-27 18:09:10 -05:00
TrèsAbhi 5330a27e96 feat: logs 2025-09-27 18:07:43 -05:00
TrèsAbhi a791aff4a0 Merge branch 'main' into dev 2025-09-27 18:03:37 -05:00
TrèsAbhi df8a5967f0 feat: start of logs 2025-09-27 18:03:20 -05:00
TrèsAbhi 6261dfc9cd fix: more linting 2025-09-27 18:01:20 -05:00
TrèsAbhi 766801826c fix: canvases 2025-09-27 17:51:29 -05:00
TrèsAbhi 7b728596ca feat: storeDeferred 2025-09-27 17:32:20 -05:00
TrèsAbhi 0bf6ac33a5 feat: more promotion 2025-09-27 17:29:12 -05:00
TrèsAbhi 9a33b84b1c feat: install button 2025-09-27 17:05:06 -05:00
TrèsAbhi 675a613a0e New translations en.json (Russian) (#170) 2025-09-22 10:06:08 -05:00
36 changed files with 3585 additions and 442 deletions

No files matched your search

+2 -1
View File
@@ -27,4 +27,5 @@ target
.astro
.vercel
/src
/packages/bot/src/prisma
/packages/bot/src/prisma
dev-dist
+1
View File
@@ -21,6 +21,7 @@
"AYUV",
"battleresults",
"bbox",
"beforeinstallprompt",
"bepaint",
"betakrieg",
"BINORMAL",
+2904
View File
File diff suppressed because it is too large. Load diff
BIN
View File
Binary file not shown.
+16
View File
@@ -0,0 +1,16 @@
# BlitzKit 1.28.0
BlitzKit, as an app and the new Mixer tool!
## Features
- Created the BlitzKit app that can be downloaded on most devices
- Re-did the BlitzKit logo to be a bit warmer
- Added the Mixer tool which lets you combine tank models into Frankensteins
- Updated all dependencies to the latest version for a decent performance boost
## Fixes
- BlitzKit no longer forgets persistent data if the app crashes without properly closing
- The tools list in the navbar no longer overflows into the neighboring elements on certain devices
- Added keying to a few places, speeding up re-rendering
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "blitzkit",
"private": true,
"version": "1.27.20",
"version": "1.28.0",
"description": "🎉 Tools for everything World of Tanks Blitz",
"type": "module",
"types": "./types.d.ts",
+37 -37
View File
@@ -6,23 +6,23 @@ import {
getTankStats,
getWN8Percentile,
TankDefinition,
} from '@blitzkit/core';
import { literals } from '@blitzkit/i18n';
import { Locale } from 'discord.js';
import { chunk } from 'lodash-es';
import * as Breakdown from '../../components/Breakdown';
import { CommandWrapper } from '../../components/CommandWrapper';
import { NoData } from '../../components/NoData';
import { TitleBar } from '../../components/TitleBar';
import { filtersToDescription } from '../../core/blitzkit/filtersToDescription';
import { tankDefinitions } from '../../core/blitzkit/nonBlockingPromises';
import { UserError } from '../../core/blitzkit/userError';
import { filterStats, StatFilters } from '../../core/blitzstars/filterStats';
import { getStatsInPeriod } from '../../core/blitzstars/getStatsInPeriod';
import { blitzStarsTankAverages } from '../../core/blitzstars/tankAverages';
import { ResolvedPeriod } from '../../core/discord/resolvePeriodFromCommand';
import { ResolvedPlayer } from '../../core/discord/resolvePlayerFromCommand';
import { translator } from '../../core/localization/translator';
} from "@blitzkit/core";
import { literals } from "@blitzkit/i18n";
import { Locale } from "discord.js";
import { chunk } from "lodash-es";
import * as Breakdown from "../../components/Breakdown";
import { CommandWrapper } from "../../components/CommandWrapper";
import { NoData } from "../../components/NoData";
import { TitleBar } from "../../components/TitleBar";
import { filtersToDescription } from "../../core/blitzkit/filtersToDescription";
import { tankDefinitions } from "../../core/blitzkit/nonBlockingPromises";
import { UserError } from "../../core/blitzkit/userError";
import { filterStats, StatFilters } from "../../core/blitzstars/filterStats";
import { getStatsInPeriod } from "../../core/blitzstars/getStatsInPeriod";
import { blitzStarsTankAverages } from "../../core/blitzstars/tankAverages";
import { ResolvedPeriod } from "../../core/discord/resolvePeriodFromCommand";
import { ResolvedPlayer } from "../../core/discord/resolvePlayerFromCommand";
import { translator } from "../../core/localization/translator";
const ROWS_PER_PAGE = 8;
const MAX_PAGES = 9;
@@ -31,7 +31,7 @@ export async function renderBreakdown(
{ region, id }: ResolvedPlayer,
{ start, end, name }: ResolvedPeriod,
filters: StatFilters,
locale: Locale,
locale: Locale
) {
const { strings, unwrap } = translator(locale);
const awaitedTankDefinitions = await tankDefinitions;
@@ -39,7 +39,7 @@ export async function renderBreakdown(
const statsInPeriod = await getStatsInPeriod(region, id, start, end, locale);
const { filteredOrder } = await filterStats(statsInPeriod, filters);
const accountInfo = await getAccountInfo(region, id);
const clanData = await getClanAccountInfo(region, id, ['clan']);
const clanData = await getClanAccountInfo(region, id, ["clan"]);
const tankStats = await getTankStats(region, id);
const filterDescriptions = await filtersToDescription(filters, locale);
const orderedCurrentStats: BlitzStats[] = [];
@@ -74,63 +74,63 @@ export async function renderBreakdown(
orderedCareerWN8Full.push(
tankAveragesEntry
? calculateWN8(tankAveragesEntry.all, tank.all)
: undefined,
: undefined
);
});
const currentBattles = orderedCurrentStats.reduce(
(accumulator, current) => accumulator + current.battles,
0,
0
);
const careerBattles = tankStats.reduce(
(accumulator, current) => accumulator + current.all.battles,
0,
0
);
const currentWinrate =
orderedCurrentStats.reduce(
(accumulator, current) => accumulator + current.wins,
0,
0
) / currentBattles;
const careerWinrate =
tankStats.reduce(
(accumulator, current) => accumulator + current.all.wins,
0,
0
) / careerBattles;
const currentWN8 =
orderedCurrentWN8.reduce<number>(
(accumulator, current, index) =>
accumulator + (current ?? 0) * orderedCurrentStats[index].battles,
0,
0
) /
orderedCurrentStats.reduce(
(accumulator, current, index) =>
accumulator +
(orderedCurrentWN8[index] === undefined ? 0 : current.battles),
0,
0
);
const careerWN8 =
orderedCareerWN8Full.reduce<number>(
(accumulator, current) => accumulator + (current ?? 0),
0,
0
) /
tankStats.reduce(
(accumulator, current, index) =>
accumulator +
(orderedCareerWN8Full[index] === undefined ? 0 : current.all.battles),
0,
0
);
const currentDamage =
orderedCurrentStats.reduce(
(accumulator, current) => accumulator + current.damage_dealt,
0,
0
) / currentBattles;
const careerDamage =
tankStats.reduce(
(accumulator, current) => accumulator + current.all.damage_dealt,
0,
0
) / careerBattles;
const children: JSX.Element[] = [];
const children: React.JSX.Element[] = [];
if (filteredOrder.length > 0) {
children.push(
@@ -172,7 +172,7 @@ export async function renderBreakdown(
delta: currentDamage - careerDamage,
},
]}
/>,
/>
);
filteredOrder.forEach((id, index) => {
@@ -206,7 +206,7 @@ export async function renderBreakdown(
{
title: strings.bot.commands.breakdown.body.winrate,
current: `${(100 * (current.wins / current.battles)).toFixed(
2,
2
)}%`,
career: `${(100 * (career.wins / career.battles)).toFixed(2)}%`,
delta:
@@ -230,24 +230,24 @@ export async function renderBreakdown(
{
title: strings.bot.commands.breakdown.body.damage,
current: Math.round(
current.damage_dealt / current.battles,
current.damage_dealt / current.battles
).toLocaleString(),
career: Math.round(
career.damage_dealt / career.battles,
career.damage_dealt / career.battles
).toLocaleString(),
delta:
current.damage_dealt / current.battles -
career.damage_dealt / career.battles,
},
]}
/>,
/>
);
});
}
const pages = chunk(
children,
Math.max(Math.ceil(children.length / MAX_PAGES), ROWS_PER_PAGE),
Math.max(Math.ceil(children.length / MAX_PAGES), ROWS_PER_PAGE)
);
if (filteredOrder.length > 0) {
+3 -3
View File
@@ -1,7 +1,7 @@
import { jsxToSvg } from './jsxToSvg';
import { svgToPng } from './svgToPng';
import { jsxToSvg } from "./jsxToSvg";
import { svgToPng } from "./svgToPng";
export async function jsxToPng(jsx: JSX.Element) {
export async function jsxToPng(jsx: React.JSX.Element) {
const svg = await jsxToSvg(jsx);
const png = svgToPng(svg);
@@ -1,10 +1,10 @@
import { jsxToSvg } from './jsxToSvg';
import { RenderConfiguration } from './renderConfiguration';
import { svgToPngThreaded } from './svgToPngThreaded';
import { jsxToSvg } from "./jsxToSvg";
import { RenderConfiguration } from "./renderConfiguration";
import { svgToPngThreaded } from "./svgToPngThreaded";
export async function jsxToPngThreaded(
jsx: JSX.Element,
renderConfiguration: RenderConfiguration,
jsx: React.JSX.Element,
renderConfiguration: RenderConfiguration
) {
const svg = await jsxToSvg(jsx, renderConfiguration);
const png = await svgToPngThreaded(svg);
@@ -1,9 +1,9 @@
import { readFile } from 'fs/promises';
import satori from 'satori';
import { RenderConfiguration } from '../renderConfiguration';
import robotoBlack from './Roboto-Black.ttf';
import robotoBold from './Roboto-Bold.ttf';
import roboto from './Roboto.ttf';
import { readFile } from "fs/promises";
import satori from "satori";
import { RenderConfiguration } from "../renderConfiguration";
import robotoBlack from "./Roboto-Black.ttf";
import robotoBold from "./Roboto-Bold.ttf";
import roboto from "./Roboto.ttf";
const fontsPromise = [
{ file: roboto, weight: 400 as const },
@@ -11,12 +11,12 @@ const fontsPromise = [
{ file: robotoBlack, weight: 900 as const },
].map(async ({ file, weight }) => {
const data = await readFile(`${__dirname}/${file}`);
return { name: 'Roboto', weight, data };
return { name: "Roboto", weight, data };
});
export async function jsxToSvg(
jsx: JSX.Element,
renderConfiguration = new RenderConfiguration(),
jsx: React.JSX.Element,
renderConfiguration = new RenderConfiguration()
) {
const fonts = await Promise.all(fontsPromise);
return await satori(jsx, { width: renderConfiguration.width, fonts });
@@ -6,14 +6,14 @@ import {
InteractionEditReplyOptions,
InteractionReplyOptions,
MessageEditOptions,
} from 'discord.js';
import { InteractionReturnable } from '../../events/interactionCreate';
import { Writeable } from '../../types/writable';
import { jsxToPngThreaded } from '../blitzkit/jsxToPngThreaded';
import { RenderConfiguration } from '../blitzkit/renderConfiguration';
} from "discord.js";
import { InteractionReturnable } from "../../events/interactionCreate";
import { Writeable } from "../../types/writable";
import { jsxToPngThreaded } from "../blitzkit/jsxToPngThreaded";
import { RenderConfiguration } from "../blitzkit/renderConfiguration";
export async function normalizeInteractionReturnable(
returnable: InteractionReturnable,
returnable: InteractionReturnable
) {
const images: [number, Buffer][] = [];
const reply: InteractionEditReplyOptions &
@@ -27,7 +27,7 @@ export async function normalizeInteractionReturnable(
await Promise.all(
normalizedReturnable.map(async (item, index) => {
if (typeof item === 'string') {
if (typeof item === "string") {
reply.content = item;
} else if (item instanceof EmbedBuilder) {
if (!reply.embeds) reply.embeds = [];
@@ -36,7 +36,7 @@ export async function normalizeInteractionReturnable(
if (!reply.components)
reply.components = [new ActionRowBuilder<ButtonBuilder>()];
(reply.components[0] as ActionRowBuilder<ButtonBuilder>).addComponents(
item,
item
);
} else if (item instanceof AttachmentBuilder) {
if (!reply.files) reply.files = [];
@@ -49,14 +49,14 @@ export async function normalizeInteractionReturnable(
const image = await jsxToPngThreaded(item, renderConfiguration);
images.push([index, image]);
}
}),
})
);
if (images.length > 0) {
images.sort(([a], [b]) => b - a);
if (!reply.files) reply.files = [];
images.forEach(([, image]) =>
(reply.files as Writeable<typeof reply.files>)?.push(image),
(reply.files as Writeable<typeof reply.files>)?.push(image)
);
}
@@ -1,7 +1,7 @@
import { DEFAULT_LOCALE, SupportedLocale } from '@blitzkit/i18n';
import { Locale } from 'discord.js';
import locales from "@blitzkit/i18n/locales.json";
import { Locale } from "discord.js";
const SUPPORTED_LOCALES_DISCORD_MAP: Record<SupportedLocale, Locale> = {
const SUPPORTED_LOCALES_DISCORD_MAP: Record<string, Locale> = {
en: Locale.EnglishUS,
es: Locale.SpanishES,
pt: Locale.PortugueseBR,
@@ -14,12 +14,12 @@ const SUPPORTED_LOCALES_DISCORD_MAP: Record<SupportedLocale, Locale> = {
};
export const SUPPORTED_LOCALES_DISCORD_MAP_INVERSE = Object.fromEntries(
Object.entries(SUPPORTED_LOCALES_DISCORD_MAP).map(([k, v]) => [v, k]),
) as Record<Locale, SupportedLocale>;
Object.entries(SUPPORTED_LOCALES_DISCORD_MAP).map(([k, v]) => [v, k])
) as Record<Locale, string>;
export const SUPPORTED_LOCALES_DISCORD = Object.values(
SUPPORTED_LOCALES_DISCORD_MAP,
SUPPORTED_LOCALES_DISCORD_MAP
);
export const DEFAULT_LOCALE_DISCORD =
SUPPORTED_LOCALES_DISCORD_MAP[DEFAULT_LOCALE];
SUPPORTED_LOCALES_DISCORD_MAP[locales.default];
@@ -1,4 +1,4 @@
import { assertSecret } from '@blitzkit/core';
import { assertSecret } from "@blitzkit/core";
import {
AttachmentBuilder,
AutocompleteInteraction,
@@ -13,30 +13,30 @@ import {
SlashCommandBuilder,
SlashCommandOptionsOnlyBuilder,
SlashCommandSubcommandsOnlyBuilder,
} from 'discord.js';
import { aboutCommand } from '../../commands/about';
import { breakdownCommand } from '../../commands/breakdown';
import { debugCommand } from '../../commands/debug';
import { evolutionCommand } from '../../commands/evolution';
import { fullStatsCommand } from '../../commands/fullStats';
import { inactiveCommand } from '../../commands/inactive';
import { verifyCommand } from '../../commands/link';
import { ownedTanksCommand } from '../../commands/ownedTanks';
import { permissionsCommand } from '../../commands/permissions';
import { pingCommand } from '../../commands/ping';
import { playerInfoCommand } from '../../commands/playerInfo';
import { ratingCommand } from '../../commands/rating';
import { ratingLeaderboardCommand } from '../../commands/ratingLeaderboard';
import { replayCommand } from '../../commands/replay';
import { researchCommand } from '../../commands/research';
import { searchClansCommand } from '../../commands/searchClans';
import { searchPlayersCommand } from '../../commands/searchPlayers';
import { statsCommand } from '../../commands/stats';
import { todayCommand } from '../../commands/today';
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
import { handleAutocomplete } from './handlers/autocomplete';
import { handleButton } from './handlers/button';
import { handleChatInputCommand } from './handlers/chatInputCommand';
} from "discord.js";
import { aboutCommand } from "../../commands/about";
import { breakdownCommand } from "../../commands/breakdown";
import { debugCommand } from "../../commands/debug";
import { evolutionCommand } from "../../commands/evolution";
import { fullStatsCommand } from "../../commands/fullStats";
import { inactiveCommand } from "../../commands/inactive";
import { verifyCommand } from "../../commands/link";
import { ownedTanksCommand } from "../../commands/ownedTanks";
import { permissionsCommand } from "../../commands/permissions";
import { pingCommand } from "../../commands/ping";
import { playerInfoCommand } from "../../commands/playerInfo";
import { ratingCommand } from "../../commands/rating";
import { ratingLeaderboardCommand } from "../../commands/ratingLeaderboard";
import { replayCommand } from "../../commands/replay";
import { researchCommand } from "../../commands/research";
import { searchClansCommand } from "../../commands/searchClans";
import { searchPlayersCommand } from "../../commands/searchPlayers";
import { statsCommand } from "../../commands/stats";
import { todayCommand } from "../../commands/today";
import { RenderConfiguration } from "../../core/blitzkit/renderConfiguration";
import { handleAutocomplete } from "./handlers/autocomplete";
import { handleButton } from "./handlers/button";
import { handleChatInputCommand } from "./handlers/chatInputCommand";
export type InteractionRawReturnable =
| string
@@ -44,7 +44,7 @@ export type InteractionRawReturnable =
| ButtonBuilder
| AttachmentBuilder
| RenderConfiguration
| JSX.Element
| React.JSX.Element
| null;
export type InteractionIterableReturnable =
| InteractionRawReturnable
@@ -58,7 +58,7 @@ interface CommandRegistryBase {
| SlashCommandBuilder
| SlashCommandSubcommandsOnlyBuilder
| SlashCommandOptionsOnlyBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
| Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
@@ -72,7 +72,7 @@ interface CommandRegistryImplicit extends CommandRegistryBase {
interface CommandRegistryExplicit extends CommandRegistryBase {
handlesInteraction?: false;
handler: (
interaction: ChatInputCommandInteraction<CacheType>,
interaction: ChatInputCommandInteraction<CacheType>
) => InteractionReturnable;
}
@@ -104,16 +104,16 @@ export const COMMANDS_RAW: Promise<CommandRegistry>[] = [
export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
return rawCommands.reduce<Record<string, CommandRegistry>>(
(commands, registry, index) => {
if (registry.status === 'rejected') {
if (registry.status === "rejected") {
console.warn(
`Command ${index} failed to load; skipping...`,
registry.reason,
registry.reason
);
return commands;
}
return { ...commands, [registry.value.command.name]: registry.value };
},
{},
{}
);
});
@@ -121,12 +121,12 @@ const rest = new REST().setToken(assertSecret(import.meta.env.DISCORD_TOKEN));
commands.then((awaitedCommands) => {
const body = Object.values(awaitedCommands).map((registry) =>
registry.command.toJSON(),
registry.command.toJSON()
);
rest.put(
Routes.applicationCommands(assertSecret(import.meta.env.DISCORD_CLIENT_ID)),
{ body },
{ body }
);
});
+9
View File
@@ -837,6 +837,15 @@
},
"home": {
"pwa": {
"title": "Install the BlitzKit App",
"new": "NEW",
"checking": "Checking compatibility...",
"instructions": "Instructions for Apple devices.",
"install": "Install",
"dismiss": "Dismiss"
},
"discord": {
"join_short": "Join cool people!",
"join_long": "Join super duper cool people!",
+1 -1
View File
@@ -815,7 +815,7 @@
"no_ricochet": "Разрывные снаряды не рикошетят"
},
"view_range": {
"camo": "Камо",
"camo": "Камуфляж",
"percentage": "%s1%",
"ghost_factory": "Промзона",
"dead_rail": "Эшелон"
File diff suppressed because it is too large. Load diff
+12 -15
View File
@@ -1,29 +1,26 @@
import {
DEFAULT_LOCALE,
SUPPORTED_LOCALES,
TranslationTree,
} from '@blitzkit/i18n';
import { writeFile } from 'fs/promises';
import { type TranslationTree } from "@blitzkit/i18n";
import locales from "@blitzkit/i18n/locales.json";
import { writeFile } from "fs/promises";
const ROOT = '@blitzkit/i18n/strings';
const WORKING_ROOT = '../../packages/i18n/strings';
const ROOT = "@blitzkit/i18n/strings";
const WORKING_ROOT = "../../packages/i18n/strings";
const defaultStrings = require(`${ROOT}/${DEFAULT_LOCALE}.json`).default;
const nonDefaultLocales = SUPPORTED_LOCALES.filter(
(locale) => locale !== DEFAULT_LOCALE,
const defaultStrings = require(`${ROOT}/${locales.default}.json`).default;
const nonDefaultLocales = locales.supported.filter(
({ locale }) => locale !== locales.default
);
function prune(defaultStrings: TranslationTree, strings: TranslationTree) {
for (const key in strings) {
if (key in defaultStrings) {
if (typeof defaultStrings[key] === typeof strings[key]) {
if (typeof strings[key] === 'string') {
if (typeof strings[key] === "string") {
if (
// are equivalent regardless of %s flavor
(defaultStrings[key] as string).replaceAll(/%s\d/g, '%s') ===
(strings[key] as string).replaceAll(/%s\d/g, '%s') ||
(defaultStrings[key] as string).replaceAll(/%s\d/g, "%s") ===
(strings[key] as string).replaceAll(/%s\d/g, "%s") ||
// string is empty
strings[key] === '' ||
strings[key] === "" ||
// string has old flavor of %s
strings[key].match(/%s([^\d]|$)/g) !== null
) {
+9 -8
View File
@@ -1,5 +1,5 @@
import { produce } from "immer";
import { merge } from "lodash-es";
import { debounce, merge } from "lodash-es";
import { useEffect, useRef, useState } from "react";
export class Varuna<Type, Arguments = void> {
@@ -20,7 +20,6 @@ export class Varuna<Type, Arguments = void> {
let data = initial;
if (this.persistence && typeof localStorage !== "undefined") {
const instance = this;
const dehydrated = localStorage.getItem(this.persistence);
if (dehydrated) {
@@ -28,9 +27,7 @@ export class Varuna<Type, Arguments = void> {
data = merge(data, rehydrated);
}
window.addEventListener("beforeunload", () => {
localStorage.setItem(this.persistence!, JSON.stringify(instance.state));
});
window.addEventListener("beforeunload", this.store.bind(this));
}
this.initialized = true;
@@ -39,8 +36,6 @@ export class Varuna<Type, Arguments = void> {
}
useInitialization(...args: Arguments[]) {
if (this.initialized) return;
const initializedThisMount = useRef(false);
if (initializedThisMount.current) return;
@@ -55,7 +50,6 @@ export class Varuna<Type, Arguments = void> {
private dispatch() {
const state = this.state;
console.log("dispatched");
this.listeners.forEach((callback) => callback(state));
}
@@ -97,6 +91,7 @@ export class Varuna<Type, Arguments = void> {
this.assertInitialized();
this._state = state;
this.dispatch();
this.storeDeferred();
}
get initial() {
@@ -118,4 +113,10 @@ export class Varuna<Type, Arguments = void> {
return slice;
}
store() {
localStorage.setItem(this.persistence!, JSON.stringify(this.state));
}
storeDeferred = debounce(this.store.bind(this), 500);
}
+26 -1
View File
@@ -12,6 +12,17 @@ import { tools } from "./src/constants/tools";
export default defineConfig({
devToolbar: { enabled: false },
vite: { server: { allowedHosts: [] } },
output: "static",
site: "https://blitzkit.app",
outDir: "../../dist/website",
prefetch: {
defaultStrategy: "hover",
prefetchAll: true,
},
build: { concurrency: 4 },
integrations: [
favicons({
name: strings.common.name,
@@ -43,6 +54,7 @@ export default defineConfig({
(strings) => strings.website.tools[stringId].name
),
url: `/${tool.id}`,
icon: `public/assets/images/tools/${tool.id}.webp`,
};
}),
@@ -75,7 +87,20 @@ export default defineConfig({
},
}),
AstroPWA({ manifest: false }),
AstroPWA({
manifest: false,
devOptions: { enabled: true },
workbox: {
globPatterns: ["**/*.{html,css,js,png,webp,svg,xml,json}"],
runtimeCaching: [
{
urlPattern: ({ url }) =>
url.href.startsWith(import.meta.env.PUBLIC_ASSET_BASE),
handler: "NetworkFirst",
},
],
},
}),
react(),
],
+14 -1
View File
@@ -9,16 +9,29 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/react": "^4.4.0",
"@astrolib/seo": "^1.0.0-beta.8",
"@fontsource/inter": "^5.2.8",
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-icons": "^1.3.2",
"@radix-ui/themes": "^3.2.1",
"@react-three/drei": "^10.7.6",
"@react-three/fiber": "^9.3.0",
"@types/react": "^19.1.14",
"@types/react-dom": "^19.1.9",
"@vite-pwa/astro": "^1.1.0",
"astro": "^5.14.1",
"astro-favicons": "^3.1.5",
"compare-versions": "^6.1.1",
"fuzzysort": "^3.1.0",
"immer": "^10.1.3",
"markdown-to-jsx": "^7.7.13",
"pwa-install-handler": "^2.6.3",
"react": "^19.1.1",
"react-dom": "^19.1.1"
"react-dom": "^19.1.1",
"react-promise-suspense": "^0.3.4",
"typescript": "^5.9.2",
"urlon": "^3.1.0"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

@@ -1,5 +1,5 @@
import { Theme, type ThemeProps } from '@radix-ui/themes';
import type { ReactNode } from 'react';
import { Theme, type ThemeProps } from "@radix-ui/themes";
import type { ReactNode } from "react";
interface BlitzKitThemeProps extends ThemeProps {
children: ReactNode;
@@ -13,13 +13,13 @@ export function BlitzKitTheme({
}: BlitzKitThemeProps) {
return (
<Theme
style={{ minHeight: 'unset', display: 'contents', ...style }}
style={{ minHeight: "unset", display: "contents", ...style }}
className={`blitzkit-theme ${className}`}
grayColor="mauve"
appearance="dark"
panelBackground="solid"
radius="full"
accentColor="amber"
accentColor="indigo"
suppressHydrationWarning
suppressContentEditableWarning
{...props}
+37
View File
@@ -0,0 +1,37 @@
---
import { pwaInfo } from "virtual:pwa-info";
---
<script>
import { pwaInstallHandler } from "pwa-install-handler";
import { registerSW } from "virtual:pwa-register";
registerSW({
immediate: true,
onRegisterError: console.error,
onRegisteredSW() {
console.log("PWA registered service worker");
},
onOfflineReady() {
console.log("PWA offline ready");
},
onNeedRefresh() {
document.documentElement.classList.add("pwa-refresh");
},
});
pwaInstallHandler.addListener((canInstall) => {
document.documentElement.classList.remove(
canInstall ? "pwa-disabled" : "pwa-enabled"
);
document.documentElement.classList.add(
canInstall ? "pwa-enabled" : "pwa-disabled"
);
});
</script>
{pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />}
@@ -0,0 +1,136 @@
---
import { Cross2Icon, DownloadIcon } from "@radix-ui/react-icons";
import {
Badge,
Box,
Button,
Card,
Flex,
Inset,
Link,
Spinner,
Text,
} from "@radix-ui/themes";
import { getStrings } from "../core/i18n/getStrings";
import type { LocaleAcceptorProps } from "../hooks/useLocale";
type Props = LocaleAcceptorProps & {
floating?: boolean;
};
const { locale, floating } = Astro.props;
const strings = getStrings(locale);
---
<style>
#pwa-prompter[data-floating="true"] {
position: fixed;
bottom: var(--space-6);
right: var(--space-6);
z-index: 1;
}
#pwa-prompter[data-floating="true"] .card {
box-shadow: var(--shadow-6);
}
.pwa-logo {
width: 6rem;
height: 6rem;
background-image: url(/assets/images/pwa-promo.png);
background-position: center;
background-size: cover;
}
html.pwa-enabled .compatibility-checker,
html.pwa-disabled .compatibility-checker {
display: none;
}
#pwa-install,
#pwa-incompatible,
#pwa-prompter[data-floating="true"],
#pwa-dismiss {
display: none;
}
html.pwa-enabled #pwa-install,
html.pwa-disabled #pwa-incompatible,
html.pwa-enabled #pwa-prompter[data-floating="true"],
#pwa-prompter[data-floating="true"] #pwa-dismiss {
display: unset;
}
.pwa-actions button {
flex: 1;
}
</style>
<script>
import { pwaInstallHandler } from "pwa-install-handler";
const pwaInstallButton = document.getElementById("pwa-install");
const pwaDismissButton = document.getElementById("pwa-dismiss");
const pwaPrompter = document.getElementById("pwa-prompter");
pwaInstallButton?.addEventListener("click", () => {
pwaInstallHandler.install();
});
pwaDismissButton?.addEventListener("click", () => {
pwaPrompter?.remove();
});
</script>
<Flex id="pwa-prompter" justify="center" mt="4" data-floating={floating}>
<Card variant="classic" className="card">
<Inset>
<Flex align="center">
<Box className="pwa-logo" />
<Flex direction="column" gap="2" px="4" py="3">
<Flex align="center" gap="2">
<Text size="4" weight="medium">
{strings.website.home.pwa.title}
</Text>
<Badge color="jade" variant="outline">
{strings.website.home.pwa.new}
</Badge>
</Flex>
<Flex className="compatibility-checker" align="center" gap="2">
<Spinner />
<Text color="gray">
{strings.website.home.pwa.checking}
</Text>
</Flex>
<Link
id="pwa-incompatible"
trim="end"
underline="always"
target="_blank"
href="https://www.cdc.gov/niosh/mining/tools/installpwa.html"
>
{strings.website.home.pwa.instructions}
</Link>
<Flex className="pwa-actions" gap="2">
<Button id="pwa-dismiss" color="tomato" variant="outline">
<Flex align="center" gap="1" justify="center">
<Cross2Icon />
{strings.website.home.pwa.dismiss}
</Flex>
</Button>
<Button id="pwa-install" color="jade">
<Flex align="center" gap="1" justify="center">
<DownloadIcon />
{strings.website.home.pwa.install}
</Flex>
</Button>
</Flex>
</Flex>
</Flex>
</Inset>
</Card>
</Flex>
@@ -1,7 +1,7 @@
import { CaretRightIcon } from '@radix-ui/react-icons';
import { Box, Flex, Link, Text } from '@radix-ui/themes';
import { Var } from '../../../core/radix/var';
import type { TankGuide } from '../../../pages/[...locale]/tanks/[slug]/index.astro';
import { CaretRightIcon } from "@radix-ui/react-icons";
import { Box, Flex, Link, Text } from "@radix-ui/themes";
import { Var } from "../../../core/radix/var";
import type { TankGuide } from "../../../pages/[...locale]/tanks/[slug]/index.astro";
interface Props {
guide: TankGuide;
@@ -16,10 +16,10 @@ export function GuideSection({ guide }: Props) {
underline="none"
highContrast
style={{
display: 'flex',
maxWidth: '35rem',
flexDirection: 'column',
gap: Var('space-4'),
display: "flex",
maxWidth: "35rem",
flexDirection: "column",
gap: Var("space-4"),
}}
>
<Flex maxWidth="35rem" direction="column" gap="4">
@@ -28,9 +28,9 @@ export function GuideSection({ guide }: Props) {
<Flex width="100%" justify="start" align="center" gap="2">
<img
style={{
width: '1.5em',
height: '1.5em',
objectFit: 'contain',
width: "1.5em",
height: "1.5em",
objectFit: "contain",
}}
src="https://guidesblitz.com/wp-content/uploads/2023/11/cropped-logo-1.png"
/>
@@ -39,7 +39,7 @@ export function GuideSection({ guide }: Props) {
</Text>
<Text size="2">{guide.description}</Text>
<img style={{ width: '100%' }} src={guide.image} />
<img style={{ width: "100%" }} src={guide.image} />
<Box
position="absolute"
@@ -48,7 +48,7 @@ export function GuideSection({ guide }: Props) {
height="100%"
left="0"
style={{
background: `linear-gradient(${Var('gray-a1')}, ${Var('gray-1')})`,
background: `linear-gradient(${Var("gray-a1")}, ${Var("gray-1")})`,
}}
/>
</Flex>
@@ -5,6 +5,7 @@ import { useRef, useState } from "react";
import { Color, SpotLight, SpotLightHelper } from "three";
import { degToRad } from "three/src/math/MathUtils.js";
import { isHalloween } from "../../../../../../core/blitzkit/isHalloween";
import { Tankopedia } from "../../../../../../stores/tankopedia";
import { HelpingSpotLight } from "../../../../../HelpingSpotLight";
const LIGHTS_COUNT = 5;
@@ -18,6 +19,7 @@ const TARGET_FRAME_RATE = 30;
export function Lighting() {
const [cast, setCast] = useState(true);
const revealed = Tankopedia.use((state) => state.revealed);
const topLight = useRef<SpotLight>(null!);
const frontLight = useRef<SpotLight>(null!);
@@ -29,7 +31,7 @@ export function Lighting() {
const samples = useRef<number[]>([]);
useFrame(({ clock }) => {
if (!cast) return;
if (!cast || !revealed) return;
const dt = clock.elapsedTime - last.current;
last.current = clock.elapsedTime;
@@ -140,7 +140,9 @@ export function HeroSection({ skeleton }: MaybeSkeletonComponentProps) {
}}
>
<Suspense>
<TankSandbox ref={canvas} thicknessRange={thicknessRange} />
{!skeleton && (
<TankSandbox ref={canvas} thicknessRange={thicknessRange} />
)}
</Suspense>
</Box>
</Box>
@@ -1,8 +1,8 @@
import { getAccountInfo, idToRegion } from '@blitzkit/core';
import { Text } from '@radix-ui/themes';
import { useMemo } from 'react';
import usePromise from 'react-promise-suspense';
import { App } from '../stores/app';
import { getAccountInfo, idToRegion } from "@blitzkit/core";
import { Text } from "@radix-ui/themes";
import { useMemo } from "react";
import usePromise from "react-promise-suspense";
import { App } from "../stores/app";
export function WargamingAccountName() {
const wargaming = App.use((state) => state.logins.wargaming);
@@ -13,7 +13,7 @@ export function WargamingAccountName() {
idToRegion(wargaming.id),
wargaming.id,
[],
{ access_token: wargaming.token },
{ access_token: wargaming.token }
);
return data?.nickname as string | undefined;
Whitespace-only changes.
@@ -1,10 +0,0 @@
import { type StoreKeys } from '@nanostores/react';
import type { Store } from 'nanostores';
import { useStoreKey } from './useStoreKey';
export function useStoreBoolean<Type>(
store: Store<Type>,
key: StoreKeys<Store<Type>>,
) {
return Boolean(useStoreKey(store, key));
}
-10
View File
@@ -1,10 +0,0 @@
import { useStore, type StoreKeys } from '@nanostores/react';
import type { Store } from 'nanostores';
export function useStoreKey<Type, Key extends StoreKeys<Store<Type>>>(
store: Store<Type>,
key: Key,
) {
const state = useStore(store, { keys: [key] });
return state[key];
}
@@ -10,6 +10,7 @@ import LocaleRedirector from "../components/LocaleRedirector.astro";
import Meta from "../components/Meta.astro";
import Navbar from "../components/Navbar.astro";
import PWA from "../components/PWA.astro";
import PWAPrompter from "../components/PWAPrompter.astro";
import Servicing from "../components/Servicing.astro";
import "./base.css";
@@ -38,6 +39,12 @@ const locale = Astro.params.locale;
<body class={noNavbar ? "no-navbar" : ""}>
<BlitzKitTheme>
{
Astro.routePattern !== "/[...locale]" && (
<PWAPrompter {locale} floating />
)
}
<Flex direction="column" minHeight="100vh">
<Navbar {integrated} />
@@ -4,6 +4,7 @@ import { GuessBackground } from "../../../components/GuessBackground";
import { Guesser } from "../../../components/Guesser";
import { GuessRenderer } from "../../../components/GuessRenderer";
import { GuessRendererLoader } from "../../../components/GuessRendererLoader";
import { PageWrapper } from "../../../components/PageWrapper";
import { awaitableModelDefinitions } from "../../../core/awaitables/modelDefinitions";
import { awaitableTankDefinitions } from "../../../core/awaitables/tankDefinitions";
import {
@@ -14,6 +15,7 @@ import {
import { Duel } from "../../../stores/duel";
import { Guess, GuessState } from "../../../stores/guess";
import { Tankopedia } from "../../../stores/tankopedia";
import type { MaybeSkeletonComponentProps } from "../../../types/maybeSkeletonComponentProps";
const [tankDefinitions, modelDefinitions] = await Promise.all([
awaitableTankDefinitions,
@@ -22,7 +24,10 @@ const [tankDefinitions, modelDefinitions] = await Promise.all([
const ids = Object.keys(tankDefinitions.tanks);
export function Page({ locale }: LocaleAcceptorProps) {
export function Page({
locale,
skeleton,
}: LocaleAcceptorProps & MaybeSkeletonComponentProps) {
const id = Number(ids[Math.floor(Math.random() * ids.length)]);
const tank = tankDefinitions.tanks[id];
@@ -30,22 +35,26 @@ export function Page({ locale }: LocaleAcceptorProps) {
return (
<LocaleProvider locale={locale}>
<Container />
<Container skeleton={skeleton} />
</LocaleProvider>
);
}
function Container() {
function Container({ skeleton }: MaybeSkeletonComponentProps) {
const tank = Guess.use((state) => state.tank);
const model = modelDefinitions.models[tank.id];
Tankopedia.useInitialization(model);
Duel.useInitialization({ tank, model });
return <Content />;
return (
<PageWrapper p="0" maxWidth="unset" color="cyan">
<Content skeleton={skeleton} />
</PageWrapper>
);
}
function Content() {
function Content({ skeleton }: MaybeSkeletonComponentProps) {
const { unwrap } = useLocale();
const tank = Guess.use((state) => state.tank);
const guessState = Guess.use((state) => state.guessState);
@@ -85,7 +94,7 @@ function Content() {
style={{ transitionDuration }}
>
<Suspense fallback={<GuessRendererLoader />}>
<GuessRenderer />
{!skeleton && <GuessRenderer />}
</Suspense>
</Box>
@@ -1,15 +1,14 @@
---
import { PageWrapper } from '../../../components/PageWrapper';
import BaseLayout from '../../../layouts/BaseLayout.astro';
import { Page } from './_index';
import BaseLayout from "../../../layouts/BaseLayout.astro";
import { Page } from "./_index";
export { getStaticPaths } from '../index.astro';
export { getStaticPaths } from "../index.astro";
const { locale } = Astro.params;
---
<BaseLayout noFooter>
<PageWrapper p="0" maxWidth="unset" color="cyan">
<Page {locale} client:load />
</PageWrapper>
<Page {locale} client:only="react">
<Page {locale} skeleton slot="fallback" />
</Page>
</BaseLayout>
@@ -8,6 +8,7 @@ import type { GetStaticPaths } from "astro";
import { AesonPlug } from "../../components/AesonPlug";
import HomeHero from "../../components/HomeHero.astro";
import { Plugs } from "../../components/Plugs";
import PWAPrompter from "../../components/PWAPrompter.astro";
import ToolCard from "../../components/ToolCard.astro";
import { tools, type Tool } from "../../constants/tools";
import { getStrings } from "../../core/i18n/getStrings";
@@ -64,6 +65,8 @@ export const getStaticPaths = (() => {
<BaseLayout>
<HomeHero />
<PWAPrompter {locale} />
<!-- <Flex justify="center" py="6" px="4" justify="center">
<Flex
wrap="wrap"
+5 -1
View File
@@ -3,6 +3,10 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react",
"types": ["vite/client"]
"types": [
"vite/client",
"vite-plugin-pwa/info.d.ts",
"vite-plugin-pwa/client.d.ts"
]
}
}