VanguardReMaster/client/Assets/Vanguard/Runtime/State/PlayerState.cs

74 lines
2.2 KiB
C#

using System;
using Vanguard.Api.Contracts;
namespace Vanguard.State
{
/// <summary>Текущий профиль игрока, общий для мета-экранов.</summary>
public sealed class PlayerState
{
public Guid UserId { get; private set; }
public string UserName { get; private set; } = string.Empty;
public bool OnboardingCompleted { get; private set; }
public string SelectedTrialDeckId { get; private set; }
public int Gold { get; private set; }
public int Dust { get; private set; }
public int Tokens { get; private set; }
public int Xp { get; private set; }
public int RankedMmr { get; private set; }
public int CasualMmr { get; private set; }
public int Matches { get; private set; }
public int Wins { get; private set; }
public event Action Changed;
public void Apply(AuthResponse response)
{
UserId = response.UserId;
UserName = response.UserName ?? string.Empty;
OnboardingCompleted = response.OnboardingCompleted;
NotifyChanged();
}
public void Apply(MeResponse me)
{
UserId = me.UserId;
UserName = me.UserName ?? string.Empty;
OnboardingCompleted = me.OnboardingCompleted;
SelectedTrialDeckId = me.SelectedTrialDeckId;
Gold = me.Gold;
Dust = me.Dust;
Tokens = me.Tokens;
Xp = me.Xp;
RankedMmr = me.RankedMmr;
CasualMmr = me.CasualMmr;
Matches = me.Matches;
Wins = me.Wins;
NotifyChanged();
}
public void Clear()
{
UserId = Guid.Empty;
UserName = string.Empty;
OnboardingCompleted = false;
SelectedTrialDeckId = null;
Gold = 0;
Dust = 0;
Tokens = 0;
Xp = 0;
RankedMmr = 0;
CasualMmr = 0;
Matches = 0;
Wins = 0;
NotifyChanged();
}
private void NotifyChanged()
{
var handler = Changed;
if (handler != null)
handler();
}
}
}