Advertisement
TheForgotten_GP

Ignore Fill OWOP

Mar 29th, 2024
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. OWOP.tool.addToolObject(new OWOP.tool.class('Skip Fill', OWOP.cursors.cursor, OWOP.fx.player.RECT_SELECT_ALIGNED(1), false, function(tool) {
  2.     tool.extra.tickAmount = 9;
  3.         var queue = [];
  4.         var fillingColor = null;
  5.         function tick() {
  6.             const eq = (a, b) => a && b && a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
  7.             const check = (x, y) => {
  8.                 if (eq(OWOP.world.getPixel(x, y), fillingColor)) {
  9.                     queue.unshift([x, y]);
  10.                     return true;
  11.                 }
  12.                 return false;
  13.             };
  14.  
  15.             if (!queue.length || !fillingColor) {
  16.                 return;
  17.             }
  18.  
  19.             var selClr = OWOP.player.selectedColor;
  20.             var painted = 0;
  21.             var tickAmount = tool.extra.tickAmount;
  22.  
  23.             for (var painted = 0; painted < tickAmount && queue.length; painted++) {
  24.                 var current = queue.pop();
  25.                 var x = current[0];
  26.                 var y = current[1];
  27.                 var thisClr = OWOP.world.getPixel(x, y);
  28.                 if (eq(thisClr, fillingColor) && !eq(thisClr, selClr)) {
  29.                     if (!OWOP.world.setPixel(x, y, selClr)) {
  30.                         queue.push(current);
  31.                         break;
  32.                     }
  33.                     //i am not going to optimize this lmao
  34.                     check(x, y - 1);
  35.                     check(x, y + 1);
  36.                     check(x - 1, y);
  37.                     check(x + 1, y);
  38.                     check(x, y - 2);
  39.                     check(x, y + 2);
  40.                     check(x - 2, y);
  41.                     check(x + 2, y);
  42.                     check(x - 1, y - 1);
  43.                     check(x + 1, y - 1);
  44.                     check(x - 1, y + 1);
  45.                     check(x + 1, y + 1);
  46.                 }
  47.             }
  48.         }
  49.         tool.setEvent('mousedown', mouse => {
  50.             if (!(mouse.buttons & 0b100)) {
  51.                 fillingColor = OWOP.world.getPixel(mouse.tileX, mouse.tileY);
  52.                 if (fillingColor) {
  53.                     queue.push([mouse.tileX, mouse.tileY]);
  54.                     tool.setEvent('tick', tick);
  55.                 }
  56.             }
  57.         });
  58.         tool.setEvent('mouseup deselect', mouse => {
  59.             if (!mouse || !(mouse.buttons & 0b1)) {
  60.                 fillingColor = null;
  61.                 queue = [];
  62.                 tool.setEvent('tick', null);
  63.             }
  64.         });
  65. }));
  66. //ignores the fact its not directly adjecent to the pixels with the same color and fills them with the select one
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement