<commit_before>﻿using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
using URSA.Save;
#if UNITY_EDITOR
using UnityEditor; 
#endif
using URSA;
using System.IO;

public class PersistentDataSystem : MonoBehaviour {


    #region SINGLETON
    private static PersistentDataSystem _instance;
    public static PersistentDataSystem instance
    {
        get {
            if (!_instance) _instance = GameObject.FindObjectOfType<PersistentDataSystem>();
            return _instance;
        }
    }
    #endregion

    public string FileName = "persistentGameData";
    public DataPath datapath;
    public string customDataPath;
    public string folderPath = "PersistenData";
    public string extension = ".data";

    public static event Action OnPersistentDataLoaded = delegate { };

    public static void MakePersistent(Entity entity) {
        UnityEngine.Object.DontDestroyOnLoad(entity.gameObject);
        entity.transform.parent = instance.transform;
    }


#if     UNITY_EDITOR
    [MenuItem(URSAConstants.PATH_MENUITEM_ROOT + URSAConstants.PATH_MENUITEM_PERSISTENT + URSAConstants.PATH_MENUITEM_PERSISTENT_SAVE)] 
#endif
    public static void Save() {
        instance.SaveTo();
    }



#if UNITY_EDITOR
    [MenuItem(URSAConstants.PATH_MENUITEM_ROOT + URSAConstants.PATH_MENUITEM_PERSISTENT + URSAConstants.PATH_MENUITEM_PERSISTENT_LOAD)] 
#endif
    public static void Load() {
        instance.LoadFrom();
    }

    static string getSystemPath() {
        var sys = PersistentDataSystem.instance;
        string path = String.Empty;
        switch (sys.datapath) {
            case DataPath.persistent: {
                    path = Application.persistentDataPath;
                }
                break;
            case DataPath.inRootFolder: {
                    path = Application.dataPath;
                }
                break;
            case DataPath.custom: {
                    path = sys.customDataPath;
                }
                break;
            default:
                break;
        }
        return path + "/" + URSASettings.current.CustomDataFolder;
    }

    public void SaveTo() {
        SaveObject file = SaveSystem.CreateSaveObjectFromPersistenData();
        PersistentDataInfo info = new PersistentDataInfo();
        info.profileName = "profile";
        info.creationDate = DateTime.Now;
        info.data = file;

        string path = getSystemPath() + "/" + folderPath;

        if (!Directory.Exists(path)) {
            Directory.CreateDirectory(path);
        }

        SerializationHelper.Serialize(info, path + "/" + FileName + extension, true);
    }

    public void LoadFrom() {

        transform.DestroyChildren();
        this.OneFrameDelay(completeLoad);
    }
<commit_msg>Additional functionality for PersistenData System<commit_after>﻿using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
using URSA.Save;
#if UNITY_EDITOR
using UnityEditor; 
#endif
using URSA;
using System.IO;

public class PersistentDataSystem : MonoBehaviour {


    #region SINGLETON
    private static PersistentDataSystem _instance;
    public static PersistentDataSystem instance
    {
        get {
            if (!_instance) _instance = GameObject.FindObjectOfType<PersistentDataSystem>();
            return _instance;
        }
    }
    #endregion

    public string FileName = "persistentGameData";
    public DataPath datapath;
    public string customDataPath;
    public string folderPath = "PersistenData";
    public string extension = ".data";

    public static event Action OnPersistentDataLoaded = delegate { };

    public static void MakePersistent(Entity entity) {
        UnityEngine.Object.DontDestroyOnLoad(entity.gameObject);
        entity.transform.parent = instance.transform;
    }


#if     UNITY_EDITOR
    [MenuItem(URSAConstants.PATH_MENUITEM_ROOT + URSAConstants.PATH_MENUITEM_PERSISTENT + URSAConstants.PATH_MENUITEM_PERSISTENT_SAVE)] 
#endif
    public static void Save() {
        instance.SaveTo();
    }



#if UNITY_EDITOR
    [MenuItem(URSAConstants.PATH_MENUITEM_ROOT + URSAConstants.PATH_MENUITEM_PERSISTENT + URSAConstants.PATH_MENUITEM_PERSISTENT_LOAD)] 
#endif
    public static void Load() {
        instance.LoadFrom();
    }

    static string getSystemPath() {
        var sys = PersistentDataSystem.instance;
        string path = String.Empty;
        switch (sys.datapath) {
            case DataPath.persistent: {
                    path = Application.persistentDataPath;
                }
                break;
            case DataPath.inRootFolder: {
                    path = Application.dataPath;
                }
                break;
            case DataPath.custom: {
                    path = sys.customDataPath;
                }
                break;
            default:
                break;
        }
        return path + "/" + URSASettings.current.CustomDataFolder;
    }

    public void SaveTo() {
        SaveObject file = SaveSystem.CreateSaveObjectFromPersistenData();
        PersistentDataInfo info = new PersistentDataInfo();
        info.profileName = "profile";
        info.creationDate = DateTime.Now;
        info.data = file;

        string path = getSystemPath() + "/" + folderPath;

        if (!Directory.Exists(path)) {
            Directory.CreateDirectory(path);
        }

        SerializationHelper.Serialize(info, path + "/" + FileName + extension, true);
    }

    public void LoadFrom() {

        ClearAnd(completeLoad);
    }

    public void ClearAnd(Action and) {
        transform.DestroyChildren();
        this.OneFrameDelay(and);
    }

    public void ClearAndLoadBlueprint(TextAsset blueprint, Action onLoaded) {
        var bpLoader = GetComponent<BlueprintLoader>();
        if (!bpLoader) {
            Debug.LogError("Blueprint loader was not found, add it to the PersistentDataSystem");
            return;
        }
        ClearAnd(() =>
        {
            bpLoader.blueprint = blueprint;
            bpLoader.Load();
            onLoaded();
        });
    }

{'fraction_non_alphanumeric': 0.08351072539708532, 'fraction_numerical': 0.0, 'mean_word_length': 2.3249863908546544, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038295', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1630, 'n_words': 354}