forked from ppfun/pixelplanet
care about canvas the template is on
This commit is contained in:
parent
d07f20047a
commit
286ccee62e
|
@ -415,7 +415,8 @@ class PixelPainterControls {
|
||||||
return renderer.getColorIndexOfPixel(...cell, true);
|
return renderer.getColorIndexOfPixel(...cell, true);
|
||||||
}
|
}
|
||||||
if (state.gui.holdPaint === HOLD_PAINT.OVERLAY) {
|
if (state.gui.holdPaint === HOLD_PAINT.OVERLAY) {
|
||||||
const rgb = templateLoader.getColorOfPixel(...cell);
|
const { canvasId } = state.canvas;
|
||||||
|
const rgb = templateLoader.getColorOfPixel(canvasId, ...cell);
|
||||||
if (!rgb) {
|
if (!rgb) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -557,7 +557,7 @@ class Renderer2D extends Renderer {
|
||||||
if (viewscale >= 5 && state.templates.ovEnabled
|
if (viewscale >= 5 && state.templates.ovEnabled
|
||||||
&& state.templates.oSmallPxls
|
&& state.templates.oSmallPxls
|
||||||
) {
|
) {
|
||||||
renderSmallPOverlay(viewport, _view, viewscale);
|
renderSmallPOverlay(state, viewport, _view, viewscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showGrid && viewscale >= 8) {
|
if (showGrid && viewscale >= 8) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ export function renderOverlay(
|
||||||
scaleThreshold,
|
scaleThreshold,
|
||||||
) {
|
) {
|
||||||
if (!templateLoader.ready) return;
|
if (!templateLoader.ready) return;
|
||||||
const { canvasSize } = state.canvas;
|
const { canvasSize, canvasId } = state.canvas;
|
||||||
// world coordinates of center of center chunk
|
// world coordinates of center of center chunk
|
||||||
const [x, y] = centerChunk
|
const [x, y] = centerChunk
|
||||||
.map((z) => z * TILE_SIZE / tiledScale
|
.map((z) => z * TILE_SIZE / tiledScale
|
||||||
|
@ -123,7 +123,7 @@ export function renderOverlay(
|
||||||
const horizontalRadius = width / 2 / scale;
|
const horizontalRadius = width / 2 / scale;
|
||||||
const verticalRadius = height / 2 / scale;
|
const verticalRadius = height / 2 / scale;
|
||||||
const templates = templateLoader.getTemplatesInView(
|
const templates = templateLoader.getTemplatesInView(
|
||||||
x, y, horizontalRadius, verticalRadius,
|
canvasId, x, y, horizontalRadius, verticalRadius,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!templates.length) return;
|
if (!templates.length) return;
|
||||||
|
@ -154,17 +154,19 @@ export function renderOverlay(
|
||||||
* high scale values
|
* high scale values
|
||||||
*/
|
*/
|
||||||
export function renderSmallPOverlay(
|
export function renderSmallPOverlay(
|
||||||
|
state,
|
||||||
$viewport,
|
$viewport,
|
||||||
view,
|
view,
|
||||||
scale,
|
scale,
|
||||||
) {
|
) {
|
||||||
if (!templateLoader.ready) return;
|
if (!templateLoader.ready) return;
|
||||||
|
const { canvasId } = state.canvas;
|
||||||
const [x, y] = view;
|
const [x, y] = view;
|
||||||
const { width, height } = $viewport;
|
const { width, height } = $viewport;
|
||||||
const horizontalRadius = width / 2 / scale;
|
const horizontalRadius = width / 2 / scale;
|
||||||
const verticalRadius = height / 2 / scale;
|
const verticalRadius = height / 2 / scale;
|
||||||
const templates = templateLoader.getTemplatesInView(
|
const templates = templateLoader.getTemplatesInView(
|
||||||
x, y, horizontalRadius, verticalRadius,
|
canvasId, x, y, horizontalRadius, verticalRadius,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!templates.length) return;
|
if (!templates.length) return;
|
||||||
|
|
|
@ -79,10 +79,11 @@ class TemplateLoader {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getColorOfPixel(x, y) {
|
getColorOfPixel(canvasId, x, y) {
|
||||||
const templatesInView = this.#store.getState().templates.list
|
const templatesInView = this.#store.getState().templates.list
|
||||||
.filter((template) => (
|
.filter((template) => (
|
||||||
template.enabled && template.x < x && template.y < y
|
template.enabled && template.canvasId === canvasId
|
||||||
|
&& template.x < x && template.y < y
|
||||||
&& template.x + template.width > x
|
&& template.x + template.width > x
|
||||||
&& template.y + template.height > y
|
&& template.y + template.height > y
|
||||||
));
|
));
|
||||||
|
@ -101,14 +102,15 @@ class TemplateLoader {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTemplatesInView(x, y, horizontalRadius, verticalRadius) {
|
getTemplatesInView(canvasId, x, y, horizontalRadius, verticalRadius) {
|
||||||
const topX = x - horizontalRadius;
|
const topX = x - horizontalRadius;
|
||||||
const topY = y - verticalRadius;
|
const topY = y - verticalRadius;
|
||||||
const bottomX = x + horizontalRadius;
|
const bottomX = x + horizontalRadius;
|
||||||
const bottomY = y + verticalRadius;
|
const bottomY = y + verticalRadius;
|
||||||
|
|
||||||
return this.#store.getState().templates.list.filter((template) => (
|
return this.#store.getState().templates.list.filter((template) => (
|
||||||
template.enabled && template.x < bottomX && template.y < bottomY
|
template.enabled && template.canvasId === canvasId
|
||||||
|
&& template.x < bottomX && template.y < bottomY
|
||||||
&& template.x + template.width > topX
|
&& template.x + template.width > topX
|
||||||
&& template.y + template.height > topY
|
&& template.y + template.height > topY
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user