rkgk/static/painter.js

37 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-08-10 23:13:20 +02:00
export class Painter {
constructor(paintArea) {
this.paintArea = paintArea;
}
2024-08-15 20:01:23 +02:00
renderBrushToWall(haku, centerX, centerY, wall) {
let evalResult = haku.evalBrush();
if (evalResult.status != "ok") return evalResult;
let left = centerX - this.paintArea / 2;
let top = centerY - this.paintArea / 2;
let leftChunk = Math.floor(left / wall.chunkSize);
let topChunk = Math.floor(top / wall.chunkSize);
let rightChunk = Math.ceil((left + this.paintArea) / wall.chunkSize);
let bottomChunk = Math.ceil((top + this.paintArea) / wall.chunkSize);
for (let chunkY = topChunk; chunkY < bottomChunk; ++chunkY) {
for (let chunkX = leftChunk; chunkX < rightChunk; ++chunkX) {
let x = Math.floor(-chunkX * wall.chunkSize + centerX);
let y = Math.floor(-chunkY * wall.chunkSize + centerY);
let chunk = wall.getOrCreateChunk(chunkX, chunkY);
2024-08-10 23:13:20 +02:00
2024-08-15 20:01:23 +02:00
let renderResult = haku.renderValue(chunk.pixmap, x, y);
if (renderResult.status != "ok") return renderResult;
}
}
haku.resetVm();
2024-08-10 23:13:20 +02:00
2024-08-15 20:01:23 +02:00
for (let y = topChunk; y < bottomChunk; ++y) {
for (let x = leftChunk; x < rightChunk; ++x) {
let chunk = wall.getChunk(x, y);
chunk.syncFromPixmap();
}
}
2024-08-10 23:13:20 +02:00
}
}