From af6ac9106bbe9bf3650360aa70cd66a9a8fa9dd2 Mon Sep 17 00:00:00 2001 From: TheJordan Date: Fri, 6 Mar 2026 23:35:32 +0100 Subject: [PATCH] Added : Utils and debug functions --- CHANGELOG.md | 3 +- src/JordanMod/utils/Debug.cs | 21 +++++++++++++ src/JordanMod/utils/Helper.cs | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/JordanMod/utils/Debug.cs create mode 100644 src/JordanMod/utils/Helper.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index df6b54b..52b7b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # v0.1.0 | Project setup - Initial project setup -- Added config dependency \ No newline at end of file +- Added config dependency +- Added utils and debug functions \ No newline at end of file diff --git a/src/JordanMod/utils/Debug.cs b/src/JordanMod/utils/Debug.cs new file mode 100644 index 0000000..fb92512 --- /dev/null +++ b/src/JordanMod/utils/Debug.cs @@ -0,0 +1,21 @@ +namespace JordanMod; + +class Debug +{ + + public static void Log(string message) + { + Plugin.Log.LogInfo(message); + } + + public static void LogWarning(string message) + { + Plugin.Log.LogWarning(message); + } + + public static void LogError(string message) + { + Plugin.Log.LogError(message); + } + +} \ No newline at end of file diff --git a/src/JordanMod/utils/Helper.cs b/src/JordanMod/utils/Helper.cs new file mode 100644 index 0000000..85c79be --- /dev/null +++ b/src/JordanMod/utils/Helper.cs @@ -0,0 +1,59 @@ +using System.Collections; +using Photon.Pun; +using UnityEngine; +using UnityEngine.SceneManagement; +using Zorro.Core; + +namespace AncestralMod; + +public static class Helper +{ + private static ItemDatabase Database => SingletonAsset.Instance; + + public static Item FindItemByName(string itemName, out Item? item) + { + item = Database.Objects.Find(item => item.name.Equals(itemName, System.StringComparison.OrdinalIgnoreCase)); + return item; + } + + public static bool IsOnIsland() + { + return SceneManager.GetActiveScene().name.ToLower().StartsWith("level_") || SceneManager.GetActiveScene().name == "WilIsland"; + } + + public static float MouseScrollDelta() + { + return Input.mouseScrollDelta.y; + } + + public static bool IsMasterClient() + { + return PhotonNetwork.IsConnected && PhotonNetwork.IsMasterClient; + } + + public static void LogToPlayer(string _message) + { + string message; + if (_message.Contains("{_message}"; + + Object.FindAnyObjectByType()?.SendMessage(message); + } + + public static IEnumerator WaitUntilPlayerHasCharacter(Photon.Realtime.Player player, System.Action onComplete, int maxTries = 30, float waitTime = 1f) + { + int tries = 0; + Character? character = null; + while (character == null && tries < maxTries) + { + character = PlayerHandler.GetPlayerCharacter(player); + if (character == null) + { + tries++; + yield return new WaitForSeconds(waitTime); + } + } + onComplete?.Invoke(character); + } + +}