diff --git a/Tools/Extensions.cs b/Tools/Extensions.cs new file mode 100644 index 0000000..94b456e --- /dev/null +++ b/Tools/Extensions.cs @@ -0,0 +1,72 @@ +using Photon.Pun; +using System; +using System.Collections.Generic; +using System.Text; +using UnityEngine; + +namespace TooMuchInfo.Tools; + +public enum GamePlatform +{ + Steam, + OculusPC, + PSVR, + Pico, + PC, + Standalone, + Unknown, +} + +public static class Extensions +{ + public static Dictionary PlayerPlatforms = new(); + public static Dictionary> PlayerMods = new(); + public static Dictionary AccountCreationDates = new(); + public static List PlayerWithCosmetics = []; + public static readonly Dictionary PlayerPing = new(); + + public static string AnimateGradiant(this string text, Color32 baseColor, float speed = 2f) + { + if (string.IsNullOrEmpty(text)) + return text; + + StringBuilder sb = new(); + int len = text.Length; + + for (int i = 0; i < len; i++) + { + float offset = (float)i / len; + float t = (Mathf.Sin(Time.time * speed + (1f - offset) * Mathf.PI * 2) + 1f) * 0.5f; + Color blended = Color.Lerp(baseColor, Color.white, t); + string hex = ColorUtility.ToHtmlStringRGB(blended); + sb.Append($"{text[i]}"); + } + + return sb.ToString(); + } + + public static GamePlatform GetPlatform(this VRRig rig) => + PlayerPlatforms.GetValueOrDefault(rig, GamePlatform.Unknown); + + public static string ParsePlatform(this GamePlatform gamePlatform) => + gamePlatform switch + { + GamePlatform.Unknown => "UNKNOWN", + GamePlatform.Steam => "STEAM", + GamePlatform.PSVR => "PSVR", + GamePlatform.Pico => "PICO", + GamePlatform.OculusPC => "OCULUS PCVR", + GamePlatform.PC => "PC", + GamePlatform.Standalone => "STANDALONE", + var _ => throw new ArgumentOutOfRangeException(), + }; + + public static DateTime GetAccountCreationDate(this VRRig rig) => AccountCreationDates[rig.creator.UserId]; + + public static string[] GetPlayerMods(this VRRig rig) => PlayerMods[rig].ToArray(); + + public static bool HasCosmetics(this VRRig rig) => PlayerWithCosmetics.Contains(rig); + + public static int GetPing(this VRRig rig) => + PlayerPing.TryGetValue(rig, out int ping) ? ping : PhotonNetwork.GetPing(); +}