import { MarkerNodeTransformer } from "./MarkerNodeTransformer.js";

export class MarkerNodeTransformerSequence extends MarkerNodeTransformer {

    /**
     *
     * @type {MarkerNodeTransformer[]}
     */
    elements = [];

    static from(elements) {
        const r = new MarkerNodeTransformerSequence();

        r.elements = elements;

        return r;
    }

    initialize(grid, seed) {
        const elements = this.elements;
        const n = elements.length;

        for (let i = 0; i < n; i++) {
            const e = elements[i];
            e.initialize(grid, seed);
        }
    }

    transform(node, grid) {
        const elements = this.elements;
        const element_count = elements.length;

        let n = node;

        // transform
        for (let j = 0; j < element_count; j++) {
            const transformer = elements[j];

            n = transformer.transform(n, grid);
        }

        return n;
    }
}
