Skip to content

Commit abda4f2

Browse files
committed
Previous floodfill improvements broke stuff again ...
1 parent 705aa1a commit abda4f2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

internal/frontend/resources/floodfill.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,15 @@ function pixelCompareAndSet(i, targetcolor, fillcolor, data) {
7171
return false;
7272
};
7373

74-
function fillUint8ClampedArray(data, x, y, color, width, height) {
75-
if (!(data instanceof Uint8ClampedArray)) throw new Error("data must be an instance of Uint8ClampedArray");
74+
function floodfillUint8ClampedArray(data, x, y, color, width, height) {
7675
if (isNaN(width) || width < 1) throw new Error("argument 'width' must be a positive integer");
7776
if (isNaN(height) || height < 1) throw new Error("argument 'height' must be a positive integer");
7877
if (isNaN(x) || x < 0) throw new Error("argument 'x' must be a positive integer");
7978
if (isNaN(y) || y < 0) throw new Error("argument 'y' must be a positive integer");
8079
if (width * height * 4 !== data.length) throw new Error("width and height do not fit Uint8ClampedArray dimensions");
8180

82-
var xi = Math.floor(x);
83-
var yi = Math.floor(y);
81+
const xi = Math.floor(x);
82+
const yi = Math.floor(y);
8483

8584
return floodfillData(data, xi, yi, color, width, height);
8685
};

internal/frontend/templates/lobby.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,15 @@
12501250
} else if (parsed.type === "line") {
12511251
drawLine(context, parsed.data.fromX * scaleDownFactor(), parsed.data.fromY * scaleDownFactor(), parsed.data.toX * scaleDownFactor(), parsed.data.toY * scaleDownFactor(), parsed.data.color, parsed.data.lineWidth * scaleDownFactor());
12521252
} else if (parsed.type === "fill") {
1253-
floodfillContext(context, parsed.data.x * scaleDownFactor(), parsed.data.y * scaleDownFactor(), parsed.data.color);
1253+
if (floodfillUint8ClampedArray(
1254+
imageData.data,
1255+
parsed.data.x * scaleDownFactor(),
1256+
parsed.data.y * scaleDownFactor(),
1257+
parsed.data.color,
1258+
imageData.width,
1259+
imageData.height)) {
1260+
context.putImageData(imageData, 0, 0);
1261+
}
12541262
} else if (parsed.type === "clear-drawing-board") {
12551263
clear(context);
12561264
} else if (parsed.type === "next-turn") {
@@ -1766,7 +1774,7 @@
17661774
.forEach(drawElement => {
17671775
const drawData = drawElement.data;
17681776
if (drawElement.type === "fill") {
1769-
fillUint8ClampedArray(
1777+
floodfillUint8ClampedArray(
17701778
imageData.data,
17711779
drawData.x * scaleFactor, drawData.y * scaleFactor,
17721780
drawData.color,
@@ -2005,7 +2013,7 @@
20052013
}, false);
20062014

20072015
function fillAndSendEvent(context, x, y, color) {
2008-
if (floodfillData(imageData.data, x, y, color, imageData.width, imageData.height)) {
2016+
if (floodfillUint8ClampedArray(imageData.data, x, y, color, imageData.width, imageData.height)) {
20092017
context.putImageData(imageData, 0, 0);
20102018
const fillInstruction = {
20112019
type: "fill",

0 commit comments

Comments
 (0)