15 lines
646 B
TypeScript
15 lines
646 B
TypeScript
|
|
// Paints the map's village pictures off the main thread, one look at a time, and hands each
|
||
|
|
// back as a PNG the moment it is done (useMapTiles).
|
||
|
|
import { MAP_LOOKS, mapTileDrawing, paintTile } from '../diorama/mapTiles'
|
||
|
|
|
||
|
|
self.onmessage = async (e: MessageEvent<{ ids: string[]; size: number }>) => {
|
||
|
|
const { ids, size } = e.data
|
||
|
|
for (const id of ids) {
|
||
|
|
const look = MAP_LOOKS.find((l) => l.id === id)
|
||
|
|
if (!look) continue
|
||
|
|
const canvas = new OffscreenCanvas(size, size)
|
||
|
|
paintTile(canvas.getContext('2d')!, mapTileDrawing(look), size)
|
||
|
|
self.postMessage({ id, blob: await canvas.convertToBlob({ type: 'image/png' }) })
|
||
|
|
}
|
||
|
|
}
|