From 36f65c3f5a6079554935577112dd2a2014fa959e Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Sat, 12 Jul 2025 13:46:42 -0700 Subject: [PATCH] Bazooka Manager is basically complete now (after 2+ weeks) and start working on server rewrite --- .../AccountMenu/AccountChangePassword.cs | 6 +- .../AccountMenu/AccountChangeUsername.cs | 6 +- Assets/Scripts/AccountMenu/AccountHandler.cs | 2 +- Assets/Scripts/AccountMenu/AccountLoggedIn.cs | 72 ++-- .../Scripts/AccountMenu/AccountLoggedOut.cs | 28 +- Assets/Scripts/AccountMenu/AccountLogin.cs | 63 ++- .../AccountMenu/AccountRefreshLogin.cs | 9 +- Assets/Scripts/AccountMenu/AccountRegister.cs | 80 ++-- Assets/Scripts/BazookaManager.cs | 407 +++++++++++++++++- Assets/Scripts/BazookaSetting.cs | 7 + Assets/Scripts/BazookaSetting.cs.meta | 2 + Assets/Scripts/ChatroomMenu.cs | 8 +- Assets/Scripts/GamePlayer.cs | 85 ++-- Assets/Scripts/GamePlayerPauseMenu.cs | 10 +- Assets/Scripts/HideIfSettingFalse.cs | 22 +- Assets/Scripts/IconsMenu.cs | 23 +- Assets/Scripts/IconsMenuBirdColorPanel.cs | 70 +-- Assets/Scripts/IconsMenuOverlayColorPanel.cs | 70 +-- Assets/Scripts/LeaderboardsMenu.cs | 29 +- Assets/Scripts/LoadingMenu.cs | 69 +-- Assets/Scripts/MenuMusic.cs | 2 +- Assets/Scripts/SettingsMenu.cs | 40 +- Assets/Scripts/SettingsMenuBgColorPanel.cs | 82 ++-- Assets/Scripts/Tools.cs | 2 +- 24 files changed, 810 insertions(+), 384 deletions(-) create mode 100644 Assets/Scripts/BazookaSetting.cs create mode 100644 Assets/Scripts/BazookaSetting.cs.meta diff --git a/Assets/Scripts/AccountMenu/AccountChangePassword.cs b/Assets/Scripts/AccountMenu/AccountChangePassword.cs index 3d8da7f..ac5ca2a 100644 --- a/Assets/Scripts/AccountMenu/AccountChangePassword.cs +++ b/Assets/Scripts/AccountMenu/AccountChangePassword.cs @@ -37,8 +37,8 @@ public class AccountChangePassword : MonoBehaviour EncryptedWWWForm dataForm = new(); dataForm.AddField("inputPassword", changePasswordCurrentPasswordInput.text); dataForm.AddField("inputNewPassword", changePasswordNewPasswordInput.text); - dataForm.AddField("session", PlayerPrefs.GetString("gameSession")); - dataForm.AddField("userName", PlayerPrefs.GetString("userName")); + dataForm.AddField("session", BazookaManager.Instance.GetAccountSession()); + dataForm.AddField("userName", BazookaManager.Instance.GetAccountName()); using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "changeAccountPassword.php", dataForm.GetWWWForm()); request.SetRequestHeader("Requester", "BerryDashClient"); request.SetRequestHeader("ClientVersion", Application.version); @@ -82,7 +82,7 @@ public class AccountChangePassword : MonoBehaviour } if (Regex.IsMatch(response, "^[a-zA-Z0-9]{512}$")) { - PlayerPrefs.SetString("gameSession", response); + BazookaManager.Instance.SetAccountSession(response); AccountHandler.instance.SwitchPanel(0); AccountHandler.UpdateStatusText(AccountHandler.instance.accountLoggedIn.loggedInText, "Password changed successfully", Color.green); } diff --git a/Assets/Scripts/AccountMenu/AccountChangeUsername.cs b/Assets/Scripts/AccountMenu/AccountChangeUsername.cs index b548709..d50b329 100644 --- a/Assets/Scripts/AccountMenu/AccountChangeUsername.cs +++ b/Assets/Scripts/AccountMenu/AccountChangeUsername.cs @@ -29,8 +29,8 @@ public class AccountChangeUsername : MonoBehaviour EncryptedWWWForm dataForm = new(); dataForm.AddField("inputUserName", changeUsernameCurrentUsernameInput.text); dataForm.AddField("inputNewUserName", changeUsernameNewUsernameInput.text); - dataForm.AddField("session", PlayerPrefs.GetString("gameSession")); - dataForm.AddField("userName", PlayerPrefs.GetString("userName")); + dataForm.AddField("session", BazookaManager.Instance.GetAccountSession()); + dataForm.AddField("userName", BazookaManager.Instance.GetAccountName()); using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "changeAccountUsername.php", dataForm.GetWWWForm()); request.SetRequestHeader("Requester", "BerryDashClient"); request.SetRequestHeader("ClientVersion", Application.version); @@ -57,7 +57,7 @@ public class AccountChangeUsername : MonoBehaviour AccountHandler.UpdateStatusText(changeUsernameStatusText, "Can't send requests on self-built instance", Color.red); break; case "1": - PlayerPrefs.SetString("userName", changeUsernameNewUsernameInput.text); + BazookaManager.Instance.SetAccountName(changeUsernameNewUsernameInput.text); AccountHandler.instance.SwitchPanel(0); AccountHandler.UpdateStatusText(AccountHandler.instance.accountLoggedIn.loggedInText, "Username changed successfully", Color.green); break; diff --git a/Assets/Scripts/AccountMenu/AccountHandler.cs b/Assets/Scripts/AccountMenu/AccountHandler.cs index c8475cc..ed389a4 100644 --- a/Assets/Scripts/AccountMenu/AccountHandler.cs +++ b/Assets/Scripts/AccountMenu/AccountHandler.cs @@ -19,7 +19,7 @@ public class AccountHandler : MonoBehaviour void Start() { - if (PlayerPrefs.HasKey("gameSession") && PlayerPrefs.HasKey("userName") && PlayerPrefs.HasKey("userId")) + if (BazookaManager.Instance.GetAccountID() != null && BazookaManager.Instance.GetAccountName() != null && BazookaManager.Instance.GetAccountSession() != null) { SwitchPanel(0); } diff --git a/Assets/Scripts/AccountMenu/AccountLoggedIn.cs b/Assets/Scripts/AccountMenu/AccountLoggedIn.cs index 342509f..9fdd222 100644 --- a/Assets/Scripts/AccountMenu/AccountLoggedIn.cs +++ b/Assets/Scripts/AccountMenu/AccountLoggedIn.cs @@ -1,3 +1,5 @@ +using System.Numerics; +using Newtonsoft.Json.Linq; using TMPro; using UnityEngine; using UnityEngine.Networking; @@ -35,7 +37,7 @@ public class AccountLoggedIn : MonoBehaviour { loggedInSaveButton.interactable = true; loggedInLoadButton.interactable = true; - loggedInText.text = "Logged in as: " + PlayerPrefs.GetString("userName"); + loggedInText.text = "Logged in as: " + BazookaManager.Instance.GetAccountName(); } async void SaveAccount() @@ -43,23 +45,23 @@ public class AccountLoggedIn : MonoBehaviour loggedInLoadButton.interactable = false; loggedInSaveButton.interactable = false; EncryptedWWWForm dataForm = new(); - dataForm.AddField("userName", PlayerPrefs.GetString("userName", "")); - dataForm.AddField("gameSession", PlayerPrefs.GetString("gameSession", "")); - dataForm.AddField("highScore", PlayerPrefs.GetString("HighScoreV2", "0")); - dataForm.AddField("icon", PlayerPrefs.GetInt("icon", 1).ToString()); - dataForm.AddField("overlay", PlayerPrefs.GetInt("overlay", 0).ToString()); - dataForm.AddField("totalNormalBerries", PlayerPrefs.GetString("TotalNormalBerries", "0")); - dataForm.AddField("totalPoisonBerries", PlayerPrefs.GetString("TotalPoisonBerries", "0")); - dataForm.AddField("totalSlowBerries", PlayerPrefs.GetString("TotalSlowBerries", "0")); - dataForm.AddField("totalUltraBerries", PlayerPrefs.GetString("TotalUltraBerries", "0")); - dataForm.AddField("totalSpeedyBerries", PlayerPrefs.GetString("TotalSpeedyBerries", "0")); - dataForm.AddField("totalAttempts", PlayerPrefs.GetString("TotalAttempts", "0")); - dataForm.AddField("birdR", PlayerPrefs.GetString("BirdColor", "255;255;255").Split(';')[0]); - dataForm.AddField("birdG", PlayerPrefs.GetString("BirdColor", "255;255;255").Split(';')[1]); - dataForm.AddField("birdB", PlayerPrefs.GetString("BirdColor", "255;255;255").Split(';')[2]); - dataForm.AddField("overlayR", PlayerPrefs.GetString("OverlayColor", "255;255;255").Split(';')[0]); - dataForm.AddField("overlayG", PlayerPrefs.GetString("OverlayColor", "255;255;255").Split(';')[1]); - dataForm.AddField("overlayB", PlayerPrefs.GetString("OverlayColor", "255;255;255").Split(';')[2]); + dataForm.AddField("userName", BazookaManager.Instance.GetAccountName()); + dataForm.AddField("gameSession", BazookaManager.Instance.GetAccountSession()); + dataForm.AddField("highScore", BazookaManager.Instance.GetGameStoreHighScore().ToString()); + dataForm.AddField("icon", BazookaManager.Instance.GetBirdIcon().ToString()); + dataForm.AddField("overlay", BazookaManager.Instance.GetBirdOverlay().ToString()); + dataForm.AddField("totalNormalBerries", BazookaManager.Instance.GetGameStoreTotalNormalBerries().ToString()); + dataForm.AddField("totalPoisonBerries", BazookaManager.Instance.GetGameStoreTotalPoisonBerries().ToString()); + dataForm.AddField("totalSlowBerries", BazookaManager.Instance.GetGameStoreTotalSlowBerries().ToString()); + dataForm.AddField("totalUltraBerries", BazookaManager.Instance.GetGameStoreTotalUltraBerries().ToString()); + dataForm.AddField("totalSpeedyBerries", BazookaManager.Instance.GetGameStoreTotalSpeedyBerries().ToString()); + dataForm.AddField("totalAttempts", BazookaManager.Instance.GetGameStoreTotalAttepts().ToString()); + dataForm.AddField("birdR", BazookaManager.Instance.GetColorSettingIcon()[0].ToString()); + dataForm.AddField("birdG", BazookaManager.Instance.GetColorSettingIcon()[1].ToString()); + dataForm.AddField("birdB", BazookaManager.Instance.GetColorSettingIcon()[2].ToString()); + dataForm.AddField("overlayR", BazookaManager.Instance.GetColorSettingOverlay()[0].ToString()); + dataForm.AddField("overlayG", BazookaManager.Instance.GetColorSettingOverlay()[1].ToString()); + dataForm.AddField("overlayB", BazookaManager.Instance.GetColorSettingOverlay()[2].ToString()); using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "saveAccount.php", dataForm.GetWWWForm()); request.SetRequestHeader("Requester", "BerryDashClient"); request.SetRequestHeader("ClientVersion", Application.version); @@ -104,8 +106,8 @@ public class AccountLoggedIn : MonoBehaviour loggedInLoadButton.interactable = false; loggedInSaveButton.interactable = false; EncryptedWWWForm dataForm = new(); - dataForm.AddField("userName", PlayerPrefs.GetString("userName", "")); - dataForm.AddField("gameSession", PlayerPrefs.GetString("gameSession", "")); + dataForm.AddField("userName", BazookaManager.Instance.GetAccountName()); + dataForm.AddField("gameSession", BazookaManager.Instance.GetAccountSession()); using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "loadAccount.php", dataForm.GetWWWForm()); request.SetRequestHeader("Requester", "BerryDashClient"); request.SetRequestHeader("ClientVersion", Application.version); @@ -138,17 +140,25 @@ public class AccountLoggedIn : MonoBehaviour var split = response.Split(":"); if (split[0] == "1") { - PlayerPrefs.SetString("HighScoreV2", split[1]); - PlayerPrefs.SetInt("icon", int.Parse(split[2])); - PlayerPrefs.SetInt("overlay", int.Parse(split[3])); - PlayerPrefs.SetString("TotalNormalBerries", split[4]); - PlayerPrefs.SetString("TotalPoisonBerries", split[5]); - PlayerPrefs.SetString("TotalSlowBerries", split[6]); - PlayerPrefs.SetString("TotalUltraBerries", split[7]); - PlayerPrefs.SetString("TotalSpeedyBerries", split[8]); - PlayerPrefs.SetString("TotalAttempts", split[9]); - PlayerPrefs.SetString("BirdColor", $"{split[10]};{split[11]};{split[12]}"); - PlayerPrefs.SetString("OverlayColor", $"{split[13]};{split[14]};{split[15]}"); + BazookaManager.Instance.SetGameStoreHighScore(BigInteger.Parse(split[1])); + BazookaManager.Instance.SetBirdIcon(int.Parse(split[2])); + BazookaManager.Instance.SetBirdOverlay(int.Parse(split[3])); + BazookaManager.Instance.SetGameStoreTotalNormalBerries(BigInteger.Parse(split[4])); + BazookaManager.Instance.SetGameStoreTotalPoisonBerries(BigInteger.Parse(split[5])); + BazookaManager.Instance.SetGameStoreTotalSlowBerries(BigInteger.Parse(split[6])); + BazookaManager.Instance.SetGameStoreTotalUltraBerries(BigInteger.Parse(split[7])); + BazookaManager.Instance.SetGameStoreTotalSpeedyBerries(BigInteger.Parse(split[8])); + BazookaManager.Instance.SetGameStoreTotalAttepts(BigInteger.Parse(split[9])); + BazookaManager.Instance.SetColorSettingIcon(new JArray( + int.Parse(split[10]), + int.Parse(split[11]), + int.Parse(split[12]) + )); + BazookaManager.Instance.SetColorSettingOverlay(new JArray( + int.Parse(split[13]), + int.Parse(split[14]), + int.Parse(split[15]) + )); AccountHandler.UpdateStatusText(loggedInText, "Loaded account data", Color.green); } else diff --git a/Assets/Scripts/AccountMenu/AccountLoggedOut.cs b/Assets/Scripts/AccountMenu/AccountLoggedOut.cs index e96e51d..69d34a7 100644 --- a/Assets/Scripts/AccountMenu/AccountLoggedOut.cs +++ b/Assets/Scripts/AccountMenu/AccountLoggedOut.cs @@ -20,20 +20,20 @@ public class AccountLoggedOut : MonoBehaviour { if (clearValues) { - PlayerPrefs.DeleteKey("gameSession"); - PlayerPrefs.DeleteKey("userName"); - PlayerPrefs.DeleteKey("userId"); - PlayerPrefs.SetString("HighScoreV2", "0"); - PlayerPrefs.SetInt("icon", 1); - PlayerPrefs.SetInt("overlay", 0); - PlayerPrefs.DeleteKey("TotalNormalBerries"); - PlayerPrefs.DeleteKey("TotalPoisonBerries"); - PlayerPrefs.DeleteKey("TotalSlowBerries"); - PlayerPrefs.DeleteKey("TotalUltraBerries"); - PlayerPrefs.DeleteKey("TotalSpeedyBerries"); - PlayerPrefs.DeleteKey("TotalAttempts"); - PlayerPrefs.DeleteKey("BirdColor"); - PlayerPrefs.DeleteKey("OverlayColor"); + BazookaManager.Instance.UnsetAccountSession(); + BazookaManager.Instance.UnsetAccountName(); + BazookaManager.Instance.UnsetAccountID(); + BazookaManager.Instance.UnsetGameStoreHighScore(); + BazookaManager.Instance.UnsetBirdIcon(); + BazookaManager.Instance.UnsetBirdOverlay(); + BazookaManager.Instance.UnsetGameStoreTotalNormalBerries(); + BazookaManager.Instance.UnsetGameStoreTotalPoisonBerries(); + BazookaManager.Instance.UnsetGameStoreTotalSlowBerries(); + BazookaManager.Instance.UnsetGameStoreTotalUltraBerries(); + BazookaManager.Instance.UnsetGameStoreTotalSpeedyBerries(); + BazookaManager.Instance.UnsetGameStoreTotalAttepts(); + BazookaManager.Instance.UnsetColorSettingIcon(); + BazookaManager.Instance.UnsetColorSettingOverlay(); clearValues = false; } } diff --git a/Assets/Scripts/AccountMenu/AccountLogin.cs b/Assets/Scripts/AccountMenu/AccountLogin.cs index b6ac08f..7016eb8 100644 --- a/Assets/Scripts/AccountMenu/AccountLogin.cs +++ b/Assets/Scripts/AccountMenu/AccountLogin.cs @@ -1,4 +1,5 @@ using System.Numerics; +using Newtonsoft.Json.Linq; using TMPro; using UnityEngine; using UnityEngine.Networking; @@ -27,10 +28,15 @@ public class AccountLogin : MonoBehaviour async void SubmitLogin() { + if (loginUsernameInput.text == string.Empty || loginPasswordInput.text == string.Empty) + { + AccountHandler.UpdateStatusText(loginPanelStatusText, "All input fields must be filled", Color.red); + return; + } EncryptedWWWForm dataForm = new(); dataForm.AddField("username", loginUsernameInput.text); dataForm.AddField("password", loginPasswordInput.text); - dataForm.AddField("currentHighScore", PlayerPrefs.GetString("HighScoreV2", "0")); + dataForm.AddField("currentHighScore", BazookaManager.Instance.GetGameStoreHighScore().ToString()); dataForm.AddField("loginType", "0"); using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "loginAccount.php", dataForm.GetWWWForm()); request.SetRequestHeader("Requester", "BerryDashClient"); @@ -63,39 +69,32 @@ public class AccountLogin : MonoBehaviour AccountHandler.UpdateStatusText(loginPanelStatusText, "Can't send requests on self-built instance", Color.red); return; } - else if (response == "-1") - { - AccountHandler.UpdateStatusText(loginPanelStatusText, "Incorrect username or password", Color.red); - } - else if (response.Split(":")[0] == "1") - { - string[] array = response.Split(':'); - string session = array[1]; - string userName = array[2]; - int userId = int.Parse(array[3]); - BigInteger highScore = BigInteger.Parse(array[4]); - int iconId = int.Parse(array[5]); - int overlayId = int.Parse(array[6]); - PlayerPrefs.SetString("gameSession", session); - PlayerPrefs.SetString("userName", userName); - PlayerPrefs.SetInt("userId", userId); - PlayerPrefs.SetString("HighScoreV2", highScore.ToString()); - PlayerPrefs.SetInt("icon", iconId); - PlayerPrefs.SetInt("overlay", overlayId); - PlayerPrefs.SetString("TotalNormalBerries", array[7]); - PlayerPrefs.SetString("TotalPoisonBerries", array[8]); - PlayerPrefs.SetString("TotalSlowBerries", array[9]); - PlayerPrefs.SetString("TotalUltraBerries", array[10]); - PlayerPrefs.SetString("TotalSpeedyBerries", array[11]); - PlayerPrefs.SetString("TotalAttempts", array[12]); - PlayerPrefs.SetString("BirdColor", $"{array[13]};{array[14]};{array[15]}"); - PlayerPrefs.SetString("OverlayColor", $"{array[16]};{array[17]};{array[18]}"); - AccountHandler.instance.SwitchPanel(0); - AccountHandler.UpdateStatusText(loginPanelStatusText, "", Color.red); - } else { - AccountHandler.UpdateStatusText(loginPanelStatusText, "Unknown server response", Color.red); + var jsonResponse = JObject.Parse(response); + if ((bool)jsonResponse["success"]) + { + BazookaManager.Instance.SetAccountSession((string)jsonResponse["data"]["session"]); + BazookaManager.Instance.SetAccountName((string)jsonResponse["data"]["username"]); + BazookaManager.Instance.SetAccountID(BigInteger.Parse((string)jsonResponse["data"]["userid"])); + BazookaManager.Instance.SetGameStoreHighScore(BigInteger.Parse((string)jsonResponse["data"]["highscore"])); + BazookaManager.Instance.SetBirdIcon((int)jsonResponse["data"]["icon"]); + BazookaManager.Instance.SetBirdOverlay((int)jsonResponse["data"]["overlay"]); + BazookaManager.Instance.SetGameStoreTotalNormalBerries(BigInteger.Parse((string)jsonResponse["data"]["totalNormalBerries"])); + BazookaManager.Instance.SetGameStoreTotalPoisonBerries(BigInteger.Parse((string)jsonResponse["data"]["totalPoisonBerries"])); + BazookaManager.Instance.SetGameStoreTotalSlowBerries(BigInteger.Parse((string)jsonResponse["data"]["totalSlowBerries"])); + BazookaManager.Instance.SetGameStoreTotalUltraBerries(BigInteger.Parse((string)jsonResponse["data"]["totalUltraBerries"])); + BazookaManager.Instance.SetGameStoreTotalSpeedyBerries(BigInteger.Parse((string)jsonResponse["data"]["totalSpeedyBerries"])); + BazookaManager.Instance.SetGameStoreTotalAttepts(BigInteger.Parse((string)jsonResponse["data"]["totalAttempts"])); + BazookaManager.Instance.SetColorSettingIcon(JArray.Parse(jsonResponse["data"]["birdColor"].ToString())); + BazookaManager.Instance.SetColorSettingOverlay(JArray.Parse(jsonResponse["data"]["overlayColor"].ToString())); + AccountHandler.instance.SwitchPanel(0); + AccountHandler.UpdateStatusText(loginPanelStatusText, "", Color.red); + } + else + { + AccountHandler.UpdateStatusText(loginPanelStatusText, (string)jsonResponse["message"], Color.red); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/AccountMenu/AccountRefreshLogin.cs b/Assets/Scripts/AccountMenu/AccountRefreshLogin.cs index cda5704..9ce9b55 100644 --- a/Assets/Scripts/AccountMenu/AccountRefreshLogin.cs +++ b/Assets/Scripts/AccountMenu/AccountRefreshLogin.cs @@ -1,3 +1,4 @@ +using System.Numerics; using TMPro; using UnityEngine; using UnityEngine.Networking; @@ -69,10 +70,10 @@ public class AccountRefreshLogin : MonoBehaviour string[] array = response.Split(':'); string session = array[1]; string userName = array[2]; - int userId = int.Parse(array[3]); - PlayerPrefs.SetString("gameSession", session); - PlayerPrefs.SetString("userName", userName); - PlayerPrefs.SetInt("userId", userId); + BigInteger userId = BigInteger.Parse(array[3]); + BazookaManager.Instance.SetAccountSession(session); + BazookaManager.Instance.SetAccountName(userName); + BazookaManager.Instance.SetAccountID(userId); AccountHandler.instance.SwitchPanel(0); AccountHandler.UpdateStatusText(refreshLoginStatusText, "", Color.red); } diff --git a/Assets/Scripts/AccountMenu/AccountRegister.cs b/Assets/Scripts/AccountMenu/AccountRegister.cs index 132d953..7ce0e55 100644 --- a/Assets/Scripts/AccountMenu/AccountRegister.cs +++ b/Assets/Scripts/AccountMenu/AccountRegister.cs @@ -1,5 +1,4 @@ -using System; -using System.Text.RegularExpressions; +using Newtonsoft.Json.Linq; using TMPro; using UnityEngine; using UnityEngine.Networking; @@ -34,19 +33,25 @@ public class AccountRegister : MonoBehaviour async void SubmitRegister() { - if (!registerEmailInput.text.Trim().Equals(registerRetypeEmailInput.text.Trim(), StringComparison.OrdinalIgnoreCase)) + if ( + registerUsernameInput.text == string.Empty || + registerEmailInput.text == string.Empty || + registerRetypeEmailInput.text == string.Empty || + registerPasswordInput.text == string.Empty || + registerRetypePasswordInput.text == string.Empty + ) { - AccountHandler.UpdateStatusText(registerPanelStatusText, "Email doesn't match", Color.red); + AccountHandler.UpdateStatusText(registerPanelStatusText, "All input fields must be filled", Color.red); return; } - if (!registerPasswordInput.text.Trim().Equals(registerRetypePasswordInput.text.Trim(), StringComparison.OrdinalIgnoreCase)) + if (registerEmailInput.text != registerRetypeEmailInput.text) { - AccountHandler.UpdateStatusText(registerPanelStatusText, "Password doesn't match", Color.red); + AccountHandler.UpdateStatusText(registerPanelStatusText, "Emails don't match", Color.red); return; } - if (!Regex.IsMatch(registerUsernameInput.text, "^[a-zA-Z0-9]{3,16}$")) + if (registerPasswordInput.text != registerRetypePasswordInput.text) { - AccountHandler.UpdateStatusText(registerPanelStatusText, "Username must be 3-16 characters, letters and numbers only", Color.red); + AccountHandler.UpdateStatusText(registerPanelStatusText, "Passwords don't match", Color.red); return; } EncryptedWWWForm dataForm = new(); @@ -64,38 +69,37 @@ public class AccountRegister : MonoBehaviour return; } string response = SensitiveInfo.Decrypt(request.downloadHandler.text, SensitiveInfo.SERVER_RECEIVE_TRANSFER_KEY); - switch (response) + if (response == "-999") { - case "-999": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Server error while fetching data", Color.red); - break; - case "-998": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Client version too outdated to access servers", Color.red); - break; - case "-997": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Encryption/decryption issues", Color.red); - break; - case "-996": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Can't send requests on self-built instance", Color.red); - break; - case "1": + AccountHandler.UpdateStatusText(registerPanelStatusText, "Server error while fetching data", Color.red); + return; + } + else if (response == "-998") + { + AccountHandler.UpdateStatusText(registerPanelStatusText, "Client version too outdated to access servers", Color.red); + return; + } + else if (response == "-997") + { + AccountHandler.UpdateStatusText(registerPanelStatusText, "Encryption/decryption issues", Color.red); + return; + } + else if (response == "-996") + { + AccountHandler.UpdateStatusText(registerPanelStatusText, "Can't send requests on self-built instance", Color.red); + return; + } + else + { + var jsonResponse = JObject.Parse(response); + if ((bool)jsonResponse["success"]) + { AccountHandler.instance.SwitchPanel(2); - break; - case "-1": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Username must be 3-16 characters, letters and numbers only", Color.red); - break; - case "-2": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Email not valid", Color.red); - break; - case "-3": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Password must have 8 characters, one number and one letter", Color.red); - break; - case "-4": - AccountHandler.UpdateStatusText(registerPanelStatusText, "Username or email already exists", Color.red); - break; - default: - AccountHandler.UpdateStatusText(registerPanelStatusText, "Unknown server response", Color.red); - break; + } + else + { + AccountHandler.UpdateStatusText(registerPanelStatusText, (string)jsonResponse["message"], Color.red); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/BazookaManager.cs b/Assets/Scripts/BazookaManager.cs index 31ffd33..4f5a734 100644 --- a/Assets/Scripts/BazookaManager.cs +++ b/Assets/Scripts/BazookaManager.cs @@ -1,7 +1,5 @@ -using System; using System.IO; -using System.Linq; -using System.Net.Security; +using System.Numerics; using Newtonsoft.Json.Linq; using UnityEngine; @@ -65,11 +63,412 @@ public class BazookaManager : MonoBehaviour public void Save() { +#if UNITY_EDITOR + return; +#else string path = Path.Join(Application.persistentDataPath, "BazookaManager.dat"); - var encoded = SensitiveInfo.EncryptRaw(saveFile.ToString(Newtonsoft.Json.Formatting.None), SensitiveInfo.BAZOOKA_MANAGER_KEY); + var encoded = SensitiveInfo.EncryptRaw(saveFile.ToString(Formatting.None), SensitiveInfo.BAZOOKA_MANAGER_KEY); if (encoded == null) return; using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); fileStream.Write(encoded, 0, encoded.Length); fileStream.Flush(true); +#endif + } + + //Bird stuff + + public void SetBirdIcon(int value) + { + if (saveFile["bird"] == null) saveFile["bird"] = new JObject(); + saveFile["bird"]["icon"] = value; + } + + public void UnsetBirdIcon() + { + if (saveFile["bird"] == null) return; + if (saveFile["bird"]["icon"] == null) return; + (saveFile["bird"] as JObject)?.Remove("icon"); + } + + public int GetBirdIcon() + { + if (saveFile["bird"] == null) return 1; + if (saveFile["bird"]["icon"] == null) return 1; + return int.Parse(saveFile["bird"]["icon"].ToString()); + } + + public void SetBirdOverlay(int value) + { + if (saveFile["bird"] == null) saveFile["bird"] = new JObject(); + saveFile["bird"]["overlay"] = value; + } + + + public void UnsetBirdOverlay() + { + if (saveFile["bird"] == null) return; + if (saveFile["bird"]["overlay"] == null) return; + (saveFile["bird"] as JObject)?.Remove("overlay"); + } + public int GetBirdOverlay() + { + if (saveFile["bird"] == null) return 0; + if (saveFile["bird"]["overlay"] == null) return 0; + return int.Parse(saveFile["bird"]["overlay"].ToString()); + } + + public void SetBirdPastOverlay(int value) + { + if (saveFile["bird"] == null) saveFile["bird"] = new JObject(); + saveFile["bird"]["pastOverlay"] = value; + } + + public void UnsetBirdPastOverlay() + { + if (saveFile["bird"] == null) return; + if (saveFile["bird"]["pastOverlay"] == null) return; + (saveFile["bird"] as JObject)?.Remove("pastOverlay"); + } + + public int GetBirdPastOverlay() + { + if (saveFile["bird"] == null) return 0; + if (saveFile["bird"]["pastOverlay"] == null) return 0; + return int.Parse(saveFile["bird"]["pastOverlay"].ToString()); + } + + //Settings stuff + + public void SetSettingFullScreen(bool value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + saveFile["settings"]["fullScreen"] = value; + } + + public bool? GetSettingFullScreen() + { + if (saveFile["settings"] == null) return null; + if (saveFile["settings"]["fullScreen"] == null) return null; + return bool.Parse(saveFile["settings"]["fullScreen"].ToString()); + } + + public void SetSettingShowFPS(bool value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + saveFile["settings"]["showFps"] = value; + } + + public bool GetSettingShowFPS() + { + if (saveFile["settings"] == null) return false; + if (saveFile["settings"]["showFps"] == null) return false; + return bool.Parse(saveFile["settings"]["showFps"].ToString()); + } + + public void SetSettingVsync(bool value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + saveFile["settings"]["vsync"] = value; + } + + public bool? GetSettingVsync() + { + if (saveFile["settings"] == null) return null; + if (saveFile["settings"]["vsync"] == null) return null; + return bool.Parse(saveFile["settings"]["vsync"].ToString()); + } + + public void SetSettingHideSocials(bool value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + saveFile["settings"]["hideSocials"] = value; + } + + public bool? GetSettingHideSocials() + { + if (saveFile["settings"] == null) return null; + if (saveFile["settings"]["hideSocials"] == null) return null; + return bool.Parse(saveFile["settings"]["hideSocials"].ToString()); + } + + public void SetSettingMusicVolume(float value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + saveFile["settings"]["musicVolume"] = value; + } + + public float GetSettingMusicVolume() + { + if (saveFile["settings"] == null) return 1f; + if (saveFile["settings"]["musicVolume"] == null) return 1f; + return float.Parse(saveFile["settings"]["musicVolume"].ToString()); + } + + public void SetSettingSFXVolume(float value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + saveFile["settings"]["sfxVolume"] = value; + } + + public float GetSettingSFXVolume() + { + if (saveFile["settings"] == null) return 1f; + if (saveFile["settings"]["sfxVolume"] == null) return 1f; + return float.Parse(saveFile["settings"]["sfxVolume"].ToString()); + } + + public void SetColorSettingBackground(JArray value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + if (saveFile["settings"]["colors"] == null) saveFile["settings"]["colors"] = new JObject(); + saveFile["settings"]["colors"]["background"] = value; + } + + public JArray GetColorSettingBackground() + { + if (saveFile["settings"] == null) return new JArray(58, 58, 58); + if (saveFile["settings"]["colors"] == null) return new JArray(58, 58, 58); + if (saveFile["settings"]["colors"]["background"] == null) return new JArray(58, 58, 58); + return JArray.Parse(saveFile["settings"]["colors"]["background"].ToString()); + } + + public void SetColorSettingIcon(JArray value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + if (saveFile["settings"]["colors"] == null) saveFile["settings"]["colors"] = new JObject(); + saveFile["settings"]["colors"]["icon"] = value; + } + + public JArray GetColorSettingIcon() + { + if (saveFile["settings"] == null) return new JArray(255, 255, 255); + if (saveFile["settings"]["colors"] == null) return new JArray(255, 255, 255); + if (saveFile["settings"]["colors"]["icon"] == null) return new JArray(255, 255, 255); + return JArray.Parse(saveFile["settings"]["colors"]["icon"].ToString()); + } + + public void UnsetColorSettingIcon() + { + if (saveFile["settings"] == null) return; + if (saveFile["settings"]["colors"] == null) return; + if (saveFile["settings"]["colors"]["icon"] == null) return; + (saveFile["settings"]["colors"] as JObject)?.Remove("icon"); + } + + public void SetColorSettingOverlay(JArray value) + { + if (saveFile["settings"] == null) saveFile["settings"] = new JObject(); + if (saveFile["settings"]["colors"] == null) saveFile["settings"]["colors"] = new JObject(); + saveFile["settings"]["colors"]["overlay"] = value; + } + + public JArray GetColorSettingOverlay() + { + if (saveFile["settings"] == null) return new JArray(255, 255, 255); + if (saveFile["settings"]["colors"] == null) return new JArray(255, 255, 255); + if (saveFile["settings"]["colors"]["overlay"] == null) return new JArray(255, 255, 255); + return JArray.Parse(saveFile["settings"]["colors"]["overlay"].ToString()); + } + + public void UnsetColorSettingOverlay() + { + if (saveFile["settings"] == null) return; + if (saveFile["settings"]["colors"] == null) return; + if (saveFile["settings"]["colors"]["overlay"] == null) return; + (saveFile["settings"]["colors"] as JObject)?.Remove("overlay"); + } + + //Account stuff + + public void SetAccountSession(string value) + { + if (saveFile["account"] == null) saveFile["account"] = new JObject(); + saveFile["account"]["session"] = value; + } + + public string GetAccountSession() + { + if (saveFile["account"] == null) return null; + if (saveFile["account"]["session"] == null) return null; + return saveFile["account"]["session"].ToString(); + } + + public void UnsetAccountSession() + { + if (saveFile["account"] == null) return; + (saveFile["account"] as JObject)?.Remove("session"); + } + + public void SetAccountName(string value) + { + if (saveFile["account"] == null) saveFile["account"] = new JObject(); + saveFile["account"]["name"] = value; + } + + public string GetAccountName() + { + if (saveFile["account"] == null) return null; + if (saveFile["account"]["name"] == null) return null; + return saveFile["account"]["name"].ToString(); + } + + public void UnsetAccountName() + { + if (saveFile["account"] == null) return; + (saveFile["account"] as JObject)?.Remove("name"); + } + + public void SetAccountID(BigInteger value) + { + if (saveFile["account"] == null) saveFile["account"] = new JObject(); + saveFile["account"]["id"] = value.ToString(); + } + + public BigInteger? GetAccountID() + { + if (saveFile["account"] == null) return null; + if (saveFile["account"]["id"] == null) return null; + return BigInteger.Parse(saveFile["account"]["id"].ToString()); + } + + public void UnsetAccountID() + { + if (saveFile["account"] == null) return; + (saveFile["account"] as JObject)?.Remove("id"); + } + + //Game store stuff + + public void SetGameStoreHighScore(BigInteger value) + { + if (saveFile["gameStore"] == null) saveFile["gameStore"] = new JObject(); + saveFile["gameStore"]["highScore"] = value.ToString(); + } + + public BigInteger GetGameStoreHighScore() + { + if (saveFile["gameStore"] == null) return 0; + if (saveFile["gameStore"]["highScore"] == null) return 0; + return BigInteger.Parse(saveFile["gameStore"]["highScore"].ToString()); + } + + public void UnsetGameStoreHighScore() + { + if (saveFile["gameStore"] == null) return; + (saveFile["gameStore"] as JObject)?.Remove("highScore"); + } + + public void SetGameStoreTotalAttepts(BigInteger value) + { + if (saveFile["gameStore"] == null) saveFile["gameStore"] = new JObject(); + saveFile["gameStore"]["totalAttempts"] = value.ToString(); + } + + public BigInteger GetGameStoreTotalAttepts() + { + if (saveFile["gameStore"] == null) return 0; + if (saveFile["gameStore"]["totalAttempts"] == null) return 0; + return BigInteger.Parse(saveFile["gameStore"]["totalAttempts"].ToString()); + } + + public void UnsetGameStoreTotalAttepts() + { + if (saveFile["gameStore"] == null) return; + (saveFile["gameStore"] as JObject)?.Remove("totalAttempts"); + } + + public void SetGameStoreTotalNormalBerries(BigInteger value) + { + if (saveFile["gameStore"] == null) saveFile["gameStore"] = new JObject(); + saveFile["gameStore"]["totalNormalBerries"] = value.ToString(); + } + + public BigInteger GetGameStoreTotalNormalBerries() + { + if (saveFile["gameStore"] == null) return 0; + if (saveFile["gameStore"]["totalNormalBerries"] == null) return 0; + return BigInteger.Parse(saveFile["gameStore"]["totalNormalBerries"].ToString()); + } + + public void UnsetGameStoreTotalNormalBerries() + { + if (saveFile["gameStore"] == null) return; + (saveFile["gameStore"] as JObject)?.Remove("totalNormalBerries"); + } + + public void SetGameStoreTotalPoisonBerries(BigInteger value) + { + if (saveFile["gameStore"] == null) saveFile["gameStore"] = new JObject(); + saveFile["gameStore"]["totalPoisonBerries"] = value.ToString(); + } + + public BigInteger GetGameStoreTotalPoisonBerries() + { + if (saveFile["gameStore"] == null) return 0; + if (saveFile["gameStore"]["totalPoisonBerries"] == null) return 0; + return BigInteger.Parse(saveFile["gameStore"]["totalPoisonBerries"].ToString()); + } + + public void UnsetGameStoreTotalPoisonBerries() + { + if (saveFile["gameStore"] == null) return; + (saveFile["gameStore"] as JObject)?.Remove("totalPoisonBerries"); + } + + public void SetGameStoreTotalSlowBerries(BigInteger value) + { + if (saveFile["gameStore"] == null) saveFile["gameStore"] = new JObject(); + saveFile["gameStore"]["totalSlowBerries"] = value.ToString(); + } + + public BigInteger GetGameStoreTotalSlowBerries() + { + if (saveFile["gameStore"] == null) return 0; + if (saveFile["gameStore"]["totalSlowBerries"] == null) return 0; + return BigInteger.Parse(saveFile["gameStore"]["totalSlowBerries"].ToString()); + } + + public void UnsetGameStoreTotalSlowBerries() + { + if (saveFile["gameStore"] == null) return; + (saveFile["gameStore"] as JObject)?.Remove("totalSlowBerries"); + } + + public void SetGameStoreTotalUltraBerries(BigInteger value) + { + if (saveFile["gameStore"] == null) saveFile["gameStore"] = new JObject(); + saveFile["gameStore"]["totalUltraBerries"] = value.ToString(); + } + + public BigInteger GetGameStoreTotalUltraBerries() + { + if (saveFile["gameStore"] == null) return 0; + if (saveFile["gameStore"]["totalUltraBerries"] == null) return 0; + return BigInteger.Parse(saveFile["gameStore"]["totalUltraBerries"].ToString()); + } + + public void UnsetGameStoreTotalUltraBerries() + { + if (saveFile["gameStore"] == null) return; + (saveFile["gameStore"] as JObject)?.Remove("totalUltraBerries"); + } + + public void SetGameStoreTotalSpeedyBerries(BigInteger value) + { + if (saveFile["gameStore"] == null) saveFile["gameStore"] = new JObject(); + saveFile["gameStore"]["totalSpeedyBerries"] = value.ToString(); + } + + public BigInteger GetGameStoreTotalSpeedyBerries() + { + if (saveFile["gameStore"] == null) return 0; + if (saveFile["gameStore"]["totalSpeedyBerries"] == null) return 0; + return BigInteger.Parse(saveFile["gameStore"]["totalSpeedyBerries"].ToString()); + } + + public void UnsetGameStoreTotalSpeedyBerries() + { + if (saveFile["gameStore"] == null) return; + (saveFile["gameStore"] as JObject)?.Remove("totalSpeedyBerries"); } } diff --git a/Assets/Scripts/BazookaSetting.cs b/Assets/Scripts/BazookaSetting.cs new file mode 100644 index 0000000..805aac6 --- /dev/null +++ b/Assets/Scripts/BazookaSetting.cs @@ -0,0 +1,7 @@ +public enum BazookaSetting +{ + FullScreen, + ShowFPS, + Vsync, + HideSocials +} \ No newline at end of file diff --git a/Assets/Scripts/BazookaSetting.cs.meta b/Assets/Scripts/BazookaSetting.cs.meta new file mode 100644 index 0000000..f98058b --- /dev/null +++ b/Assets/Scripts/BazookaSetting.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ee4201969db9e67d3b251fdcec5bfbd2 \ No newline at end of file diff --git a/Assets/Scripts/ChatroomMenu.cs b/Assets/Scripts/ChatroomMenu.cs index 64510b3..0cbf1f6 100644 --- a/Assets/Scripts/ChatroomMenu.cs +++ b/Assets/Scripts/ChatroomMenu.cs @@ -22,7 +22,7 @@ public class ChatroomMenu : MonoBehaviour void Start() { - if (!PlayerPrefs.HasKey("gameSession") || !PlayerPrefs.HasKey("userName") || !PlayerPrefs.HasKey("userId")) + if (BazookaManager.Instance.GetAccountID() == null || BazookaManager.Instance.GetAccountName() == null || BazookaManager.Instance.GetAccountSession() == null) { sendButton.interactable = false; messageInputField.interactable = false; @@ -56,7 +56,7 @@ public class ChatroomMenu : MonoBehaviour EncryptedWWWForm dataForm = new(); dataForm.AddField("content", text); - dataForm.AddField("gameSession", PlayerPrefs.GetString("gameSession", "")); + dataForm.AddField("gameSession", BazookaManager.Instance.GetAccountSession()); using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "sendChatroomMessage.php", dataForm.GetWWWForm()); request.SetRequestHeader("Requester", "BerryDashClient"); request.SetRequestHeader("ClientVersion", Application.version); @@ -179,7 +179,7 @@ public class ChatroomMenu : MonoBehaviour var overlayG = rowSplit[10]; var overlayB = rowSplit[11]; - if (content.transform.Find("ChatroomRow_" + id) != null) + if (content.transform.Find("ChatroomRow_" + id + "_" + uid) != null) { continue; } @@ -229,7 +229,7 @@ public class ChatroomMenu : MonoBehaviour playerIcon.color = Color.white; playerOverlayIcon.color = Color.white; } - rowInfo.name = "ChatroomRow_" + id; + rowInfo.name = "ChatroomRow_" + id + "_" + uid; rowInfo.SetActive(true); } } diff --git a/Assets/Scripts/GamePlayer.cs b/Assets/Scripts/GamePlayer.cs index dc16d58..31a5af5 100644 --- a/Assets/Scripts/GamePlayer.cs +++ b/Assets/Scripts/GamePlayer.cs @@ -40,27 +40,27 @@ public class GamePlayer : MonoBehaviour public GameObject backButton; public float lastMoveTime; - void Awake() + void Start() { - var backgroundColor = PlayerPrefs.GetString("BackgroundColor", "58;58;58").Split(";"); - var birdColor = PlayerPrefs.GetString("BirdColor", "255;255;255").Split(";"); - var overlayColor = PlayerPrefs.GetString("OverlayColor", "255;255;255").Split(";"); + var backgroundColor = BazookaManager.Instance.GetColorSettingBackground(); + var birdColor = BazookaManager.Instance.GetColorSettingIcon(); + var overlayColor = BazookaManager.Instance.GetColorSettingOverlay(); try { Camera.main.backgroundColor = new Color( - int.Parse(backgroundColor[0]) / 255f, - int.Parse(backgroundColor[1]) / 255f, - int.Parse(backgroundColor[2]) / 255f + int.Parse(backgroundColor[0].ToString()) / 255f, + int.Parse(backgroundColor[1].ToString()) / 255f, + int.Parse(backgroundColor[2].ToString()) / 255f ); bird.GetComponent().color = new Color( - int.Parse(birdColor[0]) / 255f, - int.Parse(birdColor[1]) / 255f, - int.Parse(birdColor[2]) / 255f + int.Parse(birdColor[0].ToString()) / 255f, + int.Parse(birdColor[1].ToString()) / 255f, + int.Parse(birdColor[2].ToString()) / 255f ); bird.transform.GetChild(0).GetComponent().color = new Color( - int.Parse(overlayColor[0]) / 255f, - int.Parse(overlayColor[1]) / 255f, - int.Parse(overlayColor[2]) / 255f + int.Parse(overlayColor[0].ToString()) / 255f, + int.Parse(overlayColor[1].ToString()) / 255f, + int.Parse(overlayColor[2].ToString()) / 255f ); } catch @@ -71,25 +71,22 @@ public class GamePlayer : MonoBehaviour lastMoveTime = Time.time; UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable(); instance = this; - highscore = BigInteger.Parse(PlayerPrefs.GetString("HighScoreV2", "0")); - totalNormalBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalNormalBerries", "0")); - totalPoisonBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalPoisonBerries", "0")); - totalSlowBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalSlowBerries", "0")); - totalUltraBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalUltraBerries", "0")); - totalSpeedyBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalSpeedyBerries", "0")); - totalAttempts = BigInteger.Parse(PlayerPrefs.GetString("TotalAttempts", "0")); - } + highscore = BazookaManager.Instance.GetGameStoreHighScore(); + totalNormalBerries = BazookaManager.Instance.GetGameStoreTotalNormalBerries(); + totalPoisonBerries = BazookaManager.Instance.GetGameStoreTotalPoisonBerries(); + totalSlowBerries = BazookaManager.Instance.GetGameStoreTotalSlowBerries(); + totalUltraBerries = BazookaManager.Instance.GetGameStoreTotalUltraBerries(); + totalSpeedyBerries = BazookaManager.Instance.GetGameStoreTotalSpeedyBerries(); + totalAttempts = BazookaManager.Instance.GetGameStoreTotalAttepts(); - void Start() - { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; SpriteRenderer component = bird.GetComponent(); - int num = PlayerPrefs.GetInt("icon", 1); - int num2 = PlayerPrefs.GetInt("overlay", 0); + int num = BazookaManager.Instance.GetBirdIcon(); + int num2 = BazookaManager.Instance.GetBirdOverlay(); if (num == 1) { - component.sprite = Tools.GetIconForUser(PlayerPrefs.GetInt("userId", 0)); + component.sprite = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0); } else { @@ -118,15 +115,14 @@ public class GamePlayer : MonoBehaviour if (component.sprite == null) { component.sprite = Resources.Load("Icons/Icons/bird_1"); - PlayerPrefs.SetInt("icon", 1); + BazookaManager.Instance.SetBirdIcon(1); } if (overlayRender.sprite == null && num2 != 0) { overlayRender.sprite = Resources.Load("Icons/Overlays/overlay_1"); - PlayerPrefs.SetInt("overlay", 1); + BazookaManager.Instance.SetBirdOverlay(1); } - PlayerPrefs.Save(); - backgroundMusic.volume = PlayerPrefs.GetFloat("musicVolume", 1f); + backgroundMusic.volume = BazookaManager.Instance.GetSettingMusicVolume(); screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect; if (Application.isMobilePlatform) { @@ -264,7 +260,7 @@ public class GamePlayer : MonoBehaviour if (doJump && isGrounded) { lastMoveTime = Time.time; - AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Jump"), Camera.main.transform.position, 0.75f * PlayerPrefs.GetFloat("sfxVolume", 1f)); + AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume()); if (boostLeft > 0f || speedyLeft > 0f) { rb.linearVelocity = UnityEngine.Vector2.up * 12f; @@ -401,7 +397,7 @@ public class GamePlayer : MonoBehaviour void Update() { - if (PlayerPrefs.GetInt("Setting2", 0) == 1 && Time.time > nextUpdate) + if (BazookaManager.Instance.GetSettingShowFPS() && Time.time > nextUpdate) { fps = 1f / Time.deltaTime; fpsCounter.text = "FPS: " + Mathf.Round(fps); @@ -448,7 +444,7 @@ public class GamePlayer : MonoBehaviour } else if (UnityEngine.Vector3.Distance(bird.transform.position, berry.transform.position) < 1.5f) { - AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Eat"), Camera.main.transform.position, 1.2f * PlayerPrefs.GetFloat("sfxVolume", 1f)); + AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Eat"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume()); Destroy(berry); totalNormalBerries++; UpdateStats(1, 0); @@ -471,7 +467,7 @@ public class GamePlayer : MonoBehaviour } else if (UnityEngine.Vector3.Distance(bird.transform.position, gameObject7.transform.position) < 1.5f) { - AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Death"), Camera.main.transform.position, 1.2f * PlayerPrefs.GetFloat("sfxVolume", 1f)); + AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Death"), Camera.main.transform.position, 1.2f * BazookaManager.Instance.GetSettingSFXVolume()); Respawn(); totalPoisonBerries++; UpdateStats(0, 0); @@ -494,7 +490,7 @@ public class GamePlayer : MonoBehaviour } else if (UnityEngine.Vector3.Distance(bird.transform.position, gameObject8.transform.position) < 1.5f) { - AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Powerup"), Camera.main.transform.position, 0.35f * PlayerPrefs.GetFloat("sfxVolume", 1f)); + AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Powerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume()); Destroy(gameObject8); totalUltraBerries++; speedyLeft = 0f; @@ -527,7 +523,7 @@ public class GamePlayer : MonoBehaviour } else if (UnityEngine.Vector3.Distance(bird.transform.position, gameObject9.transform.position) < 1.5f) { - AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Downgrade"), Camera.main.transform.position, 0.35f * PlayerPrefs.GetFloat("sfxVolume", 1f)); + AudioSource.PlayClipAtPoint(Resources.Load("Sounds/Downgrade"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume()); Destroy(gameObject9); boostLeft = 0f; slownessLeft = 10f; @@ -556,7 +552,7 @@ public class GamePlayer : MonoBehaviour } else if (UnityEngine.Vector3.Distance(bird.transform.position, gameObject10.transform.position) < 1.5f) { - AudioSource.PlayClipAtPoint(Resources.Load("Sounds/SpeedyPowerup"), Camera.main.transform.position, 0.35f * PlayerPrefs.GetFloat("sfxVolume", 1f)); + AudioSource.PlayClipAtPoint(Resources.Load("Sounds/SpeedyPowerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume()); Destroy(gameObject10); boostLeft = 0f; slownessLeft = 0f; @@ -658,14 +654,13 @@ public class GamePlayer : MonoBehaviour { highscore = score; } - PlayerPrefs.SetString("HighScoreV2", highscore.ToString()); - PlayerPrefs.SetString("TotalNormalBerries", totalNormalBerries.ToString()); - PlayerPrefs.SetString("TotalPoisonBerries", totalPoisonBerries.ToString()); - PlayerPrefs.SetString("TotalSlowBerries", totalSlowBerries.ToString()); - PlayerPrefs.SetString("TotalUltraBerries", totalUltraBerries.ToString()); - PlayerPrefs.SetString("TotalSpeedyBerries", totalSpeedyBerries.ToString()); - PlayerPrefs.SetString("TotalAttempts", totalAttempts.ToString()); - PlayerPrefs.Save(); + BazookaManager.Instance.SetGameStoreHighScore(highscore); + BazookaManager.Instance.SetGameStoreTotalNormalBerries(totalNormalBerries); + BazookaManager.Instance.SetGameStoreTotalPoisonBerries(totalPoisonBerries); + BazookaManager.Instance.SetGameStoreTotalSlowBerries(totalSlowBerries); + BazookaManager.Instance.SetGameStoreTotalUltraBerries(totalUltraBerries); + BazookaManager.Instance.SetGameStoreTotalSpeedyBerries(totalSpeedyBerries); + BazookaManager.Instance.SetGameStoreTotalAttepts(totalAttempts); scoreText.text = $"Score: {Tools.FormatWithCommas(score)} \\u2022 Attempts: {Tools.FormatWithCommas(attempts)}"; highScoreText.text = $"High Score: {Tools.FormatWithCommas(highscore)} \\u2022 Total Attempts: {Tools.FormatWithCommas(totalAttempts)}"; if (restartButton != null) restartButton.GetComponent().material.color = score == 0 ? Color.gray : Color.white; diff --git a/Assets/Scripts/GamePlayerPauseMenu.cs b/Assets/Scripts/GamePlayerPauseMenu.cs index c114717..dfd526c 100644 --- a/Assets/Scripts/GamePlayerPauseMenu.cs +++ b/Assets/Scripts/GamePlayerPauseMenu.cs @@ -21,8 +21,8 @@ public class GamePlayerPauseMenu : MonoBehaviour void Awake() { Instance = this; - musicSlider.value = PlayerPrefs.GetFloat("musicVolume", 1f); - sfxSlider.value = PlayerPrefs.GetFloat("sfxVolume", 1f); + musicSlider.value = BazookaManager.Instance.GetSettingMusicVolume(); + sfxSlider.value = BazookaManager.Instance.GetSettingSFXVolume(); backButton.onClick.AddListener(async () => { await UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("MainMenu"); @@ -30,14 +30,12 @@ public class GamePlayerPauseMenu : MonoBehaviour continueButton.onClick.AddListener(GamePlayer.instance.DisablePause); musicSlider.onValueChanged.AddListener(value => { - PlayerPrefs.SetFloat("musicVolume", value); - PlayerPrefs.Save(); + BazookaManager.Instance.SetSettingMusicVolume(value); songLoop.volume = value; }); sfxSlider.onValueChanged.AddListener(value => { - PlayerPrefs.SetFloat("sfxVolume", value); - PlayerPrefs.Save(); + BazookaManager.Instance.SetSettingSFXVolume(value); }); editUiButton.onClick.AddListener(() => { diff --git a/Assets/Scripts/HideIfSettingFalse.cs b/Assets/Scripts/HideIfSettingFalse.cs index 71cafd7..84d9bbd 100644 --- a/Assets/Scripts/HideIfSettingFalse.cs +++ b/Assets/Scripts/HideIfSettingFalse.cs @@ -1,12 +1,22 @@ using UnityEngine; -public class HideIfSettingFalse : MonoBehaviour -{ - public string setting; +public class HideIfSettingFalse : MonoBehaviour { + public BazookaSetting setting; public bool reverse; - void Awake() - { - gameObject.SetActive(PlayerPrefs.GetInt(setting, 0) == (reverse ? 0 : 1)); + void Start() { + bool value = GetSettingValue(setting); + gameObject.SetActive(value == !reverse); + } + + bool GetSettingValue(BazookaSetting s) { + var b = BazookaManager.Instance; + return s switch { + BazookaSetting.FullScreen => b.GetSettingFullScreen() ?? false, + BazookaSetting.ShowFPS => b.GetSettingShowFPS(), + BazookaSetting.Vsync => b.GetSettingVsync() ?? false, + BazookaSetting.HideSocials => b.GetSettingHideSocials() ?? false, + _ => false + }; } } \ No newline at end of file diff --git a/Assets/Scripts/IconsMenu.cs b/Assets/Scripts/IconsMenu.cs index a5a971f..ea81522 100644 --- a/Assets/Scripts/IconsMenu.cs +++ b/Assets/Scripts/IconsMenu.cs @@ -40,12 +40,12 @@ public class Iconsmenu : MonoBehaviour private void Start() { - defaultIcon = Tools.GetIconForUser(PlayerPrefs.GetInt("userId", 0)); + defaultIcon = Tools.GetIconForUser(BazookaManager.Instance.GetAccountID() ?? 0); icon1.transform.GetChild(0).GetComponent().sprite = defaultIcon; SwitchToIcon(); - SelectOverlay(PlayerPrefs.GetInt("overlay", Mathf.Clamp(PlayerPrefs.GetInt("overlay", 0), 0, 14))); - SelectIcon(PlayerPrefs.GetInt("icon", Mathf.Clamp(PlayerPrefs.GetInt("icon", 0), 1, 8))); - if (PlayerPrefs.GetInt("icon", 0) == 7) + SelectOverlay(BazookaManager.Instance.GetBirdOverlay()); + SelectIcon(BazookaManager.Instance.GetBirdIcon()); + if (BazookaManager.Instance.GetBirdIcon() == 7) { SelectOverlay(0); placeholderButton.interactable = false; @@ -53,9 +53,6 @@ public class Iconsmenu : MonoBehaviour placeholderButton.onClick.AddListener(ToggleKit); backButton.onClick.AddListener(async () => { - PlayerPrefs.SetInt("icon", Mathf.Clamp(PlayerPrefs.GetInt("icon", 0), 1, 8)); - PlayerPrefs.SetInt("overlay", Mathf.Clamp(PlayerPrefs.GetInt("overlay", 0), 0, 14)); - PlayerPrefs.Save(); await SceneManager.LoadSceneAsync("MainMenu"); }); previewBird.GetComponentInParent