True fill tool (fix).

Now u can fill unlimited.

  1. // ==UserScript==
  2. // @name True fill tool (fix).
  3. // @version 0.1
  4. // @description Now u can fill unlimited.
  5. // @author nab aka NoT BoT
  6. // @match *.ourworldofpixels.com/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace https://greasyfork.org/users/228105
  10. // ==/UserScript==
  11. function install() {
  12. let move = (x, y) => {
  13. OWOP.net.protocol.lastSentX = x * 16;
  14. OWOP.net.protocol.lastSentY = y * 16;
  15. OWOP.net.connection.send(new Int32Array([x * 16, y * 16, 0]).buffer);
  16. };
  17. OWOP.tool.addToolObject(new OWOP.tool.class('True Fill', OWOP.cursors.fill, OWOP.fx.player.NONE, false, function (tool) {
  18. tool.extra.tickAmount = 6;
  19. var queue = [];
  20. var fillingColor = null;
  21. var defaultFx = OWOP.fx.player.RECT_SELECT_ALIGNED(1);
  22. tool.setFxRenderer(function (fx, ctx, time) {
  23. ctx.globalAlpha = 0.8;
  24. ctx.strokeStyle = fx.extra.player.htmlRgb;
  25. var z = OWOP.camera.zoom;
  26. if (!fillingColor || !fx.extra.isLocalPlayer) {
  27. defaultFx(fx, ctx, time);
  28. } else {
  29. ctx.beginPath();
  30. for (var i = 0; i < queue.length; i++) {
  31. ctx.rect((queue[i][0] - OWOP.camera.x) * z, (queue[i][1] - OWOP.camera.y) * z, z, z);
  32. }
  33. ctx.stroke();
  34. }
  35. });
  36. function tick() {
  37. var eq = function eq(a, b) {
  38. return a && b && a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
  39. };
  40. var check = function check(x, y) {
  41. if (eq(OWOP.world.getPixel(x, y), fillingColor)) {
  42. queue.unshift([x, y]);
  43. return true;
  44. }
  45. return false;
  46. };
  47.  
  48. if (!queue.length || !fillingColor) {
  49. return;
  50. }
  51.  
  52. var selClr = OWOP.player.selectedColor;
  53. var painted = 0;
  54. var tickAmount = tool.extra.tickAmount;
  55. for (var painted = 0; painted < tickAmount && queue.length; painted++) {
  56. var current = queue.pop();
  57. var x = current[0];
  58. var y = current[1];
  59. var thisClr = OWOP.world.getPixel(x, y);
  60. if (eq(thisClr, fillingColor) && !eq(thisClr, selClr)) {
  61. move(x,y);
  62. if (!OWOP.world.setPixel(x, y, selClr)) {
  63. queue.push(current);
  64. break;
  65. }
  66.  
  67. // diamond check first
  68. var top = check(x, y - 1);
  69. var bottom = check(x, y + 1);
  70. var left = check(x - 1, y);
  71. var right = check(x + 1, y);
  72.  
  73. // if corners are not closed by parts of the diamond, then they can be accessed
  74. if (top && left) {
  75. check(x - 1, y - 1);
  76. }
  77. if (top && right) {
  78. check(x + 1, y - 1);
  79. }
  80. if (bottom && left) {
  81. check(x - 1, y + 1);
  82. }
  83. if (bottom && right) {
  84. check(x + 1, y + 1);
  85. }
  86.  
  87. // Shape diamond, infra not like
  88. /*check(x , y - 1);
  89. check(x - 1, y );
  90. check(x + 1, y );
  91. check(x , y + 1);*/
  92. }
  93. }
  94. }
  95. tool.setEvent('mousedown', function (mouse) {
  96. if (!(mouse.buttons & 4)) {
  97. fillingColor = OWOP.world.getPixel(mouse.tileX, mouse.tileY);
  98. if (fillingColor) {
  99. queue.push([mouse.tileX, mouse.tileY]);
  100. tool.setEvent('tick', tick);
  101. }
  102. }
  103. });
  104. tool.setEvent('mouseup deselect', function (mouse) {
  105. if (!mouse || !(mouse.buttons & 1)) {
  106. fillingColor = null;
  107. queue = [];
  108. tool.setEvent('tick', null);
  109. }
  110. });
  111. }));
  112. }
  113. setTimeout(() => {
  114. install()
  115. },5000)