Add player profile system
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using XGame;
|
||||
#if UNITY_EDITOR
|
||||
using XGame.EditorTools;
|
||||
#endif
|
||||
|
||||
public sealed class PlayerProfileModuleTests
|
||||
{
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
PlayerProfileStore.ResetToDefault();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DefaultProfile_HasPlayableCombatStats()
|
||||
{
|
||||
PlayerProfileData profile = PlayerProfileData.CreateDefault();
|
||||
|
||||
Assert.That(profile.Nickname, Is.EqualTo("Player"));
|
||||
Assert.That(profile.Uid, Is.EqualTo("0"));
|
||||
Assert.That(profile.Lv, Is.EqualTo(1));
|
||||
Assert.That(profile.HpMax, Is.GreaterThan(0));
|
||||
Assert.That(profile.Hp, Is.EqualTo(profile.HpMax));
|
||||
Assert.That(profile.MpMax, Is.GreaterThan(0));
|
||||
Assert.That(profile.Mp, Is.EqualTo(profile.MpMax));
|
||||
Assert.That(profile.Ad, Is.GreaterThan(0));
|
||||
Assert.That(profile.MoveSpeed, Is.GreaterThan(0f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Replace_SanitizesInvalidValuesAndRaisesChanged()
|
||||
{
|
||||
int changed = 0;
|
||||
Action<PlayerProfileData> handler = _ => changed++;
|
||||
PlayerProfileStore.Changed += handler;
|
||||
|
||||
try
|
||||
{
|
||||
PlayerProfileStore.Replace(new PlayerProfileData
|
||||
{
|
||||
Nickname = "Alice",
|
||||
Uid = "42",
|
||||
AvatarId = -1,
|
||||
RoleType = PlayerRoleType.Mage,
|
||||
Lv = -5,
|
||||
Exp = -20,
|
||||
Hp = 999,
|
||||
HpMax = 100,
|
||||
Mp = -3,
|
||||
MpMax = 50,
|
||||
AtkSpeed = -1f,
|
||||
MoveSpeed = -2f
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
PlayerProfileStore.Changed -= handler;
|
||||
}
|
||||
|
||||
PlayerProfileData current = PlayerProfileStore.Current;
|
||||
Assert.That(changed, Is.EqualTo(1));
|
||||
Assert.That(current.AvatarId, Is.EqualTo(0));
|
||||
Assert.That(current.Lv, Is.EqualTo(1));
|
||||
Assert.That(current.Exp, Is.EqualTo(0));
|
||||
Assert.That(current.Hp, Is.EqualTo(100));
|
||||
Assert.That(current.Mp, Is.EqualTo(0));
|
||||
Assert.That(current.AtkSpeed, Is.GreaterThan(0f));
|
||||
Assert.That(current.MoveSpeed, Is.GreaterThan(0f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Experience01_ClampsAgainstLevelRequirement()
|
||||
{
|
||||
PlayerProfileData profile = PlayerProfileData.CreateDefault();
|
||||
profile.Lv = 2;
|
||||
profile.Exp = 150;
|
||||
|
||||
Assert.That(profile.Experience01, Is.EqualTo(0.75f).Within(0.001f));
|
||||
|
||||
profile.Exp = 999;
|
||||
Assert.That(profile.Experience01, Is.EqualTo(1f));
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[Test]
|
||||
public void PlayerProfileJsonFiles_PassPrefabBuilderValidation()
|
||||
{
|
||||
Assert.That(JsonUIPrefabBuilder.Validate("../Doc/UIPrefabCreater/UI_PlayerProfileHud.json").Ok, Is.True);
|
||||
Assert.That(JsonUIPrefabBuilder.Validate("../Doc/UIPrefabCreater/UI_PlayerProfilePanel.json").Ok, Is.True);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b4203a5eef50434ca57e39295869354
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user