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

public class SerializableElement : MonoBehaviour {
    public string prefabPath;

    public void BeforeSave(LevelElement element)
    {
        BlockedAreaScript bas = GetComponent<BlockedAreaScript>();
        if (bas != null)
        {
            element.worldPosition1 = bas.worldPosition1;
            element.worldPosition2 = bas.worldPosition2;
        }

        VictoryAreaScript vas = GetComponent<VictoryAreaScript>();
        if (vas != null)
        {
            element.worldPosition1 = vas.worldPosition1;
            element.worldPosition2 = vas.worldPosition2;
        }

        LevelWall wall = GetComponent<LevelWall>();
        if (wall != null)
        {
            element.worldPosition1 = wall.worldPosition1;
            element.worldPosition2 = wall.worldPosition2;
        }
    }

    public void AfterLoad(LevelElement element)
    {
        BlockedAreaScript bas = GetComponent<BlockedAreaScript>();
        if (bas != null)
        {
            bas.worldPosition1 = element.worldPosition1;
            bas.worldPosition2 = element.worldPosition2;
            bas.loadedFromDisk = true;
        }

        VictoryAreaScript vas = GetComponent<VictoryAreaScript>();
        if (vas != null)
        {
            vas.worldPosition1 = element.worldPosition1;
            vas.worldPosition2 = element.worldPosition2;
            vas.loadedFromDisk = true;
        }

        LevelWall wall = GetComponent<LevelWall>();
        if (wall != null)
        {
            wall.worldPosition1 = element.worldPosition1;
            wall.worldPosition2 = element.worldPosition2;
            wall.loadedFromDisk = true;
        }
    }
}
