2024-12-16 22:42:27 -06:00
|
|
|
import { BLITZKIT_TANK_ICON_SIZE, fetchTankDefinitions } from '@blitzkit/core';
|
|
|
|
|
import { launch } from 'puppeteer';
|
|
|
|
|
import sharp from 'sharp';
|
|
|
|
|
import { commitAssets } from '../core/github/commitAssets';
|
|
|
|
|
import { FileChange } from '../core/github/commitMultipleFiles';
|
|
|
|
|
|
|
|
|
|
export async function blitzkitTankIcons() {
|
2024-12-17 21:06:11 -06:00
|
|
|
console.log('Building blitzkit tank icons...');
|
|
|
|
|
|
|
|
|
|
console.log('Starting website dev server...');
|
2024-12-16 22:42:27 -06:00
|
|
|
const browser = await launch();
|
|
|
|
|
const page = await browser.newPage();
|
2024-12-19 11:16:27 -06:00
|
|
|
const tanks = Object.values((await fetchTankDefinitions()).tanks);
|
2024-12-16 22:42:27 -06:00
|
|
|
const files: FileChange[] = [];
|
|
|
|
|
|
|
|
|
|
let index = 0;
|
|
|
|
|
for (const { id, name } of tanks) {
|
|
|
|
|
await page.setViewport({
|
|
|
|
|
width: BLITZKIT_TANK_ICON_SIZE.width - 1,
|
|
|
|
|
height: BLITZKIT_TANK_ICON_SIZE.height,
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`http://localhost:4321/api/tankopedia/tank-icon/${id}/`, {
|
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
|
});
|
2024-12-17 21:06:11 -06:00
|
|
|
|
|
|
|
|
if (index === 0) {
|
|
|
|
|
console.log('Dev server started!');
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-16 22:42:27 -06:00
|
|
|
const screenshot = await page.screenshot({
|
|
|
|
|
type: 'webp',
|
|
|
|
|
omitBackground: true,
|
|
|
|
|
});
|
|
|
|
|
const content = await sharp(screenshot).trim({ threshold: 100 }).toBuffer();
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
console.log(
|
|
|
|
|
`Rendered ${id} (${name}) ${((index / tanks.length) * 100).toFixed(2)}%`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
files.push({ path: `icons/tanks/blitzkit/${id}.webp`, content });
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-19 18:10:00 -06:00
|
|
|
await page.close();
|
2024-12-16 22:42:27 -06:00
|
|
|
await browser.close();
|
|
|
|
|
|
|
|
|
|
await commitAssets('tank icons', files);
|
|
|
|
|
}
|