Update morechemistry.js v1.5.2

This commit is contained in:
Alexthetransfem 2024-03-23 16:05:59 -05:00 committed by GitHub
parent af8d857b4e
commit eb63dda62a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 232 additions and 29 deletions

View File

@ -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(){
</tr>
<tr>
<th>
p.tick
p.tick
</th>
<th>
the amount of ticks that have happened so far in the game.
</th>
</tr>
</tbody></table>
`)
// document.getElementById("extraInfo").innerHTML = `
// <small><a href="https://sandboxels.r74n.com/changelog" id="changelogButton" target="_blank">Changelog<span style="color:red">(NEW)</span></a> • <a href="https://sandboxels.R74n.com/feedback" target="_blank" style="color:lime;">Feedback</a> • <a href="https://sandboxels.wiki.gg/" target="_blank" id="wikiButton" title="Official Sandboxels Wiki - wiki.gg" style="color:white;">Wiki</a> • <a id="moreSocial" href="https://reddit.com/r/Sandboxels" rel="me" target="_blank"><span style="color:#FF5700">Reddit</span></a> • <a href="https://discord.gg/ejUc6YPQuS" target="_blank" style="color:#2f60ff;">Discord</a><span id="install-button" style="display: inline-block;">&nbsp;• <a onclick="deferredPrompt.prompt(); return false" href="#" style="text-shadow: 0px 2px 10px #ff00ff; cursor:pointer">Install Offline</a> • <a href = "https://sandboxels.r74n.com/#variables">Variables</a></span><!--<br><br><a style="color:lime" target="_blank" href="https://docs.google.com/forms/d/e/1FAIpQLSf8pVMSdC6oSnBSaTpzjPQa8Ef-vxG_eXL99UITnMSQtJFTJA/viewform?usp=sf_link">FILL OUT THE CENSUS<span style="color:red">(NEW)</span></a>--></small><small><p>v1.9.3 • 559 elements, with <span id="hiddenCount">0</span> hidden.</p><p>©2021-2024. <a href="https://sandboxels.R74n.com/license.txt" rel="license" target="_blank">All Rights Reserved</a>. <a style="color:#00ffff" rel="author" href="https://r74n.com">R74n</a></p></small>
// `
<p>Paste function code for the prop machine in the text area below, typing doesnt work well.</p>
<textarea id="func"></textarea>
<button onClick = "Func = document.getElementById('func').value;">Use as function</button>
`);
});