-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsave-smite.mjs
More file actions
44 lines (36 loc) · 1.61 KB
/
save-smite.mjs
File metadata and controls
44 lines (36 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const puppeteer = require("/home/ab/.nvm/versions/node/v25.2.1/lib/node_modules/puppeteer");
import fs from "fs";
import path from "path";
const URL = "http://localhost:4444/gen-smite.html";
const OUT = path.resolve("game-sprites/lightning-smite");
if (!fs.existsSync(OUT)) fs.mkdirSync(OUT, { recursive: true });
const browser = await puppeteer.launch({
headless: false,
executablePath: "/home/ab/.cache/puppeteer/chrome/linux-140.0.7339.207/chrome-linux64/chrome",
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-gpu-sandbox",
"--enable-webgl",
"--ignore-gpu-blocklist"
]
});
const page = await browser.newPage();
page.on("console", m => process.stdout.write(`[page] ${m.text()}\n`));
page.on("pageerror", e => process.stderr.write(`[err] ${e}\n`));
console.log("Loading gen-smite.html...");
await page.goto(URL, { waitUntil: "domcontentloaded", timeout: 120000 });
console.log("Waiting for smite frame generation...");
await page.waitForFunction("window.__done === true", { timeout: 300000, polling: 1000 });
const frames = await page.evaluate(() => window.__frames);
console.log(`Got ${frames.length} frames. Saving to ${OUT}...`);
for (let i = 0; i < frames.length; i++) {
const b64 = frames[i].replace(/^data:image\/png;base64,/, "");
const name = String(i).padStart(4, "0") + ".png";
fs.writeFileSync(path.join(OUT, name), Buffer.from(b64, "base64"));
process.stdout.write(` saved ${name}\n`);
}
console.log(`Done! ${frames.length} tall frames (128x512) saved to ${OUT}`);
await browser.close();