dimden

Unpixel Tool for OWOP

Nov 30th, 2018
1,424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Unpixel Tool
  3. // @version      1.0.2
  4. // @description  Tool for replacing some pixels.
  5. // @authors      dimden
  6. // @match        *.ourworldofpixels.com/*
  7. // @match        augustberchelmann.com/owop/*
  8. // @match        https://owoppa.netlify.com/*
  9. // @match        https://owoppa.000webhostapp.com/*
  10. // @grant        none
  11. // ==/UserScript==
  12.  
  13. // 90% shit, 10% tool!
  14. // Sometimes I need to fill only one colour, so I made this poopy tool for this.
  15. // You select colour that you only need to change, and just draw! It will replace only colour that you need.
  16. // by dimden | fluffyboi#1877
  17.  
  18. // How it works: http://recordit.co/r2OcNYeYCW
  19.  
  20. // 1.0.1 - You can now Reverse tool! It will replace all colours but not colour that you need.
  21. // 1.0.2 - Now you can use it in Console and TamperMonkey, and it will work everywhere.
  22.  
  23. var UnpixelTool = function () {
  24.  OWOP.tool.addToolObject(new OWOP.tool.class('Unpixel', OWOP.cursors.cursor, OWOP.fx.player.RECT_SELECT_ALIGNED(1), false, function(tool){
  25.    function hex2rgb(hex) {
  26.   return ['0x' + hex[1] + hex[2] | 0, '0x' + hex[3] + hex[4] | 0, '0x' + hex[5] + hex[6] | 0];
  27. };
  28.  
  29. document.getElementById("palette-bg").insertAdjacentHTML('afterEnd',
  30. `
  31. <input id="unpixel-check" style="position: absolute;left:42px;top: 370px;background-color: rgba(231,24,24,0.5);border-style: outset;font-size: 15px; z-index: 999" type="checkbox"></input>
  32.  
  33. `);
  34.  
  35.  
  36.    function componentToHex(c) {
  37.     var hex = c.toString(16);
  38.     return hex.length == 1 ? "0" + hex : hex;
  39.   }
  40.    function rgb2hex(r, g, b) {
  41.   return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
  42. };
  43. function arraysEqual(a, b) {
  44.   if (a === b) return true;
  45.   if (a == null || b == null) return false;
  46.   if (a.length != b.length) return false;
  47.   for (var i = 0; i < a.length; ++i) {
  48.     if (a[i] !== b[i]) return false;
  49.   }
  50.   return true;
  51. }
  52.    tool.setEvent("select", function() {
  53.      document.getElementById("tool-unpixel").innerHTML = `
  54.      <input type="color" id="unpixel-input"></input>`;
  55.      document.getElementById("unpixel-input").value = rgb2hex(OWOP.player.selectedColor[0],OWOP.player.selectedColor[1],OWOP.player.selectedColor[2]);
  56.      document.getElementById("unpixel-input").addEventListener("change", function () {
  57.      unpixel_color = hex2rgb(document.getElementById("unpixel-input").value);
  58.    }, false);
  59.     unpixel_color = hex2rgb(document.getElementById("unpixel-input").value);
  60.  });
  61.    tool.setEvent("deselect", function() {
  62.      document.getElementById("tool-unpixel").innerHTML = `<div style="background-image: url(&quot;http://ourworldofpixels.com/img/toolset.png&quot;); background-position: 0px 0px;"></div>`;
  63.    });
  64.    tool.setEvent("mousemove mousedown", function(mouse, event) {if(mouse.buttons != 0){if(!document.getElementById("unpixel-check").checked){if(arraysEqual(OWOP.world.getPixel(OWOP.mouse.tileX,OWOP.mouse.tileY),unpixel_color)) {OWOP.world.setPixel(OWOP.world.setPixel(OWOP.mouse.tileX,OWOP.mouse.tileY,OWOP.player.selectedColor,1))}}else{if(!arraysEqual(OWOP.world.getPixel(OWOP.mouse.tileX,OWOP.mouse.tileY),unpixel_color)) {OWOP.world.setPixel(OWOP.world.setPixel(OWOP.mouse.tileX,OWOP.mouse.tileY,OWOP.player.selectedColor,1))}};}});
  65. }));
  66. };
  67.  
  68. navData = window.performance.getEntriesByType("navigation");
  69. if (navData.length > 0 && navData[0].loadEventEnd > 0)
  70. {
  71.   UnpixelTool();
  72. } else {
  73.   window.addEventListener('load', function() {
  74.       setTimeout(UnpixelTool, 1234);
  75.   });
  76. }
Advertisement
Add Comment
Please, Sign In to add comment