From 8de3162d8cdc50e1f002ffe2d7adf36db93a1764 Mon Sep 17 00:00:00 2001 From: An Orbit <68935009+orbit-loona@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:25:01 -0500 Subject: [PATCH] helper functions, bladesea, plasma rainbow --- mods/a_mod_by_alice.js | 175 ++++++++++++++++++++++++++++++++--------- 1 file changed, 139 insertions(+), 36 deletions(-) diff --git a/mods/a_mod_by_alice.js b/mods/a_mod_by_alice.js index f859be4f..a2299180 100644 --- a/mods/a_mod_by_alice.js +++ b/mods/a_mod_by_alice.js @@ -4,7 +4,7 @@ var dependencyExistence = dependencies.map(x => enabledMods.includes(x)); var allDependenciesExist = dependencyExistence.reduce(function(a,b) { return a && b }); //console.log(allDependenciesExist); if(allDependenciesExist) { - +try { //COMMON VARIABLES ## const whiteColor = {r: 255, g: 255, b: 255}; @@ -290,6 +290,26 @@ if(allDependenciesExist) { return matches }; + function elementsWith(keyQuery) { + if(typeof(window.keyQuery) == "undefined") { window.keyQuery = "" }; //necessary because of filter's idiotic no-argument policy + window.keyQuery = keyQuery; + var elemNames = Object.keys(elements); + var matches = elemNames.filter(function(name) { + return typeof(elements[name]?.[window.keyQuery]) !== "undefined" + }); + return matches + }; + + function elementsWithout(keyInverseQuery) { + if(typeof(window.keyInverseQuery) == "undefined") { window.keyInverseQuery = "" }; //necessary because of filter's idiotic no-argument policy + window.keyInverseQuery = keyInverseQuery; + var elemNames = Object.keys(elements); + var matches = elemNames.filter(function(name) { + return typeof(elements[name]?.[window.keyInverseQuery]) === "undefined" + }); + return matches + }; + function getElementsInCategory(categoryName) { if(["",null,undefined].includes(categoryName)) { categoryName = "other" }; window.categoryQuery = categoryName; @@ -4442,6 +4462,9 @@ color1 and color2 spread through striped paint like dye does with itself. col runAfterAutogen(function() { //rAA because velocity.js already puts its redef in a rAL and rAA comes after that drawPixels = function(forceTick=false) { + // Draw the current pixels + var canvas = document.getElementById("game"); + var ctx = canvas.getContext("2d"); // newCurrentPixels = shuffled currentPixels var newCurrentPixels = currentPixels.slice(); var pixelsFirst = []; @@ -4473,9 +4496,6 @@ color1 and color2 spread through striped paint like dye does with itself. col pixelsFirst.push(pixel); } } - // Draw the current pixels - var canvas = document.getElementById("game"); - var ctx = canvas.getContext("2d"); ctx.clearRect(0, 0, canvas.width, canvas.height); if (!settings["bg"]) {ctx.clearRect(0, 0, canvas.width, canvas.height)} else { @@ -7620,6 +7640,58 @@ color1 and color2 spread through striped paint like dye does with itself. col hardness: 0.7, } + var temp = "firesea,lektre,concoction,mistake,unstable_mistake,toxic_mistake".split(","); + for(var i = 0; i < temp.length; i++) { + temp[i].state = "liquid"; + temp[i].category = "liquids" + }; + + + elements.head.cutInto = ["bone","meat","blood"]; + elements.body.cutInto = ["bone","meat","meat","blood","blood"]; + elements.wood.cutInto = ["wood_plank","wood_plank","wood_plank","wood_plank","wood_plank","wood_plank","wood_plank","wood_plank","sawdust"]; + elements.fish.breakInto = ["meat","meat","bone","blood"]; + elements.fish.cutInto = ["meat","meat","bone","blood"]; + + elements.bladesea = { + color: ["#959696", "#b1b3b3", "#d4d4d4", "#bfbdbd"], + state: "liquid", + viscosity: 5, + behavior: behaviors.LIQUID, + tick: function(pixel) { //Code from R74n/vanilla "smash" tool + var pX = pixel.x; + var pY = pixel.y; + for(i = 0; i < adjacentCoords.length; i++) { + var oX = adjacentCoords[i][0]; + var oY = adjacentCoords[i][1]; + var fX = pX+oX; + var fY = pY+oY; + if(!isEmpty(fX,fY,true)) { + var checkPixel = pixelMap[fX][fY]; + var otherElement = elements[checkPixel.element]; + if (typeof(otherElement.cutInto) !== "undefined") { + var hardness = otherElement.hardness ?? 0; + if (Math.random() < (1 - hardness)) { + var cutInto = otherElement.cutInto; + // if breakInto is an array, pick one + if (Array.isArray(cutInto)) { + cutInto = randomChoice(cutInto); + }; + changePixel(checkPixel,cutInto); + } + } + }; + }; + }, + density: 200, + category: "liquids", + hidden: true, + reactions: { + "concoction": { "elem1": "bladesea", "elem2": "bladesea", "chance":0.005}, + }, + }; + + //ASSORTED RAINBOW VARIANTS ## elements.concoction.reactions.diorite_gravel = { @@ -7651,6 +7723,7 @@ color1 and color2 spread through striped paint like dye does with itself. col elements.rainbow.reactions ??= {}; elements.rainbow.reactions.fire = { elem1: "fireshimmer", chance: 0.1 }; + elements.rainbow.reactions.plasma = { elem1: "plasmashimmer", chance: 0.1 }; elements.rainbow.insulate = false; elements.rainbow.burnInto = "fireshimmer"; elements.rainbow.burn = 0.1; @@ -7735,7 +7808,7 @@ color1 and color2 spread through striped paint like dye does with itself. col elements.rainbow.reactions.iodine = { elem1: "iodoshimmer" }; elements.rainbow.reactions.molten_iodine = { elem1: "iodoshimmer" }; elements.rainbow.reactions.iodine_gas = { elem1: "iodoshimmer" }; - elements.astatine.tempHigh = 302; + runAfterLoad(function() { elements.astatine.tempHigh = 302 }); elements.molten_astatine ??= {}; elements.molten_astatine.tempHigh = 337; elements.rainbow.reactions.astatine = { elem1: "astatoshimmer" }; elements.rainbow.reactions.molten_astatine = { elem1: "astatoshimmer" }; @@ -7871,6 +7944,37 @@ color1 and color2 spread through striped paint like dye does with itself. col } }, category: "special", + reactions: { + dye: elements.rainbow.reactions.dye, + plasma: {elem1: "plasmashimmer", tempMin: 10000} + }, + behavior: behaviors.WALL, + state: "solid", + category: "rainbow variants", + movable: false, + }; + + elements.plasmashimmer = { + color: ["#8800ff","#f2f2f2","#8800ff","#f2f2f2"], + tick: function(pixel) { + var dyeColor = pixel.dyeColor ?? null; + var t = pixelTicks*3+pixel.x+pixel.y; + var value = Math.floor(127*((Math.max(0,1-(rainbowMathlet(t,25,0)))) ** 1.1)); + baseColor = "rgb(" + [Math.round(127 + (value/2)), value, 255].join(",") + ")"; + if(!dyeColor) { + pixel.color = baseColor + } else { + var baseJSON = convertColorFormats(baseColor,"json"); + var dyeJSON = convertColorFormats(dyeColor,"json"); + var dyedColor = multiplyColors(dyeJSON,baseJSON,"json"); + //70% multiplied + var semiDyedColor = averageColorObjects(dyedColor,baseJSON,0.7); + //35% dye color, 65% result + var finalColor = averageColorObjects(semiDyedColor,dyeJSON,0.65); + pixel.color = convertColorFormats(finalColor,"rgb") + } + }, + category: "special", reactions: { dye: elements.rainbow.reactions.dye }, @@ -7919,7 +8023,7 @@ color1 and color2 spread through striped paint like dye does with itself. col movable: false, }; - elements.rainbow.behavior = behaviors.WALL; + elements.rainbow.behavior = behaviors.WALL; //7989 yay soshi! elements.dye.ignore ??= []; @@ -7986,7 +8090,7 @@ color1 and color2 spread through striped paint like dye does with itself. col var r = Math.floor(255*(1-Math.cos(t*Math.PI/24))); pixel.color = "rgb("+Math.ceil((r*(7/8))+32)+","+0+","+0+")"; }, - behavior: behaviors.WALL, //7989 yay soshi! + behavior: behaviors.WALL, state: "solid", category: "rainbow variants", }; @@ -14109,7 +14213,7 @@ Pixel size (rendering only): (Use if the save looks cut o stain: elements.spray_paint.stain, }; - var temp = { + temp = { invisible_wall: "asdfg", invisible_dye: 2, invisible_dye_gas: false @@ -14769,18 +14873,10 @@ Pixel size (rendering only): (Use if the save looks cut o var fY = pY+oY; if(!isEmpty(fX,fY,true)) { var checkPixel = pixelMap[fX][fY]; - var thisElementName = pixel.element; - var otherElementName = checkPixel.element; - var thisElement = elements[pixel.element]; var otherElement = elements[checkPixel.element]; if (typeof(otherElement.breakInto) !== "undefined") { - var hardness = null; - if (typeof(otherElement.hardness) === "number") { - hardness = otherElement.hardness; - } else { - hardness = 1; - }; - if (Math.random() < hardness) { + var hardness = otherElement.hardness ?? 0; + if (Math.random() < (1 - hardness)) { var breakInto = otherElement.breakInto; // if breakInto is an array, pick one if (Array.isArray(breakInto)) { @@ -19635,7 +19731,7 @@ Pixel size (rendering only): (Use if the save looks cut o elements.frozen_ketchup.breakInto = "ketchup_snow" elements.frozen_poisoned_ketchup.breakInto = "poisoned_ketchup_snow" - regularShinyThingArray = ["iron", "zinc", "tin", "nickel", "silver", "aluminum", "lead", "tungsten", "brass", "bronze", "sterling", "steel", "white_gold", "blue_gold", "rose_gold", "red_gold", "solder", "gold", "pyrite", "mythril", "mithril_mythril_alloy", "titanium", "ilitium", "mithril", "beryllium", "boron", "ruthenium", "rhodium", "palladium", "rhenium", "osmium", "iridium", "platinum", "frozen_mercury", "lithium", "niobium", "ketchup_metal", "ketchup_gold", "tungstensteel", "densinium", "mithril", "signalum", "laetium"] + regularShinyThingArray = ["iron", "zinc", "tin", "nickel", "silver", "aluminum", "lead", "tungsten", "brass", "bronze", "sterling", "steel", "white_gold", "blue_gold", "rose_gold", "red_gold", "solder", "gold", "pyrite", "mythril", "mithril_mythril_alloy", "titanium", "ilitium", "mithril", "beryllium", "boron", "ruthenium", "rhodium", "palladium", "rhenium", "osmium", "iridium", "platinum", "frozen_mercury", "lithium", "niobium", "ketchup_metal", "ketchup_gold", "tungstensteel", "densinium", "mithril", "signalum", "laetium", "kurshunjukium", "zirconium", "jinsoulite"]; elements.nitrogen_snow = { color: "#efefef", @@ -19654,23 +19750,26 @@ Pixel size (rendering only): (Use if the save looks cut o runAfterLoad(function() { for(i = 0; i < regularShinyThingArray.length; i++) { var thing = regularShinyThingArray[i]; - if(elements[thing]) { - elements[`${thing}_scrap`] = { - color: elements[thing].color, - behavior: behaviors.POWDER, - tempHigh: elements[thing].tempHigh, - stateHigh: thing, - category: "powders", - hidden: true, - density: elements[thing].density * 0.09, - conduct: elements[thing].conduct * 0.4, - movable: true, + if(typeof(elements[thing]) == "object") { + if(typeof(elements[thing]?.breakInto) == "undefined") { + elements[`${thing}_scrap`] = { + color: elements[thing].color, + behavior: behaviors.POWDER, + tempHigh: elements[thing].tempHigh, + stateHigh: thing, + category: "powders", + hidden: true, + density: elements[thing].density * 0.09, + conduct: elements[thing].conduct * 0.4, + movable: true, + }; + if(elements[thing].reactions) { + elements[`${thing}_scrap`].reactions = elements[thing].reactions; + }; + elements[thing].breakInto = `${thing}_scrap`; }; - if(elements[thing].reactions) { - elements[`${thing}_scrap`].reactions = elements[thing].reactions; - }; - elements[thing].breakInto = `${thing}_scrap`; - }; + elements[thing].cutInto = elements[thing].breakInto + } }; elements.acid.ignore.push("densinium_scrap") @@ -40891,6 +40990,7 @@ Make sure to save your command in a file if you want to add this preset again.` state: "solid", hardness: 0.2, breakInto: "sawdust", + cutInto: ["wood_plank","wood_plank","wood_plank","wood_plank","wood_plank","wood_plank","sawdust"] }; elements.hanging_concrete = { @@ -43858,7 +43958,10 @@ maxPixels (default 1000): Maximum amount of pixels/changes (if xSpacing and ySpa behavior: behaviors.WALL, maxColorOffset: 0 }; - +} catch (error) { + alert(`Load failed (try reloading)\nError: ${error.stack}`); + console.error(error) +}; } else { var nonexistentMods = dependencies.filter(function(modPath) { return !(enabledMods.includes(modPath)) }); nonexistentMods.forEach(function(modPath) {