dimden

Untitled

Nov 4th, 2018
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. OWOP.tool.addToolObject(new OWOP.tool.class('Big checker fill', OWOP.cursors.wand, OWOP.fx.player.NONE, OWOP.RANK.MODERATOR, function (tool) {
  2. tool.extra.tickAmount = 32;
  3. var queue = [];
  4. var fillingColor = null;
  5. var defaultFx = OWOP.fx.player.RECT_SELECT_ALIGNED(1);
  6. tool.setFxRenderer(function (fx, ctx, time) {
  7. ctx.globalAlpha = 0.8;
  8. ctx.strokeStyle = fx.extra.player.htmlRgb;
  9. var z = OWOP.camera.zoom;
  10. if (!fillingColor || !fx.extra.isLocalPlayer)
  11. defaultFx(fx, ctx, time);
  12. else {
  13. ctx.beginPath();
  14. for (var i = 0; i < queue.length; i++)
  15. ctx.rect((queue[i][0] - OWOP.camera.x) * z, (queue[i][1] - OWOP.camera.y) * z, z, z);
  16. ctx.stroke();
  17. }
  18. });
  19. function tick() {
  20. var eq = function eq(a, b) {
  21. return a && b && a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
  22. };
  23. var slientCheck = function slientCheck(x, y) {
  24. return eq(OWOP.world.getPixel(x, y), fillingColor);
  25. }
  26. var check = function check(x, y) {
  27. if (slientCheck(x, y)) {
  28. queue.unshift([x, y]);
  29. return true;
  30. }
  31. return false;
  32. };
  33.  
  34. if (!queue.length || !fillingColor) {
  35. return;
  36. }
  37.  
  38. var selClr = OWOP.player.selectedColor;
  39. var painted = 0;
  40. var tickAmount = tool.extra.tickAmount;
  41. for (var painted = 0; painted < tickAmount && queue.length; painted++) {
  42. var current = queue.pop();
  43. var x = current[0];
  44. var y = current[1];
  45. var thisClr = OWOP.world.getPixel(x, y);
  46. if (eq(thisClr, fillingColor) && !eq(thisClr, selClr)) {
  47. if (!OWOP.world.setPixel(x, y, selClr)) {
  48. queue.push(current);
  49. break;
  50. }
  51.  
  52. var top = slientCheck(x, y - 1);
  53. var bottom = slientCheck(x, y + 1);
  54. var left = slientCheck(x - 1, y);
  55. var right = slientCheck(x + 1, y);
  56.  
  57. if (right) {
  58. check(x + 2, y);
  59. }
  60. if (bottom && right) {
  61. check(x + 2, y + 2);
  62. }
  63. if (bottom) {
  64. check(x, y + 2);
  65. }
  66. if (bottom && left) {
  67. check(x - 2, y + 2);
  68. }
  69. if (left) {
  70. check(x - 2, y);
  71. }
  72. if (top && left) {
  73. check(x - 2, y - 2);
  74. }
  75. if (top) {
  76. check(x, y - 2);
  77. }
  78. if (top && right) {
  79. check(x + 2, y - 2);
  80. }
  81. }
  82. }
  83. }
  84. tool.setEvent('mousedown', function (mouse) {
  85. if (!(mouse.buttons & 4)) {
  86. fillingColor = OWOP.world.getPixel(mouse.tileX, mouse.tileY);
  87. if (fillingColor) {
  88. queue.push([mouse.tileX, mouse.tileY]);
  89. tool.setEvent('tick', tick);
  90. }
  91. }
  92. });
  93. tool.setEvent('mouseup deselect', function (mouse) {
  94. if (!mouse || !(mouse.buttons & 1)) {
  95. fillingColor = null;
  96. queue = [];
  97. tool.setEvent('tick', null);
  98. }
  99. });
  100. }));
Advertisement
Add Comment
Please, Sign In to add comment