import { PixiComponent, withPixiApp } from '@inlet/react-pixi'
import { memory } from 'golem/lib_bg.wasm'
import * as PIXI from 'pixi.js'
const behavior = {
create: () => new PIXI.Graphics(),
applyProps: (instance, _, props) => {
const { cellSize, colors, rows, cols, cellsPtr, area } = props
const cells = new Uint8Array(memory.buffer, cellsPtr, area)
for (let row = 0; row < rows; row += 1) {
for (let col = 0; col < cols; col += 1) {
const state = cells[row * cols + col]
if (state > 0) {
instance.beginFill(colors[state])
instance.drawRect(
col * cellSize,
row * cellSize,
cellSize,
cellSize
)
instance.endFill()
}
}
}
}
}
export default withPixiApp(PixiComponent('GolemCells', behavior))