From eb63dda62a12ca365c4326e825962de2405338d7 Mon Sep 17 00:00:00 2001 From: Alexthetransfem <124483815+theenchantedsword@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:05:59 -0500 Subject: [PATCH] Update morechemistry.js v1.5.2 --- mods/morechemistry.js | 261 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 232 insertions(+), 29 deletions(-) diff --git a/mods/morechemistry.js b/mods/morechemistry.js index 65bb4326..59a57b3e 100644 --- a/mods/morechemistry.js +++ b/mods/morechemistry.js @@ -1,4 +1,5 @@ //This mod was made by Adora the transfem, https://discord.com/users/778753696804765696 on discord and https://www.tiktok.com/@alextheagenenby?_t=8hoCVI3NRhu&_r=1 on tiktok. +let version = "1.5.2"; function pixelInRange(pixel, range){ let i = 0; while (i < range.length) { @@ -1162,6 +1163,7 @@ function conditionTrue(condition, pixel){ let ifCondition = ""; let currentProp = ""; let currentPropValue = ""; +let Func = ""; elements.propmachine = { name: "PropMachine", behavior: behaviors.WALL, @@ -1186,41 +1188,48 @@ onSelect: function(pixel) { } else { exclude2 += "propmachine"; } - var answer1 = prompt("Warning - This tool may break the simulator if used incorrectly.\n\nEnter a pixel attribute to modify:",(currentProp||undefined)); + var answer1 = prompt("Warning - This tool may break the simulator if used incorrectly.\n\nEnter a pixel attribute to modify or enter !FUNC to execute a function on pixels.",(currentProp||undefined)); + if(answer1.includes("!FUNC")){ + alert("enter the function you wish to execute in the function textbox at the bottom of the page. if you have not before you get this alert, nothing will happen. make sure the function has \"function(){\" before it and \"}\" after it. an example is: \"function(){console.log(\"Hello World!\")}\""); + var answer2 = Func; + } console.log(answer1) if (!answer1) { return } - var answer2 = prompt("Now, enter a value for "+answer1+":",(currentPropValue||undefined)); - if (!answer2) { return } - var valueL = answer2.toLowerCase(); - if (valueL === "true") { answer2 = true } - else if (valueL === "false") { answer2 = false } - else if (valueL === "null") { answer2 = null } - else if (valueL === "undefined") { answer2 = undefined } - else if (answer1 === "color" && valueL[0] === "#") { - var rgb = hexToRGB(valueL); - answer2 = "rgb("+rgb.r+","+rgb.g+","+rgb.b+")"; - } - currentProp = answer1; - currentPropValue = answer2; - console.log(answer1); - var num = parseFloat(answer2); - if (!isNaN(num)) { answer2 = num } - currentPropValue = answer2; - logMessage("Prop: "+currentProp); - logMessage("Value: "+currentPropValue); -}, + if(!answer2){ + var answer2 = prompt("Now, enter a value for "+answer1+":",(currentPropValue||undefined)); + if (!answer2) { return } + var valueL = answer2.toLowerCase(); + if (valueL === "true") { answer2 = true } + else if (valueL === "false") { answer2 = false } + else if (valueL === "null") { answer2 = null } + else if (valueL === "undefined") { answer2 = undefined } + else if (answer1 === "color" && valueL[0] === "#") { + var rgb = hexToRGB(valueL); + answer2 = "rgb("+rgb.r+","+rgb.g+","+rgb.b+")"; + } + currentProp = answer1; + currentPropValue = answer2; + console.log(answer1); + var num = parseFloat(answer2); + if (!isNaN(num)) { answer2 = num } + currentPropValue = answer2; + logMessage("Prop: "+currentProp); + logMessage("Value: "+currentPropValue); + } + }, tick: function(pixel) { if(pixel.start == pixelTicks) { pixel.range = num4; pixel.condition = ifCondition; pixel.prop = currentProp; pixel.val = currentPropValue; + pixel.func = Func; } let range = mouseRange(pixel.x, pixel.y, pixel.range); - prop({ property: pixel.prop, value: pixel.val },range, exclude2, pixel.condition); - } + prop({ property: pixel.prop, value: pixel.val },range, exclude2, pixel.condition, pixel.func); + } } -function prop(obj, range, exclude = [], condition = ""){ +function prop(obj, range, exclude = [], condition = "", func = undefined){ let list = []; for (var i = 0; i < range.length; i++) { var x = range[i][0]; @@ -1233,6 +1242,9 @@ function prop(obj, range, exclude = [], condition = ""){ for (var i = 0; i < list.length; i++) { if (!isEmpty(list[i].x, list[i].y, true)) { var pixel = list[i]; + if(func){ + eval(func); + } if (!exclude.includes(pixel.element) && conditionTrue(condition, pixel)){ if(/^\d+$/.test(obj.value)){ obj.value = parseInt(obj.value); @@ -1386,6 +1398,197 @@ elements.sign = { } } } +let attrElem = ""; +let magnetRange = 0; +let magnetElems = []; +elements.magnet = { + category: "machines", + tick:function(pixel){ + if(pixelTicks == pixel.start){ + if(attrElem.includes(" ")){attrElem.replace(/s/g, "")} + pixel.elem = (attrElem.includes(",")) ? attrElem.split(",") : attrElem; + pixel.range = magnetRange; + } + let range = mouseRange(pixel.x, pixel.y, pixel.range) + for (var i = 0; i < currentPixels.length; i++){ + if(pixelInRange(currentPixels[i], range)){ + let pixel2 = currentPixels[i] + if(!pixel2.drag && pixel.elem.includes(pixel2.element)){pixel2.drag = true} + if(pixel2.drag && !pixel.elem.includes(pixel2.element) && !beamPixels.includes(pixel2) && ((draggingPixels && draggingPixels.includes(pixel2)) || !draggingPixels)){pixel2.drag = false;} + if(!magnetElems.includes(pixel2) && pixel.elem.includes(pixel2.element)){magnetElems.push(pixel2)} + if(pixel.elem.includes(pixel2.element)){ + (pixel2.x > pixel.x) ? tryMove(pixel2, pixel2.x - 1, pixel2.y, undefined, true) : tryMove(pixel2, pixel2.x + 1, pixel2.y, undefined, true); + (pixel2.y > pixel.y) ? tryMove(pixel2, pixel2.x, pixel2.y - 1, undefined, true) : tryMove(pixel2, pixel2.x, pixel2.y + 1, undefined, true); + } + } else if (draggingPixels && !draggingPixels.includes(currentPixels[i])){ + currentPixels[i].drag = false; + } + } + }, + onSelect: function(){ + attrElem = prompt("Enter the element you want to attract.", (attrElem || undefined)); + magnetRange = parseInt(prompt("Enter the range you want to attract " + attrElem + " to.", (magnetRange || undefined))); + } +} +let move = false; +let moves = { + a: [-1,0], + d: [1,0], + s: [0,1], + w: [0,-1] +} +let UFOs = []; +let beamPixels = []; +let a = adjacentCoords; +function randomString(length){ + let str = ""; + let chars = "abcdefghijklmnopqrstuvwxyz"; + let charArr = chars.split(""); + for(var i = 0; i < length; i++){ + str += charrArr[Math.floor(Math.random() * charArr.length)]; + } + return str; +} +elements.ufo = { + category: "machines", + behavior: behaviors.WALL, + properties: { + cooldown: 0, + }, + tick: function(pixel){ + if(!UFOs.includes(pixel)){ UFOs = []; UFOs.push(pixel); } + if(move){ + tryMove(pixel, pixel.x + move[0], pixel.y + move[1]) + } + }, + hardness: 1, + insulate: true, +} +let keysDown = {}; +document.addEventListener("keydown", function(event){ + if(moves[event.key.toLowerCase()]){ + move = moves[event.key.toLowerCase()]; + } + keysDown[event.key.toLowerCase()] = true; + if(event.key.toLowerCase() == "b"){ + for(var i = 0; i < UFOs.length; i++){ + if(isEmpty(UFOs[i].x, UFOs[i].y+1) && !outOfBounds(UFOs[i].x, UFOs[i].y+1)){ + createPixel("heat_ray", UFOs[i].x, UFOs[i].y+1); + } + } + } + if(event.key.toLowerCase() == "q"){ + for(var i = 0; i < UFOs.length; i++){ + if(isEmpty(UFOs[i].x, UFOs[i].y+1) && !outOfBounds(UFOs[i].x, UFOs[i].y+1)){ + for(var ii = 0; ii < adjacentCoords.length; ii++){ + let x = UFOs[i].x + adjacentCoords[ii][0]; + let y = UFOs[i].y + adjacentCoords[ii][1]; + if(event.shiftKey){ + explodeAt(x, y, 10) + } else { + explodeAt(x, y, 4); + } + } + } + } + } + if(event.key.toLowerCase() == "x"){ + for(var i = 0; i < UFOs.length; i++){ + for(var ii = 0; ii < currentPixels.length; ii++){ + if([UFOs[i].x].includes(currentPixels[ii].x) && currentPixels[ii].y > UFOs[i].y){ + if(isEmpty(currentPixels[ii].x, currentPixels[ii].y - 1) && !outOfBounds(currentPixels[ii].x, currentPixels[ii].y - 1)){ + beamPixels.push(currentPixels[ii]); + currentPixels[ii].drag = true; + movePixel(currentPixels[ii], currentPixels[ii].x, currentPixels[ii].y - 1); + } + } + + } + } + } + if(event.key.toLowerCase() == "g"){ + for(var i = 0; i < UFOs.length; i++){ + pixel = UFOs[i]; + for (var ii = 0; i < adjacentCoords.length; ii++){ + let x = pixel.x + a[ii][0]; + let y = pixel.y + a[ii][1]; + if(!isEmpty(x, y) && !outOfBounds(x, y)){ + let pixel2 = pixelMap[x][y]; + if(elements[pixel2.element].breakInto){ + if(typeof elements[pixel2.element].breakInto == "object"){ + changePixel(pixel2, elements[pixel2.element].breakInto[Math.floor(Math.random() * elements[pixel2.element].breakInto.length)]); + } else { + changePixel(pixel2, elements[pixel2.element].breakInto); + } + } + } + } + } + } + if(event.key.toLowerCase() == "j"){ + for(var i = 0; i < UFOs.length; i++){ + pixel = UFOs[i]; + for (var ii = 0; i < adjacentCoords.length; ii++){ + let x = pixel.x + a[ii][0]; + let y = pixel.y + a[ii][1]; + if(!isEmpty(x, y) && !outOfBounds(x, y) && elements[pixelMap[x][y].element].conduct > 0){ + pixelMap[x][y].charge = 1; + } + } + } + } +}) +function isArray(item) { + return Object.prototype.toString.call(item) === '[object Array]'; +} + +document.addEventListener("keyup", function(event){ + keysDown[event.key.toLowerCase()] = false; + if(moves[event.key.toLowerCase()] && move){ + move = false; + } + if(event.key.toLowerCase() == "x"){ + for(var i = 0; i < beamPixels.length; i++){ + beamPixels[i].drag = false; + } + beamPixels = []; + } +}) +function deletePixel(x,y) { + // remove pixelMap[x][y] from currentPixels + currentPixels.splice(currentPixels.indexOf(pixelMap[x][y]),1); + if(UFOs.includes(pixelMap[x][y])){ + UFOs.splice(UFOs.indexOf(pixelMap[x][y]),1) + } + if (pixelMap[x][y]) {pixelMap[x][y].del = true;} + delete pixelMap[x][y]; +} +setInterval(function(){ + for(var i = 0; i < currentPixels.length; i++){ + for(var ii = 0; ii < UFOs.length; ii++){ + if(beamPixels.includes(currentPixels[i]) && currentPixels[i].x != UFOs[ii].x && !keysDown.x){ + beamPixels.splice(beamPixels.indexOf(currentPixels[i]), 1); + currentPixels[i].drag = false; + } + else if (currentPixels[i].x != UFOs[ii].x && beamPixels.includes(currentPixels[i])){ + (currentPixels[i].x > UFOs[ii].x) ? null : null; + } + } + if(currentPixels[i].drag && !beamPixels.includes(currentPixels[i])){ + if(draggingPixels && !draggingPixels.includes(currentPixels[i])){ + if(!magnetElems.includes(currentPixels[i])){ + currentPixels.drag = false; + } + } else if(!draggingPixels){ + if(!magnetElems.includes(currentPixels[i])){ + currentPixels[i].drag = false; + } + } else if (draggingPixels && draggingPixels.includes(currentPixels[i])){ + continue; + } + } + } +}, 1000/tps) runAfterLoad(function(){ document.body.insertAdjacentHTML("beforeend",` these are all properties of the pixel. another way to find pixel properties is using debug on a pixel, it will tell you the property and the value, like x and y, or, in plants.js, fruit. @@ -1450,15 +1653,15 @@ runAfterLoad(function(){ - p.tick + p.tick the amount of ticks that have happened so far in the game. - `) - // document.getElementById("extraInfo").innerHTML = ` - // Changelog(NEW)FeedbackWikiRedditDiscord • Install OfflineVariables

v1.9.3 • 559 elements, with 0 hidden.

©2021-2024. All Rights Reserved.

- // ` +

Paste function code for the prop machine in the text area below, typing doesnt work well.

+ + + `); });