post init

This commit is contained in:
2023-10-26 01:14:35 -06:00
parent 95afbf9bd3
commit 65a34f960c
3 changed files with 96 additions and 61 deletions

View File

@@ -2,13 +2,20 @@
import { Constants } from "./geometry/constants.ts";
import { Vector } from "./geometry/vector.ts";
import { postInit } from "./postInit.ts";
import { ZoomableDoodler } from "./zoomableCanvas.ts";
export const init = (opt: IDoodlerOptions, zoomable: boolean) => {
export const init = (
opt: IDoodlerOptions,
zoomable: boolean,
postInit?: postInit,
) => {
if (window.doodler) {
throw "Doodler has already been initialized in this window";
}
window.doodler = zoomable ? new ZoomableDoodler(opt) : new Doodler(opt);
window.doodler = zoomable
? new ZoomableDoodler(opt, postInit)
: new Doodler(opt, postInit);
window.doodler.init();
};
@@ -49,7 +56,7 @@ export class Doodler {
canvas,
bg,
framerate,
}: IDoodlerOptions) {
}: IDoodlerOptions, postInit?: postInit) {
if (!canvas) {
canvas = document.createElement("canvas");
document.body.append(canvas);
@@ -66,6 +73,8 @@ export class Doodler {
const ctx = canvas.getContext("2d");
if (!ctx) throw "Unable to initialize Doodler: Canvas context not found";
this.ctx = ctx;
postInit?.(this.ctx);
}
init() {