Skip to content
Snippets Groups Projects
Commit 44539599 authored by Malik Rafsanjani's avatar Malik Rafsanjani
Browse files

stash temp load feature

parent 5613e3b5
No related merge requests found
......@@ -6,7 +6,7 @@ using System.IO;
public class GlobalManager : MonoBehaviour
{
public static GlobalManager Instance;
private GlobalStateManager globalState;
private GlobalStateManager globalStateManager;
private string playerName;
public string PlayerName
{
......@@ -17,6 +17,24 @@ public class GlobalManager : MonoBehaviour
}
}
private int idxLoadSlot = -1;
public int IdxLoadSlot
{
get => idxLoadSlot;
set
{
idxLoadSlot = value;
stateSave = SaveLoadManager.Instance.GetStateFromFile(idxLoadSlot);
OnLoad();
}
}
private StateSave stateSave = null;
public StateSave StateSave
{
get => stateSave;
}
private void Awake()
{
if (Instance != null)
......@@ -26,10 +44,15 @@ public class GlobalManager : MonoBehaviour
}
Instance = this;
globalState = GlobalStateManager.Instance;
globalStateManager = GlobalStateManager.Instance;
DontDestroyOnLoad(gameObject);
}
private void OnLoad()
{
playerName = stateSave.playerStateSave.playerName;
}
// Start is called before the first frame update
void Start()
{
......
......@@ -61,7 +61,7 @@ public class SaveLoadManager : MonoBehaviour
public void LoadState(int Id)
{
var file = SaveLoadConfig.files[Id];
/* var file = SaveLoadConfig.files[Id];
var path = Application.persistentDataPath + "/" + file + ".json";
if (File.Exists(path))
{
......@@ -69,6 +69,26 @@ public class SaveLoadManager : MonoBehaviour
Debug.Log("JSON:" + json);
StateSave state = JsonUtility.FromJson<StateSave>(json);
GlobalStateManager.Instance.SetState(state);
}*/
var state = GetStateFromFile(Id);
if (state != null)
{
GlobalStateManager.Instance.SetState(state);
}
}
public StateSave GetStateFromFile(int id)
{
var file = SaveLoadConfig.files[id];
var path = Application.persistentDataPath + "/" + file + ".json";
if (File.Exists(path))
{
string json = File.ReadAllText(path);
Debug.Log("JSON:" + json);
StateSave state = JsonUtility.FromJson<StateSave>(json);
return state;
}
return null;
}
}
......@@ -5,6 +5,20 @@ using UnityEngine;
public class SavePlace : MonoBehaviour
{
private bool onArea = false;
private Temple temple;
private bool IsOnQuest
{
get
{
return temple.OnQuest;
}
}
private void Awake()
{
temple = FindObjectOfType<Temple>();
}
// Start is called before the first frame update
void Start()
......@@ -15,7 +29,7 @@ public class SavePlace : MonoBehaviour
// Update is called once per frame
void Update()
{
if (onArea && Input.GetKeyDown(KeyCode.B))
if (onArea && !IsOnQuest && Input.GetKeyDown(KeyCode.B))
{
Debug.Log("SAVING");
if (SaveLoadManager.Instance == null )
......@@ -35,7 +49,10 @@ public class SavePlace : MonoBehaviour
{
if (other.CompareTag("Player"))
{
ToastManager.Instance.ShowToast("Press B to save", 3);
if (!IsOnQuest)
{
ToastManager.Instance.ShowToast("Press B to save", 3);
}
onArea = true;
}
}
......
......@@ -132,7 +132,7 @@ public class GlobalStateManager : MonoBehaviour
// TODO: set meta player save
GlobalManager.Instance.PlayerName = state.playerStateSave.playerName;
/* GlobalManager.Instance.PlayerName = state.playerStateSave.playerName;
playerHealth.currentHealth = state.playerStateSave.health;
GameControl.control.currency = state.playerStateSave.money;
temple.IdxCurrentQuest = state.playerStateSave.idxQuest;
......@@ -147,7 +147,7 @@ public class GlobalStateManager : MonoBehaviour
playerWeapons.UnlockWeapon(type);
playerWeapons.SetLevel(type, level);
}
}
}*/
// TODO: set player state save
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment