44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
|
|
namespace XGame
|
|
{
|
|
public static class PlayerProfileStore
|
|
{
|
|
private static PlayerProfileData current = PlayerProfileData.CreateDefault();
|
|
|
|
public static event Action<PlayerProfileData> 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<PlayerProfileData> 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;
|
|
});
|
|
}
|
|
}
|
|
}
|