import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
import { Action } from "../../../src/core/process/undo/Action.js";

class TransformModifyAction extends Action {
    /**
     *
     * @param entity
     * @param {Transform} modified
     * @constructor
     */
    constructor(entity, modified) {
        super();

        this.oldState = null;
        this.modified = modified;
        this.entity = entity;
    }

    computeByteSize() {
        return 280;
    }

    /**
     *
     * @param {Editor} editor
     */
    async apply(editor) {
        const entityManager = editor.engine.entityManager;

        const component = entityManager.getComponent(this.entity, Transform);

        this.oldState = component.clone();

        component.copy(this.modified);
    }

    async revert(editor) {
        const entityManager = editor.engine.entityManager;

        const component = entityManager.getComponent(this.entity, Transform);

        component.copy(this.oldState);
    }
}

export default TransformModifyAction;
