2023-11-23 08:53:28 +00:00
|
|
|
const data = document.getElementById("data");
|
|
|
|
const generateButton = document.getElementById("generateButton");
|
|
|
|
const hexdisplay = document.getElementById("hexdisplay");
|
|
|
|
|
|
|
|
const steam_game = document.getElementById("steam_game");
|
|
|
|
const scott_index = document.getElementById("scott_index");
|
|
|
|
const stash = document.getElementById("stash");
|
|
|
|
const align = document.getElementById("align");
|
|
|
|
|
|
|
|
const root = document.querySelector(":root");
|
|
|
|
|
|
|
|
async function loadImage(url) {
|
|
|
|
return new Promise((r) => {
|
|
|
|
let img = new Image();
|
|
|
|
img.onload = () => r(img);
|
|
|
|
img.src = url;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-23 17:33:47 +00:00
|
|
|
function initDocument(hx, w, h, t) {
|
2023-11-25 01:53:10 +00:00
|
|
|
console.log(window.parent, window.parent.manager);
|
|
|
|
const newWindow = window.top.manager.createWindow(
|
2023-11-23 17:33:47 +00:00
|
|
|
`<html>
|
|
|
|
<head>
|
|
|
|
<title>Result</title>
|
|
|
|
</head>
|
2023-11-23 23:30:36 +00:00
|
|
|
<body style="display:flex;margin:0;height:100vh;align-items:safe center;justify-content:safe center;">
|
2023-11-23 17:33:47 +00:00
|
|
|
<canvas id="canvas" width="1280" height="720"></canvas>
|
|
|
|
</body>
|
|
|
|
</html>`,
|
2023-11-23 18:08:33 +00:00
|
|
|
true,
|
|
|
|
1280,
|
|
|
|
720
|
2023-11-23 17:33:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
newWindow.windowContent.contentWindow.addEventListener("load", () => {
|
|
|
|
getScott(newWindow.windowContent.contentDocument.querySelector("#canvas"));
|
2023-11-25 01:53:10 +00:00
|
|
|
propagateStyles(getComputedStyle(root), newWindow.windowObject);
|
2023-11-23 17:33:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getScott(canvas) {
|
2023-11-23 08:53:28 +00:00
|
|
|
var gameID = steam_game.value;
|
|
|
|
var scottID = scott_index.value;
|
|
|
|
var alignment = align.value;
|
|
|
|
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
|
|
|
|
var hero = await loadImage(
|
|
|
|
`https://cdn.cloudflare.steamstatic.com/steam/apps/${gameID}/library_hero.jpg`
|
|
|
|
).catch(() => "404");
|
|
|
|
var scott = await loadImage(
|
|
|
|
stash.checked ? `public/wozstash.png` : `public/woz${scottID}.png`
|
|
|
|
).catch(() => "404");
|
|
|
|
var logo = await loadImage(
|
|
|
|
`https://cdn.cloudflare.steamstatic.com/steam/apps/${gameID}/logo.png`
|
|
|
|
).catch(() => "404");
|
|
|
|
|
|
|
|
if (scott === "404") {
|
|
|
|
console.log("Scott error: " + scottID);
|
|
|
|
return `Scott ID ${scottID} does not exist.`;
|
|
|
|
}
|
|
|
|
if (hero === "404" || logo === "404") {
|
|
|
|
console.log("404 error: " + gameID);
|
|
|
|
return `Steam ID ${gameID} does not have logo, hero image, or does not exist.`;
|
|
|
|
}
|
|
|
|
var xalign;
|
|
|
|
switch (alignment) {
|
|
|
|
case "left":
|
|
|
|
xalign = 0;
|
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
xalign = -950;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xalign = -505;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
console.log("Generating: " + gameID);
|
|
|
|
ctx.drawImage(hero, xalign, 0, 2229, 720);
|
|
|
|
ctx.drawImage(scott, 0, 0, 1280, 720);
|
|
|
|
|
|
|
|
const newHeight = 800 / (logo.width / logo.height);
|
|
|
|
ctx.fillStyle = "#000";
|
|
|
|
ctx.shadowColor = "#000";
|
|
|
|
ctx.shadowBlur = 16;
|
|
|
|
|
|
|
|
if (stash.checked)
|
|
|
|
ctx.drawImage(
|
|
|
|
logo,
|
|
|
|
400,
|
|
|
|
Math.min(560 - newHeight / 2, 669 - newHeight),
|
|
|
|
800,
|
|
|
|
newHeight
|
|
|
|
);
|
|
|
|
else
|
|
|
|
ctx.drawImage(logo, 64, Math.max(240 - newHeight / 2, 32), 800, newHeight);
|
|
|
|
}
|
|
|
|
|
2023-11-23 17:33:47 +00:00
|
|
|
generateButton.addEventListener("click", initDocument);
|