using System; namespace XGame { public static class PlayerProfileStore { private static PlayerProfileData current = PlayerProfileData.CreateDefault(); public static event Action Changed; public static PlayerProfileData Current => current.Clone(); public static void Replace(PlayerProfileData profile) { current = profile == null ? PlayerProfileData.CreateDefault() : profile.Clone(); current.Normalize(); Changed?.Invoke(Current); } public static void Update(Action updater) { PlayerProfileData next = Current; updater?.Invoke(next); Replace(next); } public static void ResetToDefault() { Replace(PlayerProfileData.CreateDefault()); } public static void SetSessionIdentity(string nickname, string uid, int avatarId = 0, PlayerRoleType roleType = PlayerRoleType.Adventurer) { Update(profile => { profile.Nickname = nickname; profile.Uid = uid; profile.AvatarId = avatarId; profile.RoleType = roleType; }); } } }