From 093813bc08fc60cf11d739d64c354d0606883624 Mon Sep 17 00:00:00 2001
From: billc27 <110593711+billc27@users.noreply.github.com>
Date: Tue, 30 Apr 2024 14:28:01 +0700
Subject: [PATCH] feat: state for cheats

---
 Assets/Scripts/States/GlobalStateManager.cs   | 40 +++++++++++++++++++
 .../Scripts/States/GlobalStateManager.cs.meta | 11 +++++
 Assets/Scripts/States/SaveState.cs            | 37 +++++++++++++++++
 Assets/Scripts/States/SaveState.cs.meta       | 11 +++++
 4 files changed, 99 insertions(+)
 create mode 100644 Assets/Scripts/States/GlobalStateManager.cs
 create mode 100644 Assets/Scripts/States/GlobalStateManager.cs.meta
 create mode 100644 Assets/Scripts/States/SaveState.cs
 create mode 100644 Assets/Scripts/States/SaveState.cs.meta

diff --git a/Assets/Scripts/States/GlobalStateManager.cs b/Assets/Scripts/States/GlobalStateManager.cs
new file mode 100644
index 0000000..a0d815d
--- /dev/null
+++ b/Assets/Scripts/States/GlobalStateManager.cs
@@ -0,0 +1,40 @@
+using Nightmare;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class GlobalStateManager : MonoBehaviour
+{
+    // Create Singleton
+    public static GlobalStateManager Instance { get; private set; }
+
+    private CheatManager cheatManager;
+
+    private void Awake()
+    {
+        if (Instance != null)
+        {
+            if (Instance != this)
+            {
+                Destroy(this);
+            }
+        }
+        else
+        {
+            Instance = this;
+            Refresh();
+        }
+    }
+
+    private void Refresh()
+    {
+        cheatManager = FindObjectOfType<CheatManager>();
+    }
+
+    public void SetState(SaveState state)
+    {
+        Refresh();
+
+        cheatManager.LoadCheat(state.globalSaveState.cheats);
+    }
+}
diff --git a/Assets/Scripts/States/GlobalStateManager.cs.meta b/Assets/Scripts/States/GlobalStateManager.cs.meta
new file mode 100644
index 0000000..5b855cc
--- /dev/null
+++ b/Assets/Scripts/States/GlobalStateManager.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 40f7e905f1aa63741b02b9146e251f76
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Assets/Scripts/States/SaveState.cs b/Assets/Scripts/States/SaveState.cs
new file mode 100644
index 0000000..da0b873
--- /dev/null
+++ b/Assets/Scripts/States/SaveState.cs
@@ -0,0 +1,37 @@
+using System;
+using Newtonsoft.Json;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+[Serializable]
+public class GlobalSaveState
+{
+    public bool[] cheats;
+
+    public GlobalSaveState(bool[] cheats)
+    {
+        this.cheats = cheats;
+    }
+
+    public override string ToString()
+    {
+        return JsonConvert.SerializeObject(this);
+    }
+}
+
+[Serializable]
+public class SaveState
+{
+    public GlobalSaveState globalSaveState;
+
+    public SaveState(GlobalSaveState globalSaveState)
+    {
+        this.globalSaveState = globalSaveState;
+    }
+
+    public override string ToString()
+    {
+        return JsonConvert.SerializeObject(this);
+    }
+}
diff --git a/Assets/Scripts/States/SaveState.cs.meta b/Assets/Scripts/States/SaveState.cs.meta
new file mode 100644
index 0000000..a0c00a3
--- /dev/null
+++ b/Assets/Scripts/States/SaveState.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e0c4e2ce428b7c044baefcfca6687111
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
-- 
GitLab