From 9f66432b2f9b74ae22c1b4e4f0695754ff041dc9 Mon Sep 17 00:00:00 2001 From: DKopalXYZ Date: Sun, 29 Jun 2025 00:17:36 +0200 Subject: [PATCH] Add files via upload --- mods/comments.js | 37 ++++++++++++++++++++++++ mods/debris.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 mods/comments.js create mode 100644 mods/debris.js diff --git a/mods/comments.js b/mods/comments.js new file mode 100644 index 00000000..3cf22339 --- /dev/null +++ b/mods/comments.js @@ -0,0 +1,37 @@ +let comment = "" +dependOn( + "debris.js", + () => { + elements.comment = { + color: "#222222", + state: "solid", + onSelect: () => { + promptInput("Enter the comment text", + (result) => { + if (result) { + comment = result + } + }, + "comments.js is asking you...", + "") + }, + tick: (pixel) => { + if (pixel.start == pixelTicks) { + pixel.text = comment + pixel.cid = debris({ + type: "text", + text: pixel.text, + color: "#fff", + size: 14, + x: pixel.x, + y: pixel.y + }) + } + }, + onDelete: (pixel) => { + removeDebris(pixel.cid) + } + } + }, + true +) \ No newline at end of file diff --git a/mods/debris.js b/mods/debris.js new file mode 100644 index 00000000..2bdb5ed6 --- /dev/null +++ b/mods/debris.js @@ -0,0 +1,75 @@ +const debrisMap = [] +let LastDebrisId = 0 + +function debris(config) { + config.start = pixelTicks; + config.id = LastDebrisId; + LastDebrisId++; + debrisMap.push(config); + + if (config.deleteAfter) { + setTimeout(() => { + const i = debrisMap.indexOf(config); + if (i !== -1) debrisMap.splice(i, 1); + }, config.deleteAfter); + }; + + return config.id +} + +function removeDebris(id) { + for (let i = 0; i < debrisMap.length; i++) { + const config = debrisMap[i] + if (config.id == id) { + debrisMap.splice(i, 1); + return true; + } + } + return false +} + +runAfterLoad(() => { + renderPostPixel((ctx) => { + for (let i = debrisMap.length - 1; i >= 0; i--) { + const config = debrisMap[i]; + + if (config.deleteAfterTicks && pixelTicks >= config.start + config.deleteAfterTicks) { + debrisMap.splice(i, 1); + continue; + } + + if (!config.type) continue; + + const opacity = config.opacity ?? 1; + ctx.globalAlpha = opacity; + + if (config.type === "pixel" && config.color && config.x !== undefined && config.y !== undefined) { + ctx.fillStyle = config.color; + ctx.fillRect(config.x * pixelSize, config.y * pixelSize, pixelSize, pixelSize); + } else if (config.type === "text" && config.color && config.text && config.x !== undefined && config.y !== undefined && config.size) { + ctx.fillStyle = config.color; + ctx.font = `${config.size}px "Press Start 2P"`; + ctx.fillText(config.text, config.x * pixelSize, config.y * pixelSize); + } else if (config.type === "rect" && config.color && config.x !== undefined && config.y !== undefined && config.width && config.height) { + ctx.fillStyle = config.color; + ctx.fillRect(config.x * pixelSize, config.y * pixelSize, config.width, config.height); + } else if (config.type === "circle" && config.color && config.x !== undefined && config.y !== undefined && config.radius) { + ctx.fillStyle = config.color; + ctx.beginPath(); + ctx.arc(config.x * pixelSize, config.y * pixelSize, config.radius, 0, 2 * Math.PI); + ctx.fill(); + } else if (config.type === "glow" && config.color && config.gColor && config.blur && config.x !== undefined && config.y !== undefined) { + const strength = config.strength || 1; + for (let j = 0; j < strength; j++) { + ctx.shadowColor = config.gColor; + ctx.shadowBlur = config.blur; + ctx.fillStyle = config.color; + ctx.fillRect(config.x * pixelSize, config.y * pixelSize, pixelSize, pixelSize); + ctx.shadowBlur = 0; + } + } + + ctx.globalAlpha = 1; + } + }) +})