From c0625c669a68bd5a3ca3fc54b3ce3e61e1bf6b6f Mon Sep 17 00:00:00 2001 From: O-01-67 <68935009+O-01-67@users.noreply.github.com> Date: Fri, 8 Jul 2022 22:29:08 -0400 Subject: [PATCH] two new mods change.js: edit of replace.js, changes anything to a given element (behavior of The Powder Toy's replace mode) triggerable_random_powders.js: adds 3 powders one becomes a random element when heated, another does when cooled, and the third does when shocked --- mods/change.js | 58 +++++++++++++++++++++++++ mods/triggerable_random_powders.js | 68 ++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 mods/change.js create mode 100644 mods/triggerable_random_powders.js diff --git a/mods/change.js b/mods/change.js new file mode 100644 index 00000000..9511a0c4 --- /dev/null +++ b/mods/change.js @@ -0,0 +1,58 @@ +changeTo = "sand"; + +document.addEventListener("keydown", function(e) { //change prompt listener + // r = changeElementPrompt() + if (e.keyCode == 186) { + e.preventDefault(); + changeElementPrompt(); + } +}); + +function changeElementPrompt() { + var cmToElement = prompt("Enter what you want to change pixels to"); + // replace spaces with underscores + cmToElement = cmToElement.replace(/ /g, "_"); + cmToElementS = mostSimilarElement(cmToElement); + if (cmToElementS === null || cmToElementS === undefined || cmToElementS === "") { + alert("Element \"" + cmToElement + "\" not found! Defaulting to sand."); + cmToElementS = "sand"; + }; + changeTo = cmToElementS; + updateChangeDescriptions(); +} + +function updateChangeDescriptions() { + elements.change.desc = "Changes any pixels it is used on to a specified type.
Currently replacing pixels with \"" + changeTo + "\".
Press [;] or click here to open the change prompt."; + elements.alt_change.desc = "Changes any pixels it is used on to a specified type, but keeping their non-element-based properties.
Currently replacing pixels with \"" + changeTo + "\".
Press [;] or click here to open the change prompt."; + elements.alt_alt_change.desc = "Changes any pixels it is used on to a specified type, but keeping their non-element-based properties except for color.
Currently replacing pixels with \"" + changeTo + "\".
Press [;] or click here to open the change prompt."; +}; + +elements.change = { + color: ["#ff0000", "#ff0000", "#ff0000", "#7f00ff", "#0000ff", "#0000ff", "#0000ff"], + tool: function(pixel) { + changePixel(pixel,changeTo,true); + }, + category: "tools", + desc: "Changes any pixels it is used on to a specified type.
Currently replacing pixels with \"" + changeTo + "\".
Press [;] or click here to open the change prompt.", +}; + +elements.alt_change = { + color: ["#ffff00", "#ffff00", "#ffff00", "#cf7f4f", "#ff00ff", "#ff00ff", "#ff00ff"], + tool: function(pixel) { + pixel.element = changeTo; + }, + category: "tools", + desc: "Changes any pixels it is used on to a specified type, but keeping their non-element-based properties.
Currently replacing pixels with \"" + changeTo + "\".
Press [;] or click here to open the change prompt.", + hidden: true, +}; + +elements.alt_alt_change = { + color: ["#00ff00", "#00ff00", "#00ff00", "#cfcf00", "#ff0000", "#ff0000", "#ff0000"], + tool: function(pixel) { + pixel.element = changeTo; + pixel.color = pixelColorPick(pixel); + }, + category: "tools", + desc: "Changes any pixels it is used on to a specified type, but keeping their non-element-based properties except for color.
Currently replacing pixels with \"" + changeTo + "\".
Press [;] or click here to open the change prompt.", + hidden: true, +}; \ No newline at end of file diff --git a/mods/triggerable_random_powders.js b/mods/triggerable_random_powders.js new file mode 100644 index 00000000..12833d55 --- /dev/null +++ b/mods/triggerable_random_powders.js @@ -0,0 +1,68 @@ +if(typeof(randomChoices) === "undefined") { + randomChoices = []; +}; //this is generated after mod load, but JS will probably die if I don't have it defined in the code + +function randomFromZeroToValue(value) { + if(value >= 0) { + return Math.floor(Math.random() * (value + 1)) + } else { + return 0 - Math.floor(Math.random() * (Math.abs(value) + 1)) + }; +}; + +function randomChoice(array) { + var length = array.length; + var randomIndex = randomFromZeroToValue(length - 1); + return array[randomIndex]; +} + +elements.heat_random = { + name: "heat-randomized powder", + color: ["#4e5f8a","#b334ec","#fa96f9","#b6ecf6","#80ebc8","#e9286b","#8eed91","#b18b30"], //"random"'s colors plus 0x100000 + behavior: behaviors.POWDER, + tick: function(pixel) { + if(pixel.temp >= 50) { + changePixel(pixel,randomChoice(randomChoices),true); + }; + }, + state: "solid", + category: "powders", + density: 1987, //average density of all vanilla elements: 1987.2842952763815 + temp: 20, + desc: "Turns to a random element when heated to 50°C", +}; + +elements.cold_random = { + name: "cold-randomized powder", + color: ["#3e5f9a","#a334fc","#e490ff","#9de3ff","#70ebd8","#d9287b","#7eeda1","#a18b40"], //"random"'s colors plus 0x000010 except where the last byte was above 0xef, where substraction was done to the first two bytes to compensate + behavior: behaviors.POWDER, + tick: function(pixel) { + if(pixel.temp <= -50) { + changePixel(pixel,randomChoice(randomChoices),true); + }; + }, + state: "solid", + density: 1987, //average density of all vanilla elements: 1987.2842952763815 + temp: 20, + category: "powders", + desc: "Turns to a random element when cooled to -50°C", +}; + +elements.shock_random = { + name: "shock-randomized powder", + color: ["#4e6f8a","#b344ec","#faa6f9","#b6fcf6","#80fbc8","#e9386b","#8efd91","#b19b30"], //"random"'s colors plus 0x101000 + behavior: behaviors.POWDER, + tick: function(pixel) { + if(pixel.charge) { + delete pixel.charge; + pixel.chargeCD = 1; + changePixel(pixel,randomChoice(randomChoices),true); + }; + }, + conduct: 1, + state: "solid", + density: 1987, //average density of all vanilla elements: 1987.2842952763815 + temp: 20, + category: "powders", + desc: "Turns to a random element when shocked", +} \ No newline at end of file