Added new Community Opponents Code

This commit is contained in:
Eddie Annor 2024-08-13 12:57:47 +01:00 committed by GitHub
parent 3b532c498c
commit 9ba2e269bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 113 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 KiB

View file

@ -0,0 +1 @@
Hahaha of the muhuhu I am the better placeholder TXT file FEAR ME!!!!!!!!!!

View file

@ -0,0 +1 @@
Yooooooo community opponent VS Screens sheeeeeeeeeeeeeeeeeesh

108
index.ts
View file

@ -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"

View file

@ -129,6 +129,10 @@ export enum Opponents {
MasterOG = "MasterOG",
}
export enum CommunityOpponents {
Stik = "Stik",
}
export enum Hair {
BeginnerSpikes = "Beginner Spikes",
CasualFro = "Casual Fro",