Add a test that creates, deletes and creates a character (#2193)
* Add a test that creates, deletes and creates a character * My prs conflict with my other prs Bottom text * Add checking for profile equality between client and server * Fix randomizing outside of an assert and add equals/hashcode and fix equality check * Fix colors being slightly off when received by the server
This commit is contained in:
125
Content.IntegrationTests/Tests/Lobby/CharacterCreationTest.cs
Normal file
125
Content.IntegrationTests/Tests/Lobby/CharacterCreationTest.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Client;
|
||||
using Content.Client.Interfaces;
|
||||
using Content.Client.State;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Preferences;
|
||||
using Content.Shared;
|
||||
using Content.Shared.Preferences;
|
||||
using NUnit.Framework;
|
||||
using Robust.Client.Interfaces.State;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Lobby
|
||||
{
|
||||
[TestFixture]
|
||||
[TestOf(typeof(ClientPreferencesManager))]
|
||||
[TestOf(typeof(ServerPreferencesManager))]
|
||||
public class CharacterCreationTest : ContentIntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public async Task CreateDeleteCreateTest()
|
||||
{
|
||||
var (client, server) = await StartConnectedServerClientPair();
|
||||
|
||||
var clientNetManager = client.ResolveDependency<IClientNetManager>();
|
||||
var clientStateManager = client.ResolveDependency<IStateManager>();
|
||||
var clientPrefManager = client.ResolveDependency<IClientPreferencesManager>();
|
||||
|
||||
var serverConfig = server.ResolveDependency<IConfigurationManager>();
|
||||
var serverTicker = server.ResolveDependency<IGameTicker>();
|
||||
var serverPrefManager = server.ResolveDependency<IServerPreferencesManager>();
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
await client.WaitIdleAsync();
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var lobbyCvar = CCVars.GameLobbyEnabled;
|
||||
serverConfig.SetCVar(lobbyCvar.Name, true);
|
||||
|
||||
serverTicker.RestartRound();
|
||||
});
|
||||
|
||||
Assert.That(serverTicker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
|
||||
|
||||
await WaitUntil(client, () => clientStateManager.CurrentState is LobbyState, maxTicks: 60);
|
||||
|
||||
Assert.NotNull(clientNetManager.ServerChannel);
|
||||
|
||||
var clientNetId = clientNetManager.ServerChannel.UserId;
|
||||
HumanoidCharacterProfile profile = null;
|
||||
|
||||
await client.WaitAssertion(() =>
|
||||
{
|
||||
clientPrefManager.SelectCharacter(0);
|
||||
|
||||
var clientCharacters = clientPrefManager.Preferences.Characters;
|
||||
Assert.That(clientCharacters.Count, Is.EqualTo(1));
|
||||
|
||||
Assert.That(clientStateManager.CurrentState, Is.TypeOf<LobbyState>());
|
||||
|
||||
profile = HumanoidCharacterProfile.Random();
|
||||
clientPrefManager.CreateCharacter(profile);
|
||||
|
||||
clientCharacters = clientPrefManager.Preferences.Characters;
|
||||
|
||||
Assert.That(clientCharacters.Count, Is.EqualTo(2));
|
||||
Assert.That(clientCharacters[1].MemberwiseEquals(profile));
|
||||
});
|
||||
|
||||
await WaitUntil(server, () => serverPrefManager.GetPreferences(clientNetId).Characters.Count == 2, maxTicks: 60);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var serverCharacters = serverPrefManager.GetPreferences(clientNetId).Characters;
|
||||
|
||||
Assert.That(serverCharacters.Count, Is.EqualTo(2));
|
||||
Assert.That(serverCharacters[1].MemberwiseEquals(profile));
|
||||
});
|
||||
|
||||
await client.WaitAssertion(() =>
|
||||
{
|
||||
clientPrefManager.DeleteCharacter(1);
|
||||
|
||||
var clientCharacters = clientPrefManager.Preferences.Characters.Count;
|
||||
Assert.That(clientCharacters, Is.EqualTo(1));
|
||||
});
|
||||
|
||||
await WaitUntil(server, () => serverPrefManager.GetPreferences(clientNetId).Characters.Count == 1, maxTicks: 60);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var serverCharacters = serverPrefManager.GetPreferences(clientNetId).Characters.Count;
|
||||
Assert.That(serverCharacters, Is.EqualTo(1));
|
||||
});
|
||||
|
||||
await client.WaitIdleAsync();
|
||||
|
||||
await client.WaitAssertion(() =>
|
||||
{
|
||||
profile = HumanoidCharacterProfile.Random();
|
||||
|
||||
clientPrefManager.CreateCharacter(profile);
|
||||
|
||||
var clientCharacters = clientPrefManager.Preferences.Characters;
|
||||
|
||||
Assert.That(clientCharacters.Count, Is.EqualTo(2));
|
||||
Assert.That(clientCharacters[1].MemberwiseEquals(profile));
|
||||
});
|
||||
|
||||
await WaitUntil(server, () => serverPrefManager.GetPreferences(clientNetId).Characters.Count == 2, maxTicks: 60);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var serverCharacters = serverPrefManager.GetPreferences(clientNetId).Characters;
|
||||
|
||||
Assert.That(serverCharacters.Count, Is.EqualTo(2));
|
||||
Assert.That(serverCharacters[1].MemberwiseEquals(profile));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ namespace Content.Shared.Preferences
|
||||
Color skinColor)
|
||||
{
|
||||
HairStyleName = hairStyleName;
|
||||
HairColor = hairColor;
|
||||
HairColor = ClampColor(hairColor);
|
||||
FacialHairStyleName = facialHairStyleName;
|
||||
FacialHairColor = facialHairColor;
|
||||
EyeColor = eyeColor;
|
||||
SkinColor = skinColor;
|
||||
FacialHairColor = ClampColor(facialHairColor);
|
||||
EyeColor = ClampColor(eyeColor);
|
||||
SkinColor = ClampColor(skinColor);
|
||||
}
|
||||
|
||||
public string HairStyleName { get; }
|
||||
@@ -102,6 +102,11 @@ namespace Content.Shared.Preferences
|
||||
}
|
||||
}
|
||||
|
||||
public static Color ClampColor(Color color)
|
||||
{
|
||||
return new Color(color.RByte, color.GByte, color.BByte);
|
||||
}
|
||||
|
||||
public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearance appearance)
|
||||
{
|
||||
string hairStyleName;
|
||||
@@ -136,22 +141,17 @@ namespace Content.Shared.Preferences
|
||||
facialHairColor,
|
||||
eyeColor,
|
||||
skinColor);
|
||||
|
||||
static Color ClampColor(Color color)
|
||||
{
|
||||
return new Color(color.RByte, color.GByte, color.BByte);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MemberwiseEquals(ICharacterAppearance maybeOther)
|
||||
{
|
||||
if (!(maybeOther is HumanoidCharacterAppearance other)) return false;
|
||||
if (HairStyleName != other.HairStyleName) return false;
|
||||
if (HairColor != other.HairColor) return false;
|
||||
if (!HairColor.Equals(other.HairColor)) return false;
|
||||
if (FacialHairStyleName != other.FacialHairStyleName) return false;
|
||||
if (FacialHairColor != other.FacialHairColor) return false;
|
||||
if (EyeColor != other.EyeColor) return false;
|
||||
if (SkinColor != other.SkinColor) return false;
|
||||
if (!FacialHairColor.Equals(other.FacialHairColor)) return false;
|
||||
if (!EyeColor.Equals(other.EyeColor)) return false;
|
||||
if (!SkinColor.Equals(other.SkinColor)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -243,5 +244,22 @@ namespace Content.Shared.Preferences
|
||||
if (!_antagPreferences.SequenceEqual(other._antagPreferences)) return false;
|
||||
return Appearance.MemberwiseEquals(other.Appearance);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is HumanoidCharacterProfile other && MemberwiseEquals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
Name,
|
||||
Age,
|
||||
Sex,
|
||||
PreferenceUnavailable,
|
||||
_jobPriorities,
|
||||
_antagPreferences,
|
||||
Appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user