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

export class OverrideContextBehavior extends AbstractDecoratorBehavior {

    __override_context = {};

    /**
     *
     * @param {*} context
     * @param {Behavior} source
     * @return {OverrideContextBehavior}
     */
    static from(context, source) {
        const r = new OverrideContextBehavior();

        r.__override_context = context;
        r.setSource(source);

        return r;
    }

    tick(timeDelta) {
        const s = this.__source.tick(timeDelta);

        return s;
    }

    initialize(context) {
        super.initialize(context);

        const child_context = Object.assign({}, context, this.__override_context);

        this.__source.initialize(child_context);
    }
}
