From 122045bf41ad9ecc95f4432f569c9db62207ff3a Mon Sep 17 00:00:00 2001
From: O-01-67 <68935009+O-01-67@users.noreply.github.com>
Date: Wed, 6 Jul 2022 22:42:55 -0400
Subject: [PATCH] Adds a replacement tool (read desc)
It replaces an element with another.
Press " (quotes key) to open the prompt. It will ask for the element type you want to change, and then the element you want to change it to.
Then, use the replace tool and it will change all pixels of the first element you click/hold it on to the second element.
By default, it changes Rock to Sand.
---
mods/replace.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 mods/replace.js
diff --git a/mods/replace.js b/mods/replace.js
new file mode 100644
index 00000000..cd5f3905
--- /dev/null
+++ b/mods/replace.js
@@ -0,0 +1,75 @@
+replaceFrom = "rock";
+replaceTo = "sand";
+
+document.addEventListener("keydown", function(e) { //replace prompt listener
+ // r = replaceElementPrompt()
+ if (e.keyCode == 222) {
+ e.preventDefault();
+ replaceElementPrompt();
+ }
+});
+
+function replaceElementPrompt() {
+ var fromElement = prompt("Enter the element you want to change");
+ // replace spaces with underscores
+ fromElement = fromElement.replace(/ /g, "_");
+ fromElementS = mostSimilarElement(fromElement);
+ if (fromElementS === null || fromElementS === undefined || fromElementS === "") {
+ alert("Element \"" + fromElement + "\" not found! Defaulting to rock.");
+ fromElementS = "rock";
+ };
+
+ var toElement = prompt("Enter what you want to replace \"" + fromElementS + "\" with");
+ // replace spaces with underscores
+ toElement = toElement.replace(/ /g, "_");
+ toElementS = mostSimilarElement(toElement);
+ if (toElementS === null || toElementS === undefined || toElementS === "") {
+ alert("Element \"" + toElement + "\" not found! Defaulting to sand.");
+ toElementS = "sand";
+ };
+ replaceFrom = fromElementS;
+ replaceTo = toElementS;
+ updateReplaceDescriptions();
+}
+
+function updateReplaceDescriptions() {
+ elements.replace.desc = "Changes pixels of a specified type to another specified type.
Currently replacing \"" + replaceFrom + "\" with \"" + replaceTo + "\".
Press [\"] to open the replace prompt.";
+ elements.alt_replace.desc = "Changes pixels of a specified type to another specified type, but keeping their non-element-based properties.
Currently replacing \"" + replaceFrom + "\" with \"" + replaceTo + "\".
Press [\"] to open the replace prompt.";
+ elements.alt_alt_replace.desc = "Changes pixels of a specified type to another specified type, but keeping their non-element-based properties except for color.
Currently replacing \"" + replaceFrom + "\" with \"" + replaceTo + "\".
Press [\"] to open the replace prompt.";
+};
+
+elements.replace = {
+ color: ["#ff0000", "#ff0000", "#ff0000", "#7f00ff", "#0000ff", "#0000ff", "#0000ff"],
+ tool: function(pixel) {
+ if(pixel.element === replaceFrom) {
+ changePixel(pixel,replaceTo,true);
+ };
+ },
+ category: "tools",
+ desc: "Changes pixels of a specified type to another specified type.
Currently replacing \"" + replaceFrom + "\" with \"" + replaceTo + "\".
Press [KEY] to open the replace prompt.",
+};
+
+elements.alt_replace = {
+ color: ["#ffff00", "#ffff00", "#ffff00", "#cf7f4f", "#ff00ff", "#ff00ff", "#ff00ff"],
+ tool: function(pixel) {
+ if(pixel.element === replaceFrom) {
+ pixel.element = replaceTo;
+ };
+ },
+ category: "tools",
+ desc: "Changes pixels of a specified type to another specified type, but keeping their non-element-based properties.
Currently replacing \"" + replaceFrom + "\" with \"" + replaceTo + "\".
Press [KEY] to open the replace prompt.",
+ hidden: true,
+};
+
+elements.alt_alt_replace = {
+ color: ["#00ff00", "#00ff00", "#00ff00", "#cfcf00", "#ff0000", "#ff0000", "#ff0000"],
+ tool: function(pixel) {
+ if(pixel.element === replaceFrom) {
+ pixel.element = replaceTo;
+ pixel.color = pixelColorPick(pixel);
+ };
+ },
+ category: "tools",
+ desc: "Changes pixels of a specified type to another specified type, but keeping their non-element-based properties except for color.
Currently replacing \"" + replaceFrom + "\" with \"" + replaceTo + "\".
Press [KEY] to open the replace prompt.",
+ hidden: true,
+};
\ No newline at end of file