2024-12-16 12:41:24 -06:00
|
|
|
import { fetchTankDefinitions } from '@blitzkit/core';
|
|
|
|
|
import { exec } from 'child_process';
|
|
|
|
|
import { launch } from 'puppeteer';
|
2024-04-04 11:04:27 -05:00
|
|
|
import sharp from 'sharp';
|
2024-09-07 21:45:00 -05:00
|
|
|
import { commitAssets } from '../core/github/commitAssets';
|
|
|
|
|
import { FileChange } from '../core/github/commitMultipleFiles';
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-08-27 14:40:43 -05:00
|
|
|
export async function tankIcons() {
|
2024-01-07 20:07:45 -06:00
|
|
|
console.log('Building tank icons...');
|
|
|
|
|
|
2024-12-16 12:41:24 -06:00
|
|
|
const websiteProcess = exec('cd ../.. && bun dev:website');
|
|
|
|
|
const browser = await launch();
|
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
const tankDefinitions = await fetchTankDefinitions();
|
|
|
|
|
const tanks = Object.values(tankDefinitions.tanks);
|
|
|
|
|
const files: FileChange[] = [];
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-12-16 12:41:24 -06:00
|
|
|
let index = 0;
|
|
|
|
|
for (const { id, name } of tanks) {
|
|
|
|
|
await page.setViewport({ width: 640 - 1, height: 480 });
|
|
|
|
|
await page.goto(`http://localhost:4321/api/tankopedia/tank-icon/${id}/`, {
|
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
|
});
|
|
|
|
|
const screenshot = await page.screenshot({
|
|
|
|
|
type: 'webp',
|
|
|
|
|
omitBackground: true,
|
|
|
|
|
});
|
|
|
|
|
const content = await sharp(screenshot).trim({ threshold: 100 }).toBuffer();
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-12-16 12:41:24 -06:00
|
|
|
index++;
|
|
|
|
|
console.log(
|
|
|
|
|
`Rendered ${id} (${name}) ${((index / tanks.length) * 100).toFixed(2)}%`,
|
|
|
|
|
);
|
2024-01-20 13:43:03 -06:00
|
|
|
|
2024-12-16 12:41:24 -06:00
|
|
|
files.push({ path: `icons/tanks/blitzkit/${id}.webp`, content });
|
|
|
|
|
}
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-12-16 12:41:24 -06:00
|
|
|
websiteProcess.kill('SIGHUP');
|
|
|
|
|
await browser.close();
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-12-16 12:41:24 -06:00
|
|
|
await commitAssets('tank icons', files);
|
2024-01-07 20:07:45 -06:00
|
|
|
}
|