This should fully make browser savefile work now

This commit is contained in:
Lncvrt committed 2025-09-22 16:52:57 -07:00
1 parent d61aae848d
commit ad8ced1904
1 file changed
+26 -3
+26 -3
View File
@@ -1,3 +1,4 @@
using System;
using System.IO; using System.IO;
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
@@ -45,6 +46,8 @@ public class BazookaManager : MonoBehaviour
} }
public void Load() public void Load()
{
if (Application.platform != RuntimePlatform.WebGLPlayer)
{ {
string path = Path.Join(Application.persistentDataPath, "save.json"); string path = Path.Join(Application.persistentDataPath, "save.json");
if (!File.Exists(path)) if (!File.Exists(path))
@@ -68,18 +71,38 @@ public class BazookaManager : MonoBehaviour
saveFile["version"] = "0"; saveFile["version"] = "0";
} }
} }
else
{
try
{
var tempSaveFile = JObject.Parse(File.ReadAllText(Encoding.UTF8.GetString(Convert.FromBase64String(PlayerPrefs.GetString("saveFile", "e30=")))));
if (tempSaveFile != null) saveFile = tempSaveFile;
}
catch
{
Debug.LogWarning("Failed to load save file");
}
}
}
public void Save() public void Save()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
return; return;
#else #else
if (Application.platform != RuntimePlatform.WebGLPlayer)
{
string path = Path.Join(Application.persistentDataPath, "save.json"); string path = Path.Join(Application.persistentDataPath, "save.json");
var encoded = Encoding.UTF8.GetBytes(saveFile.ToString()); var encoded = Encoding.UTF8.GetBytes(saveFile.ToString());
using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
fileStream.Write(encoded, 0, encoded.Length); fileStream.Write(encoded, 0, encoded.Length);
fileStream.Flush(true); fileStream.Flush(true);
#endif }
else
{
PlayerPrefs.SetString("saveFile", Convert.ToBase64String(Encoding.UTF8.GetBytes(saveFile.ToString(Newtonsoft.Json.Formatting.None))));
}
#endif
} }
public void ResetSave() public void ResetSave()