From 7f9390d50ee019b587820eb37dcfc3240306ca99 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Wed, 2 Apr 2025 21:14:22 -0400 Subject: [PATCH 1/5] f --- mods/nousersthings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/nousersthings.js b/mods/nousersthings.js index a8c6cbfa..ac5316f0 100644 --- a/mods/nousersthings.js +++ b/mods/nousersthings.js @@ -3939,7 +3939,7 @@ renderPostPixel(function(ctx){ if ((pixel.element == "sign") && pixel.sign){ ctx.font = `12pt Arial` ctx.fillStyle = pixel.color; - ctx.fillText(pixel.sign = pixel.sign.replace(/\$\{([\w.\[\]]+)\}/g, (_, path) => { + ctx.fillText(pixel.sign.replace(/\$\{([\w.\[\]]+)\}/g, (_, path) => { try { const value = new Function('return globalThis.' + path)(); return typeof value === 'object' ? JSON.stringify(value) : value ?? ''; @@ -3951,7 +3951,7 @@ renderPostPixel(function(ctx){ if (pixel.charge || pixel.chargeCD){ ctx.font = `12pt Arial` ctx.fillStyle = pixel.color; - ctx.fillText(pixel.sign = pixel.sign.replace(/\$\{([\w.\[\]]+)\}/g, (_, path) => { + ctx.fillText(pixel.sign.replace(/\$\{([\w.\[\]]+)\}/g, (_, path) => { try { const value = new Function('return globalThis.' + path)(); return typeof value === 'object' ? JSON.stringify(value) : value ?? ''; From cf3b95910e876075e167a63ed5fc5243967b281a Mon Sep 17 00:00:00 2001 From: slweeb <91897291+slweeb@users.noreply.github.com> Date: Thu, 3 Apr 2025 13:56:25 -0400 Subject: [PATCH 2/5] gravity_test.js --- index.html | 14 ++++++++++++ mods/gravity_test.js | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 mods/gravity_test.js diff --git a/index.html b/index.html index 64be082e..0c565e9e 100644 --- a/index.html +++ b/index.html @@ -13048,6 +13048,10 @@ onAddElementList = []; function onAddElement(callback) { onAddElementList.push(callback); } +validateMovesList = []; +function validateMoves(callback) { + validateMovesList.push(callback); +} canvasLayers = { // bg: document.createElement("canvas"), pixels: document.createElement("canvas"), @@ -13764,6 +13768,16 @@ function langKey(key,fallback,template) { function tryMove(pixel,nx,ny,leaveBehind,force) { if (pixel.drag && force !== true) { return true; } if (pixel.del) { return false } + if (validateMovesList.length !== 0 && force !== true) { + for (let i = 0; i < validateMovesList.length; i++) { + const result = validateMovesList[i](pixel,nx,ny); + if (result === false) return false; + else if (Array.isArray(result)) { + nx = result[0]; + ny = result[1]; + } + } + } var info = elements[pixel.element]; var oob = outOfBounds(nx,ny); if (isEmpty(nx,ny,false,oob)) { // If coords is empty, move to coords diff --git a/mods/gravity_test.js b/mods/gravity_test.js new file mode 100644 index 00000000..3c90a653 --- /dev/null +++ b/mods/gravity_test.js @@ -0,0 +1,51 @@ +// validateMoves((pixel,nx,ny) => { +// if (pixel.y-ny < 0) { //goes down usually +// return false; +// } +// }) + +validateMoves((pixel,nx,ny) => { + if (elements[pixel.element].isGas) return true; + if (true || pixel.y-ny < 0) { //goes down usually + + nx = 0; + ny = 0; + + const centerX = Math.floor(width/2); + const centerY = Math.floor(height/2); + + let diffX = centerX-pixel.x; + let diffY = centerY-pixel.y; + + let dirX = 0; + let dirY = 0; + if (Math.abs(diffX) > Math.abs(diffY)) { + dirX = Math.sign(diffX); + } + else { + dirY = Math.sign(diffY); + } + + if (Math.random() < Math.abs(diffX)/100) diffX = Math.sign(diffX); + else diffX = 0; + if (Math.random() < Math.abs(diffY)/100) diffY = Math.sign(diffY); + else diffY = 0; + + if ((diffX || diffY) && !isEmpty(pixel.x+diffX,pixel.y+diffY)) { + if (dirX !== 0) { + diffY = Math.random() < 0.5 ? 1 : -1; + } + else if (dirY !== 0) { + diffX = Math.random() < 0.5 ? 1 : -1; + } + } + + // if (!(pixel.y-ny)) { + // diffX += pixel.y-ny; + // diffY += pixel.x-nx; + // } + + return [pixel.x+diffX,pixel.y+diffY]; + + } +}) \ No newline at end of file From a2565e4a119ca8bd297baf33e5df14e198e5c838 Mon Sep 17 00:00:00 2001 From: slweeb <91897291+slweeb@users.noreply.github.com> Date: Fri, 4 Apr 2025 10:06:33 -0400 Subject: [PATCH 3/5] Update index.html --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 0c565e9e..5130620f 100644 --- a/index.html +++ b/index.html @@ -18590,7 +18590,7 @@ window.onload = function() {