diff --git a/assets/communitymaps/None.png b/assets/communitymaps/None.png new file mode 100644 index 0000000..28868ba Binary files /dev/null and b/assets/communitymaps/None.png differ diff --git a/assets/communitymaps/betterplaceholder.txt b/assets/communitymaps/betterplaceholder.txt new file mode 100644 index 0000000..a069e1d --- /dev/null +++ b/assets/communitymaps/betterplaceholder.txt @@ -0,0 +1 @@ +Hahaha of the muhuhu I am the better placeholder TXT file FEAR ME!!!!!!!!!! \ No newline at end of file diff --git a/assets/communityvs/placeholder.txt b/assets/communityvs/placeholder.txt new file mode 100644 index 0000000..12d26fa --- /dev/null +++ b/assets/communityvs/placeholder.txt @@ -0,0 +1 @@ +Yooooooo community opponent VS Screens sheeeeeeeeeeeeeeeeeesh \ No newline at end of file diff --git a/index.ts b/index.ts index 914287a..49796be 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,8 @@ import { GenerateBattleImageOptions, PlayerActionOptions, Opponents, - CustomActionOptions + CustomActionOptions, + CommunityOpponents } from "./types"; import { generateBattler, drawText, applyText, @@ -145,6 +146,13 @@ const opponents = { } } +const communityopponents = { + [CommunityOpponents.Stik]: { + text: "Stik", + colour: ["#FF0000", "#000000"] + } +} + const server = createServer(async (req, res) => { if (req.method === "OPTIONS") { res.setHeader("access-control-allow-origin", "*") @@ -248,6 +256,57 @@ const server = createServer(async (req, res) => { return res.end(canvas.toBuffer("image/png"), 'binary') } + if ( + req.method == "GET" && + url.pathname == "communityvs/.png" + ) { + const opts = Object.fromEntries( + Array.from(url.searchParams.entries()) + .map(([key, value]) => [key, value.replaceAll('+', ' ')]), + ) as GenerateBattlerOptions & GenerateBattleImageOptions; + + if (!opts.opponent) { + res.writeHead(400, { 'content-type': "application/json" }) + return res.end( + JSON.stringify({ + error: '"opponent" query parameter not specified', + }) + ); + } + + console.log(`Generating battle start for ${opts.username} and ${opts.opponent}`) + + // Image dimensions + const canvas = createCanvas(1920, 1080); + const context = canvas.getContext("2d"); + + if (!validOpponents.includes(opts.opponent)) opts.opponent = CommunityOpponents.None + + const SquadBackground = await loadImage( + `./assets/communityvs/${opts.opponent}.png`, + ); + + context.drawImage(SquadBackground, 0, 0, canvas.width, canvas.height); + + const battler = await generateBattler(opts); + + context.drawImage(battler, -140, -100, battler.width, battler.height); + + context.textAlign = "center" + + context.font = applyText(canvas, opponents[opts.opponent].text, 875) + + drawText([1450, 1000], opponents[opts.opponent].text, opponents[opts.opponent].colour[1], { colour: opponents[opts.opponent].colour[0], width: 20 }, context); + + context.font = applyText(canvas, opts.username, 675) + + drawText([470, 1000], opts.username, opts.username == "homeannor" ? "#AA00FF" : "#000000", { colour: "#FFFFFF", width: 20 }, context) + + res.setHeader('content-type', 'image/png'); + + return res.end(canvas.toBuffer("image/png"), 'binary') + } + if ( req.method == "GET" && url.pathname == "/playeraction.png" @@ -464,6 +523,53 @@ const server = createServer(async (req, res) => { return res.end(canvas.toBuffer("image/png"), 'binary') } + if ( + req.method == "GET" && + url.pathname == "/communitymap.png" + ) { + const opts = Object.fromEntries( + Array.from(url.searchParams.entries()) + .map(([key, value]) => [key, value.replaceAll('+', ' ')]), + ) as { player: string, map: string }; + + if (!opts.player || !opts.map) { + res.writeHead(400, { 'content-type': "application/json" }) + return res.end( + JSON.stringify({ + error: + 'Did not pass all parameters', + }) + ); + } + + console.log(`Generating map (${opts.map})`) + + const p1URL = new URL(encodeURI(opts.player)) + + const p1Opts = Object.fromEntries( + Array.from(p1URL.searchParams.entries()) + .map(([key, value]) => [key, value.replaceAll('+', ' ')]), + ) as GenerateBattlerOptions + + const p1 = await generateBattler(p1Opts); + + // Image dimensions + const canvas = createCanvas(1920, 1080); + const context = canvas.getContext("2d"); + + const Background = await loadImage( + `./assets/communitymaps/${opts.map}.png`, + ); + + context.drawImage(Background, 0, 0, canvas.width, canvas.height); + + context.drawImage(p1, 140, 313, p1.width / 2, p1.height / 2); + + res.setHeader('content-type', 'image/png'); + + return res.end(canvas.toBuffer("image/png"), 'binary') + } + if ( req.method == "GET" && url.pathname == "/pvp.png" diff --git a/types.ts b/types.ts index 53c914f..654c62c 100644 --- a/types.ts +++ b/types.ts @@ -129,6 +129,10 @@ export enum Opponents { MasterOG = "MasterOG", } +export enum CommunityOpponents { + Stik = "Stik", +} + export enum Hair { BeginnerSpikes = "Beginner Spikes", CasualFro = "Casual Fro",