mirror of
https://github.com/DaInfLoop/Battler-Generator.git
synced 2024-11-21 13:29:55 +00:00
Added new Community Opponents Code
This commit is contained in:
parent
3b532c498c
commit
9ba2e269bd
BIN
assets/communitymaps/None.png
Normal file
BIN
assets/communitymaps/None.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 261 KiB |
1
assets/communitymaps/betterplaceholder.txt
Normal file
1
assets/communitymaps/betterplaceholder.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Hahaha of the muhuhu I am the better placeholder TXT file FEAR ME!!!!!!!!!!
|
1
assets/communityvs/placeholder.txt
Normal file
1
assets/communityvs/placeholder.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Yooooooo community opponent VS Screens sheeeeeeeeeeeeeeeeeesh
|
108
index.ts
108
index.ts
|
@ -4,7 +4,8 @@ import {
|
||||||
GenerateBattleImageOptions,
|
GenerateBattleImageOptions,
|
||||||
PlayerActionOptions,
|
PlayerActionOptions,
|
||||||
Opponents,
|
Opponents,
|
||||||
CustomActionOptions
|
CustomActionOptions,
|
||||||
|
CommunityOpponents
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import {
|
import {
|
||||||
generateBattler, drawText, applyText,
|
generateBattler, drawText, applyText,
|
||||||
|
@ -145,6 +146,13 @@ const opponents = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const communityopponents = {
|
||||||
|
[CommunityOpponents.Stik]: {
|
||||||
|
text: "Stik",
|
||||||
|
colour: ["#FF0000", "#000000"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const server = createServer(async (req, res) => {
|
const server = createServer(async (req, res) => {
|
||||||
if (req.method === "OPTIONS") {
|
if (req.method === "OPTIONS") {
|
||||||
res.setHeader("access-control-allow-origin", "*")
|
res.setHeader("access-control-allow-origin", "*")
|
||||||
|
@ -248,6 +256,57 @@ const server = createServer(async (req, res) => {
|
||||||
return res.end(canvas.toBuffer("image/png"), 'binary')
|
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 (
|
if (
|
||||||
req.method == "GET" &&
|
req.method == "GET" &&
|
||||||
url.pathname == "/playeraction.png"
|
url.pathname == "/playeraction.png"
|
||||||
|
@ -464,6 +523,53 @@ const server = createServer(async (req, res) => {
|
||||||
return res.end(canvas.toBuffer("image/png"), 'binary')
|
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 (
|
if (
|
||||||
req.method == "GET" &&
|
req.method == "GET" &&
|
||||||
url.pathname == "/pvp.png"
|
url.pathname == "/pvp.png"
|
||||||
|
|
4
types.ts
4
types.ts
|
@ -129,6 +129,10 @@ export enum Opponents {
|
||||||
MasterOG = "MasterOG",
|
MasterOG = "MasterOG",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum CommunityOpponents {
|
||||||
|
Stik = "Stik",
|
||||||
|
}
|
||||||
|
|
||||||
export enum Hair {
|
export enum Hair {
|
||||||
BeginnerSpikes = "Beginner Spikes",
|
BeginnerSpikes = "Beginner Spikes",
|
||||||
CasualFro = "Casual Fro",
|
CasualFro = "Casual Fro",
|
||||||
|
|
Loading…
Reference in a new issue