-
Notifications
You must be signed in to change notification settings - Fork 17
fix: scene emotes masked loop #9532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
Explorer/Assets/DCL/AvatarRendering/Emotes/Tests/CharacterMaskedEmoteComponentShould.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| using DCL.ECSComponents; | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
| using Utility.Animations; | ||
|
|
||
| namespace DCL.AvatarRendering.Emotes.Tests | ||
| { | ||
| public class CharacterMaskedEmoteComponentShould | ||
| { | ||
| private const float CLIP_LENGTH = 2f; | ||
|
|
||
| private GameObject gameObject = null!; | ||
| private EmoteReferences emoteReferences = null!; | ||
| private AnimationClip clip = null!; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| gameObject = new GameObject(nameof(CharacterMaskedEmoteComponentShould)); | ||
| emoteReferences = gameObject.AddComponent<EmoteReferences>(); | ||
|
|
||
| clip = new AnimationClip { name = "TestClip" }; | ||
| clip.SetCurve(string.Empty, typeof(Transform), "localPosition.x", AnimationCurve.Linear(0, 0, CLIP_LENGTH, 1)); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| if (gameObject != null) Object.DestroyImmediate(gameObject); | ||
| if (clip != null) Object.DestroyImmediate(clip); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PlayingEmoteDuration_ReturnsZero_WhenNoReferenceIsSet() | ||
| { | ||
| var masked = new CharacterMaskedEmoteComponent(); | ||
|
|
||
| Assert.AreEqual(0f, masked.PlayingEmoteDuration, 0.001f); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PlayingEmoteDuration_ReturnsZero_WhenReferenceHasNoAvatarClip() | ||
| { | ||
| emoteReferences.Initialize(null, null, null, null, 0, legacy: false); | ||
|
|
||
| var masked = new CharacterMaskedEmoteComponent { CurrentEmoteReference = emoteReferences }; | ||
|
|
||
| Assert.AreEqual(0f, masked.PlayingEmoteDuration, 0.001f); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PlayingEmoteDuration_ReturnsAvatarClipLength() | ||
| { | ||
| emoteReferences.Initialize(clip, null, null, null, 0, legacy: false); | ||
|
|
||
| var masked = new CharacterMaskedEmoteComponent { CurrentEmoteReference = emoteReferences }; | ||
|
|
||
| Assert.AreEqual(CLIP_LENGTH, masked.PlayingEmoteDuration, 0.001f, | ||
| "The broadcast duration of a masked emote comes from the masked clip itself, not from the full body emote."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void PlayingEmoteDuration_ScalesWithAnimatorSpeed() | ||
| { | ||
| Animator animator = gameObject.AddComponent<Animator>(); | ||
| animator.speed = 2f; | ||
| emoteReferences.Initialize(clip, null, animator, null, 0, legacy: false); | ||
|
|
||
| var masked = new CharacterMaskedEmoteComponent { CurrentEmoteReference = emoteReferences }; | ||
|
|
||
| Assert.AreEqual(CLIP_LENGTH * 2f, masked.PlayingEmoteDuration, 0.001f); | ||
| } | ||
|
|
||
| [Test] | ||
| public void IsPlaying_ReturnsFalse_WhenNoReferenceIsSet() | ||
| { | ||
| var masked = new CharacterMaskedEmoteComponent(); | ||
| masked.SetAnimationTag(AnimationHashes.MASKED_EMOTE); | ||
|
|
||
| Assert.IsFalse(masked.IsPlaying); | ||
| } | ||
|
|
||
| [Test] | ||
| public void IsPlaying_ReturnsTrue_WhenAnimatorInMaskedEmoteLoopTag() | ||
| { | ||
| emoteReferences.Initialize(clip, null, null, null, 0, legacy: false); | ||
|
|
||
| var masked = new CharacterMaskedEmoteComponent { CurrentEmoteReference = emoteReferences }; | ||
| masked.SetAnimationTag(AnimationHashes.MASKED_EMOTE_LOOP); | ||
|
|
||
| Assert.IsTrue(masked.IsPlaying); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Reset_ClearsTheEmoteUrn() | ||
| { | ||
| var masked = new CharacterMaskedEmoteComponent | ||
| { | ||
| EmoteUrn = "urn:decentraland:off-chain:scene-emote:test-scene-hash-false", | ||
| EmoteLoop = true, | ||
| CurrentEmoteReference = emoteReferences, | ||
| Mask = AvatarEmoteMask.AemUpperBody, | ||
| }; | ||
|
|
||
| masked.Reset(); | ||
|
|
||
| Assert.IsTrue(masked.EmoteUrn.IsNullOrEmpty(), | ||
| "Clearing the urn is what stops a finished emote from being replayed."); | ||
| Assert.IsNull(masked.CurrentEmoteReference); | ||
| Assert.IsFalse(masked.EmoteLoop); | ||
| } | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
Explorer/Assets/DCL/AvatarRendering/Emotes/Tests/CharacterMaskedEmoteComponentShould.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
Explorer/Assets/DCL/AvatarRendering/Emotes/Tests/SceneMaskedEmoteSystemShould.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| using Arch.Core; | ||
| using CommunicationData.URLHelpers; | ||
| using DCL.AvatarRendering.AvatarShape.Components; | ||
| using DCL.AvatarRendering.AvatarShape.UnityInterface; | ||
| using DCL.AvatarRendering.Emotes.Play; | ||
| using DCL.AvatarRendering.Loading.Assets; | ||
| using DCL.AvatarRendering.Loading.Components; | ||
| using DCL.ECSComponents; | ||
| using DCL.Multiplayer.Emotes; | ||
| using DCL.Utilities; | ||
| using ECS.StreamableLoading.Common.Components; | ||
| using ECS.TestSuite; | ||
| using NSubstitute; | ||
| using NUnit.Framework; | ||
| using SceneRunner.Scene; | ||
| using UnityEngine; | ||
| using Object = UnityEngine.Object; | ||
|
|
||
| namespace DCL.AvatarRendering.Emotes.Tests | ||
| { | ||
| public class SceneMaskedEmoteSystemShould : UnitySystemTestBase<SceneMaskedEmoteSystem> | ||
| { | ||
| private const string EMOTE_URN_FORMAT = "urn:decentraland:off-chain:scene-emote:test-scene-bafkreiemotehash-{0}"; | ||
|
|
||
| private World globalWorld = null!; | ||
| private Entity globalPlayerEntity; | ||
| private IEmoteStorage emoteStorage = null!; | ||
| private GameObject poolRoot = null!; | ||
| private GameObject audioSourcePrefab = null!; | ||
| private GameObject avatarBaseGameObject = null!; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| poolRoot = new GameObject("ROOT_POOL_CONTAINER"); | ||
| audioSourcePrefab = new GameObject("EmoteAudioSource"); | ||
| AudioSource audioSource = audioSourcePrefab.AddComponent<AudioSource>(); | ||
| var emotePlayer = new EmotePlayer(audioSource, ScriptableObject.CreateInstance<EmoteMaskCatalog>(), legacyAnimationsEnabled: true); | ||
|
|
||
| globalWorld = World.Create(); | ||
| globalPlayerEntity = globalWorld.Create(new AvatarShapeComponent { BodyShape = BodyShape.MALE }); | ||
|
|
||
| avatarBaseGameObject = new GameObject(nameof(AvatarBase)); | ||
| var avatarBaseProxy = new ObjectProxy<AvatarBase>(); | ||
| avatarBaseProxy.SetObject(avatarBaseGameObject.AddComponent<AvatarBase>()); | ||
|
|
||
| emoteStorage = Substitute.For<IEmoteStorage>(); | ||
|
|
||
| // The player stands in the scene that triggered the emote, so the play conditions are met. | ||
| ISceneStateProvider sceneStateProvider = Substitute.For<ISceneStateProvider>(); | ||
| sceneStateProvider.IsCurrent.Returns(true); | ||
|
|
||
| system = new SceneMaskedEmoteSystem(world, globalWorld, globalPlayerEntity, avatarBaseProxy, | ||
| emotePlayer, emoteStorage, Substitute.For<IEmotesMessageBus>(), sceneStateProvider); | ||
| } | ||
|
|
||
| protected override void OnTearDown() | ||
| { | ||
| globalWorld.Dispose(); | ||
| Object.DestroyImmediate(avatarBaseGameObject); | ||
| Object.DestroyImmediate(audioSourcePrefab); | ||
| Object.DestroyImmediate(poolRoot); | ||
| } | ||
|
pravusjif marked this conversation as resolved.
|
||
|
|
||
| [Test] | ||
| public void DiscardNonLoopingEmoteThatAlreadyPlayed() | ||
| { | ||
| Entity entity = CreateSuspendedMaskedEmote(loop: false); | ||
|
|
||
| system!.Update(0); | ||
|
|
||
| CharacterMaskedEmoteComponent masked = world.Get<CharacterMaskedEmoteComponent>(entity); | ||
|
|
||
| Assert.IsTrue(masked.EmoteUrn.IsNullOrEmpty(), | ||
| "A one-shot masked emote that already played must not stay resumable: while its urn is set, every frame that meets the play conditions starts the emote again."); | ||
| Assert.IsNull(masked.CurrentEmoteReference); | ||
| Assert.IsFalse(globalWorld.Has<EmotePendingToBroadcast>(globalPlayerEntity), | ||
| "Nothing was played, so nothing must be broadcast."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void KeepLoopingEmoteResumable() | ||
| { | ||
| Entity entity = CreateSuspendedMaskedEmote(loop: true); | ||
|
|
||
| system!.Update(0); | ||
|
|
||
| CharacterMaskedEmoteComponent masked = world.Get<CharacterMaskedEmoteComponent>(entity); | ||
|
|
||
| Assert.IsFalse(masked.EmoteUrn.IsNullOrEmpty(), | ||
| "A looping masked emote is resumed once the play conditions are met again, so its urn must survive being suspended."); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A masked emote in the state a non-permanent stop leaves behind: the animation is torn down | ||
| /// but the urn is kept so that the emote can be resumed. | ||
| /// </summary> | ||
| private Entity CreateSuspendedMaskedEmote(bool loop) | ||
| { | ||
| IEmote emote = Substitute.For<IEmote>(); | ||
| emote.IsLoading.Returns(false); | ||
| emote.IsLooping().Returns(loop); | ||
|
|
||
| // Empty results: the asset is not resident, so playback stops short of touching the avatar view. | ||
| emote.AssetResults.Returns(new StreamableLoadingResult<AttachmentRegularAsset>?[BodyShape.COUNT]); | ||
|
|
||
| emoteStorage.TryGetElement(Arg.Any<URN>(), out Arg.Any<IEmote>()) | ||
| .Returns(call => | ||
| { | ||
| call[1] = emote; | ||
| return true; | ||
| }); | ||
|
|
||
| return world.Create(new CharacterMaskedEmoteComponent | ||
| { | ||
| EmoteUrn = string.Format(EMOTE_URN_FORMAT, loop.ToString().ToLower()), | ||
| Mask = AvatarEmoteMask.AemUpperBody, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
2 changes: 2 additions & 0 deletions
2
Explorer/Assets/DCL/AvatarRendering/Emotes/Tests/SceneMaskedEmoteSystemShould.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.