Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OWOP.tool.addToolObject(new OWOP.tool.class('Skip Fill', OWOP.cursors.cursor, OWOP.fx.player.RECT_SELECT_ALIGNED(1), false, function(tool) {
- tool.extra.tickAmount = 9;
- var queue = [];
- var fillingColor = null;
- function tick() {
- const eq = (a, b) => a && b && a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
- const check = (x, y) => {
- if (eq(OWOP.world.getPixel(x, y), fillingColor)) {
- queue.unshift([x, y]);
- return true;
- }
- return false;
- };
- if (!queue.length || !fillingColor) {
- return;
- }
- var selClr = OWOP.player.selectedColor;
- var painted = 0;
- var tickAmount = tool.extra.tickAmount;
- for (var painted = 0; painted < tickAmount && queue.length; painted++) {
- var current = queue.pop();
- var x = current[0];
- var y = current[1];
- var thisClr = OWOP.world.getPixel(x, y);
- if (eq(thisClr, fillingColor) && !eq(thisClr, selClr)) {
- if (!OWOP.world.setPixel(x, y, selClr)) {
- queue.push(current);
- break;
- }
- //i am not going to optimize this lmao
- check(x, y - 1);
- check(x, y + 1);
- check(x - 1, y);
- check(x + 1, y);
- check(x, y - 2);
- check(x, y + 2);
- check(x - 2, y);
- check(x + 2, y);
- check(x - 1, y - 1);
- check(x + 1, y - 1);
- check(x - 1, y + 1);
- check(x + 1, y + 1);
- }
- }
- }
- tool.setEvent('mousedown', mouse => {
- if (!(mouse.buttons & 0b100)) {
- fillingColor = OWOP.world.getPixel(mouse.tileX, mouse.tileY);
- if (fillingColor) {
- queue.push([mouse.tileX, mouse.tileY]);
- tool.setEvent('tick', tick);
- }
- }
- });
- tool.setEvent('mouseup deselect', mouse => {
- if (!mouse || !(mouse.buttons & 0b1)) {
- fillingColor = null;
- queue = [];
- tool.setEvent('tick', null);
- }
- });
- }));
- //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