2024-09-08 13:53:29 +02:00
|
|
|
import { listen } from "rkgk/framework.js";
|
2024-08-24 18:40:16 +02:00
|
|
|
|
2024-09-08 13:53:29 +02:00
|
|
|
function* chunksInRectangle(left, top, right, bottom, chunkSize) {
|
|
|
|
let leftChunk = Math.floor(left / chunkSize);
|
|
|
|
let topChunk = Math.floor(top / chunkSize);
|
|
|
|
let rightChunk = Math.ceil(right / chunkSize);
|
|
|
|
let bottomChunk = Math.ceil(bottom / chunkSize);
|
|
|
|
for (let chunkY = topChunk; chunkY < bottomChunk; ++chunkY) {
|
|
|
|
for (let chunkX = leftChunk; chunkX < rightChunk; ++chunkX) {
|
|
|
|
yield [chunkX, chunkY];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-15 20:01:23 +02:00
|
|
|
|
2024-09-08 13:53:29 +02:00
|
|
|
export function renderToChunksInArea(wall, renderArea, renderToPixmap) {
|
|
|
|
for (let [chunkX, chunkY] of chunksInRectangle(
|
|
|
|
renderArea.left,
|
|
|
|
renderArea.top,
|
|
|
|
renderArea.right,
|
|
|
|
renderArea.bottom,
|
|
|
|
wall.chunkSize,
|
|
|
|
)) {
|
|
|
|
let chunk = wall.getOrCreateChunk(chunkX, chunkY);
|
|
|
|
let translationX = -chunkX * wall.chunkSize;
|
|
|
|
let translationY = -chunkY * wall.chunkSize;
|
|
|
|
let result = renderToPixmap(chunk.pixmap, translationX, translationY);
|
|
|
|
chunk.markModified();
|
|
|
|
if (result.status != "ok") return result;
|
|
|
|
}
|
2024-08-15 20:01:23 +02:00
|
|
|
|
2024-09-08 13:53:29 +02:00
|
|
|
return { status: "ok" };
|
|
|
|
}
|
2024-08-10 23:13:20 +02:00
|
|
|
|
2024-09-08 13:53:29 +02:00
|
|
|
export function dotterRenderArea(wall, dotter) {
|
|
|
|
let halfPaintArea = wall.paintArea / 2;
|
|
|
|
return {
|
|
|
|
left: dotter.toX - halfPaintArea,
|
|
|
|
top: dotter.toY - halfPaintArea,
|
|
|
|
right: dotter.toX + halfPaintArea,
|
|
|
|
bottom: dotter.toY + halfPaintArea,
|
|
|
|
};
|
|
|
|
}
|
2024-08-10 23:13:20 +02:00
|
|
|
|
2024-09-08 13:53:29 +02:00
|
|
|
export function selfController(interactionQueue, wall, event) {
|
|
|
|
let renderArea = null;
|
|
|
|
return {
|
|
|
|
async runScribble(renderToPixmap) {
|
|
|
|
interactionQueue.push({ kind: "scribble" });
|
|
|
|
if (renderArea != null) {
|
|
|
|
return renderToChunksInArea(wall, renderArea, renderToPixmap);
|
|
|
|
} else {
|
|
|
|
console.debug("render area is empty, nothing will be rendered");
|
2024-08-15 20:01:23 +02:00
|
|
|
}
|
2024-09-08 13:53:29 +02:00
|
|
|
return { status: "ok" };
|
|
|
|
},
|
2024-08-19 23:56:11 +02:00
|
|
|
|
2024-09-08 13:53:29 +02:00
|
|
|
async runDotter() {
|
|
|
|
let dotter = await event.continueAsDotter();
|
|
|
|
interactionQueue.push({
|
|
|
|
kind: "dotter",
|
|
|
|
from: { x: dotter.fromX, y: dotter.fromY },
|
|
|
|
to: { x: dotter.toX, y: dotter.toY },
|
|
|
|
num: dotter.num,
|
|
|
|
});
|
|
|
|
renderArea = dotterRenderArea(wall, dotter);
|
|
|
|
return dotter;
|
|
|
|
},
|
|
|
|
};
|
2024-08-10 23:13:20 +02:00
|
|
|
}
|