using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MaskingDeformation : BaseDeformation
{
    public override string DeformationName { get; protected set; } = "Masking";

    public override string Description { get; set; } = "Masking description";

    private float _intensity = 1;
    public override float Intensity
    {
        get
        {
            return _intensity;
        }
        set
        {
            if (value > _intensity)
            {
                _intensity = 1;
            } else if (value < _intensity)
            {
                _intensity = 0;
            }
            
        }
    }

    [SerializeField]
    private ComputeShaderManager computeShaderManager;

    private void Update()
    {
        if (IsDeforming)
        {
            computeShaderManager.Masking(DeformationManager.LocalCurrentPosition, DeformationManager.ScaledAreaOfEffect, Intensity,
                                DeformationManager.MaskedVertices, DeformationManager.CurrentVertices, DeformationManager.CurrentVertexColors, DeformationManager.DeformingMesh);
        }

    }

    public override void AddUndoStep(UndoStack undoStack)
    {
        undoStack.AddStep(new UndoMaskedVertices());
    }

    public override void InitializeDeformation(DeformationManager deformationManager)
    {
        DeformationManager = deformationManager;
        if (computeShaderManager.VerticesCount != deformationManager.CurrentVertexColors.Length)
        {
            computeShaderManager.SetupBuffers(deformationManager.CurrentVertexColors.Length);
        }
    }

    public override void StartDeforming()
    {
        if (IsDeforming)
        {
            return;
        }
        computeShaderManager.StartMasking(DeformationManager.MaskedVertices, DeformationManager.CurrentVertices, DeformationManager.CurrentVertexColors);
        IsDeforming = true;
    }

    public override void StopDeforming()
    {
        IsDeforming = false;
    }
}

