using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;

public static class SaveSystem
{
    private static string path = Application.persistentDataPath + "/joints.sav";

    public static void Save(List<Transform[]> jointsSequence)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        FileStream stream = new FileStream(path, FileMode.Create);

        JointsDataSequence data = new JointsDataSequence(jointsSequence);
        formatter.Serialize(stream, data);
        stream.Close();
    }

    public static JointsDataSequence Load()
    {
        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream stream = new FileStream(path, FileMode.Open);

            JointsDataSequence data = formatter.Deserialize(stream) as JointsDataSequence;
            stream.Close();
            return data;
        } else
        {
            Debug.LogError("Save file not found in " + path);
            return null;
        }
    }
}
