<commit_before>﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;

namespace Fungus
{
    public class SaveGameHelper : MonoBehaviour 
    {
        const string SaveDataKey = "save_data";

        const string NewGameSavePointKey = "new_game";

        [SerializeField] protected string startScene = "";

        [SerializeField] protected bool autoStartGame = true;

        [SerializeField] protected bool restartDeletesSave = false;

        [SerializeField] protected CanvasGroup saveMenuGroup;

        [SerializeField] protected Button saveMenuButton;

        [SerializeField] protected Button saveButton;

        [SerializeField] protected Button loadButton;

        [SerializeField] protected Button rewindButton;

        [SerializeField] protected Button restartButton;

        [SerializeField] protected SaveGameObjects saveGameObjects = new SaveGameObjects();

        protected AudioSource clickAudioSource;

        protected virtual void Awake()
        {
            clickAudioSource = GetComponent<AudioSource>();
        }

        protected virtual void Start()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (autoStartGame &&
                saveManager.NumSavePoints == 0)
            {
                SavePointLoaded.NotifyEventHandlers(NewGameSavePointKey);
            }

            CheckSavePointKeys();
        }

        protected virtual void Update()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (saveButton != null)
            {
                // Don't allow saving unless there's at least one save point in the history,
                // This avoids the case where you could try to load a save data with 0 save points.
                saveButton.interactable = saveManager.NumSavePoints > 0;
            }
            if (loadButton != null)
            {
                loadButton.interactable = saveManager.SaveDataExists(SaveDataKey);
            }
            if (rewindButton != null)
            {
                rewindButton.interactable = saveManager.NumSavePoints > 1;
            }

            Debug.Log("Update");
        }

        protected void CheckSavePointKeys()
        {
            List<string> keys = new List<string>();

            var savePoints = GameObject.FindObjectsOfType<SavePoint>();

            foreach (var savePoint in savePoints)
            {
                if (string.IsNullOrEmpty(savePoint.SavePointKey))
                {
                    continue;
                }

                if (keys.Contains(savePoint.SavePointKey))
                {
                    Debug.LogError("Save Point Key " + savePoint.SavePointKey + " is defined multiple times.");
                }
                else
                {
                    keys.Add(savePoint.SavePointKey);
                }
            }
        }

        protected void PlayClickSound()
        {
            if (clickAudioSource != null)
            {
                clickAudioSource.Play();
            }
        }

        protected LTDescr fadeTween;

        protected bool saveMenuActive = true;

        #region Public methods

        public SaveGameObjects SaveGameObjects { get { return saveGameObjects; } }

        public virtual void ToggleSaveMenu()
        {
            if (fadeTween != null)
            {
                LeanTween.cancel(fadeTween.id);
                fadeTween = null;
            }

            if (saveMenuActive)
            {
                // Switch save menu off
                LeanTween.value(saveMenuGroup.gameObject, saveMenuGroup.alpha, 0f, 0.5f).setOnUpdate( (t) => { 
                    saveMenuGroup.alpha = t;
                }).setOnComplete( () => {
                    //saveMenuGroup.interactable = false;
                    //saveMenuGroup.gameObject.SetActive(false);
                });
            }
            else
            {
                // Switch save menu on
                //saveMenuGroup.gameObject.SetActive(true);
                saveMenuGroup.interactable = false;
                LeanTween.value(saveMenuGroup.gameObject, saveMenuGroup.alpha, 1f, 0.5f).setOnUpdate( (t) => { 
                    saveMenuGroup.alpha = t;
                }).setOnComplete( () => {
                });
            }

            saveMenuActive = !saveMenuActive;
        }

        public virtual void Save()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (saveManager.NumSavePoints > 0)
            {
                PlayClickSound();
                saveManager.Save(SaveDataKey);
            }
        }

        public virtual void Load()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (saveManager.SaveDataExists(SaveDataKey))
            {<commit_msg>Hide / show save menu<commit_after>﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;

namespace Fungus
{
    public class SaveGameHelper : MonoBehaviour 
    {
        const string SaveDataKey = "save_data";

        const string NewGameSavePointKey = "new_game";

        [SerializeField] protected string startScene = "";

        [SerializeField] protected bool autoStartGame = true;

        [SerializeField] protected bool saveMenuActive = false;

        [SerializeField] protected bool restartDeletesSave = false;

        [SerializeField] protected CanvasGroup saveMenuGroup;

        [SerializeField] protected Button saveMenuButton;

        [SerializeField] protected Button saveButton;

        [SerializeField] protected Button loadButton;

        [SerializeField] protected Button rewindButton;

        [SerializeField] protected Button restartButton;

        [SerializeField] protected SaveGameObjects saveGameObjects = new SaveGameObjects();

        protected AudioSource clickAudioSource;

        protected LTDescr fadeTween;

        protected virtual void Awake()
        {
            clickAudioSource = GetComponent<AudioSource>();
        }

        protected virtual void Start()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (!saveMenuActive)
            {
                saveMenuGroup.alpha = 0f;
            }

            if (autoStartGame &&
                saveManager.NumSavePoints == 0)
            {
                SavePointLoaded.NotifyEventHandlers(NewGameSavePointKey);
            }

            CheckSavePointKeys();
        }

        protected virtual void Update()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (saveButton != null)
            {
                // Don't allow saving unless there's at least one save point in the history,
                // This avoids the case where you could try to load a save data with 0 save points.
                saveButton.interactable = saveManager.NumSavePoints > 0;
            }
            if (loadButton != null)
            {
                loadButton.interactable = saveManager.SaveDataExists(SaveDataKey);
            }
            if (rewindButton != null)
            {
                rewindButton.interactable = saveManager.NumSavePoints > 1;
            }
        }

        protected void CheckSavePointKeys()
        {
            List<string> keys = new List<string>();

            var savePoints = GameObject.FindObjectsOfType<SavePoint>();

            foreach (var savePoint in savePoints)
            {
                if (string.IsNullOrEmpty(savePoint.SavePointKey))
                {
                    continue;
                }

                if (keys.Contains(savePoint.SavePointKey))
                {
                    Debug.LogError("Save Point Key " + savePoint.SavePointKey + " is defined multiple times.");
                }
                else
                {
                    keys.Add(savePoint.SavePointKey);
                }
            }
        }

        protected void PlayClickSound()
        {
            if (clickAudioSource != null)
            {
                clickAudioSource.Play();
            }
        }

        #region Public methods

        public SaveGameObjects SaveGameObjects { get { return saveGameObjects; } }

        public virtual void ToggleSaveMenu()
        {
            if (fadeTween != null)
            {
                LeanTween.cancel(fadeTween.id);
                fadeTween = null;
            }

            if (saveMenuActive)
            {
                // Switch menu off
                LeanTween.value(saveMenuGroup.gameObject, saveMenuGroup.alpha, 0f, 0.5f).setOnUpdate( (t) => { 
                    saveMenuGroup.alpha = t;
                });
            }
            else
            {
                // Switch menu on
                LeanTween.value(saveMenuGroup.gameObject, saveMenuGroup.alpha, 1f, 0.5f).setOnUpdate( (t) => { 
                    saveMenuGroup.alpha = t;
                });
            }

            saveMenuActive = !saveMenuActive;
        }

        public virtual void Save()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (saveManager.NumSavePoints > 0)
            {
                PlayClickSound();
                saveManager.Save(SaveDataKey);
            }
        }

        public virtual void Load()
        {
            var saveManager = FungusManager.Instance.SaveManager;

            if (saveManager.SaveDataExists(SaveDataKey))
            {
{'fraction_non_alphanumeric': 0.0759821706229916, 'fraction_numerical': 0.00238416087902975, 'mean_word_length': 1.5329482803885535, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '4933209', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2259, 'n_words': 525}