fix out-of-bounds placing
This commit is contained in:
parent
c617d8f92b
commit
97737a16a1
|
@ -182,17 +182,23 @@ class PixelPlainterControls {
|
|||
if (scale < 3) return;
|
||||
|
||||
const curColor = renderer.getColorIndexOfPixel(...cell);
|
||||
if (selectedColor !== curColor) {
|
||||
const { canvasSize } = state.canvas;
|
||||
const [i, j] = getChunkOfPixel(canvasSize, ...cell);
|
||||
const offset = getOffsetOfPixel(canvasSize, ...cell);
|
||||
tryPlacePixel(
|
||||
store,
|
||||
i, j, offset,
|
||||
selectedColor,
|
||||
curColor,
|
||||
);
|
||||
if (selectedColor === curColor) {
|
||||
return;
|
||||
}
|
||||
const { canvasSize } = state.canvas;
|
||||
const [x, y] = cell;
|
||||
const maxCoords = canvasSize / 2;
|
||||
if (x < -maxCoords || x >= maxCoords || y < -maxCoords || y >= maxCoords) {
|
||||
return;
|
||||
}
|
||||
const [i, j] = getChunkOfPixel(canvasSize, x, y);
|
||||
const offset = getOffsetOfPixel(canvasSize, x, y);
|
||||
tryPlacePixel(
|
||||
store,
|
||||
i, j, offset,
|
||||
selectedColor,
|
||||
curColor,
|
||||
);
|
||||
}
|
||||
|
||||
static getMultiTouchDistance(event: TouchEvent) {
|
||||
|
@ -377,7 +383,21 @@ class PixelPlainterControls {
|
|||
this.viewport,
|
||||
[clientX, clientY],
|
||||
);
|
||||
if (!hover || hover[0] !== screenCoor[0] || hover[1] !== screenCoor[1]) {
|
||||
const [x, y] = screenCoor;
|
||||
|
||||
/* out of bounds check */
|
||||
const { canvasSize } = state.canvas;
|
||||
const maxCoords = canvasSize / 2;
|
||||
if (x < -maxCoords || x >= maxCoords
|
||||
|| y < -maxCoords || y >= maxCoords
|
||||
) {
|
||||
if (hover) {
|
||||
store.dispatch(unsetHover(screenCoor));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hover || hover[0] !== x || hover[1] !== y) {
|
||||
store.dispatch(setHover(screenCoor));
|
||||
}
|
||||
if (this.holdPainting && !this.coolDownDelta) {
|
||||
|
|
|
@ -66,10 +66,12 @@ export async function drawByOffsets(
|
|||
*/
|
||||
if (i >= canvasSize / tileSize) {
|
||||
// x out of bounds
|
||||
// (we don't have to check for <0 becaue it is received as uint)
|
||||
throw new Error(2);
|
||||
}
|
||||
if (j >= canvasSize / tileSize) {
|
||||
// y out of bounds
|
||||
// (we don't have to check for <0 becaue it is received as uint)
|
||||
throw new Error(3);
|
||||
}
|
||||
if (canvas.req !== -1) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user