import { EnginePlugin } from "../../../plugin/EnginePlugin.js";
import { Gizmo } from "./Gizmo.js";

export class GizmoRenderingPlugin extends EnginePlugin {
    async startup() {
        this.__layer = this.engine.graphics.layers.create('debug');

        this.__layer.buildVisibleSet = (destination, destination_offset, view) => {
            return Gizmo.collect(destination, destination_offset, view);
        };

        this.engine.graphics.on.postRender.add(Gizmo.clear, Gizmo);

        return super.startup();
    }

    async shutdown() {
        this.engine.graphics.layers.remove(this.__layer);

        this.engine.graphics.on.postRender.remove(Gizmo.clear, Gizmo);

        return super.shutdown();
    }

}
