introduce tags, structs, and reticles

this was meant to be split into smaller changes, but I realised I edited my existing revision too late.
This commit is contained in:
りき萌 2024-09-08 13:53:29 +02:00
parent 8356b6c750
commit 5b7d9586ea
26 changed files with 1113 additions and 351 deletions

View file

@ -113,6 +113,12 @@ export class Pixmap {
}
}
// NOTE: This must be kept in sync with ContKind on the haku-wasm side.
export const ContKind = {
Scribble: 0,
Dotter: 1,
};
export class Haku {
#pInstance = 0;
#pBrush = 0;
@ -206,17 +212,49 @@ export class Haku {
}
}
evalBrush() {
return this.#statusCodeToResultObject(w.haku_eval_brush(this.#pInstance, this.#pBrush));
beginBrush() {
return this.#statusCodeToResultObject(w.haku_begin_brush(this.#pInstance, this.#pBrush));
}
renderValue(pixmap, translationX, translationY) {
expectedContKind() {
return w.haku_cont_kind(this.#pInstance);
}
contScribble(pixmap, translationX, translationY) {
return this.#statusCodeToResultObject(
w.haku_render_value(this.#pInstance, pixmap.ptr, translationX, translationY),
w.haku_cont_scribble(this.#pInstance, pixmap.ptr, translationX, translationY),
);
}
resetVm() {
w.haku_reset_vm(this.#pInstance);
contDotter({ fromX, fromY, toX, toY, num }) {
return this.#statusCodeToResultObject(
w.haku_cont_dotter(this.#pInstance, fromX, fromY, toX, toY, num),
);
}
async evalBrush(options) {
let { runDotter, runScribble } = options;
let result;
result = this.beginBrush();
if (result.status != "ok") return result;
while (this.expectedContKind() != ContKind.Invalid) {
switch (this.expectedContKind()) {
case ContKind.Scribble:
result = await runScribble((pixmap, translationX, translationY) => {
return this.contScribble(pixmap, translationX, translationY);
});
return result;
case ContKind.Dotter:
let dotter = await runDotter();
result = this.contDotter(dotter);
if (result.status != "ok") return result;
break;
}
}
return { status: "ok" };
}
}