-
Notifications
You must be signed in to change notification settings - Fork 17
fix: scene's gliding restriction stayed active after the player left that scene #9518
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 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
153 changes: 153 additions & 0 deletions
153
Explorer/Assets/DCL/SDKComponents/InputModifier/Tests/InputModifierComponentShould.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,153 @@ | ||
| using DCL.SDKComponents.InputModifier.Components; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace DCL.SDKComponents.InputModifier.Tests | ||
| { | ||
| public class InputModifierComponentShould | ||
| { | ||
| public enum ModifierFlag | ||
| { | ||
| Walk, | ||
| Jog, | ||
| Run, | ||
| Jump, | ||
| Emote, | ||
| DoubleJump, | ||
| Gliding, | ||
| All, | ||
| } | ||
|
|
||
| [Test] | ||
| public void BeEverythingEnabled_ByDefault() | ||
| { | ||
| var component = new InputModifierComponent(); | ||
| Assert.IsTrue(component.EverythingEnabled); | ||
| } | ||
|
|
||
| [TestCase(ModifierFlag.Walk)] | ||
| [TestCase(ModifierFlag.Jog)] | ||
| [TestCase(ModifierFlag.Run)] | ||
| [TestCase(ModifierFlag.Jump)] | ||
| [TestCase(ModifierFlag.Emote)] | ||
| [TestCase(ModifierFlag.DoubleJump)] | ||
| [TestCase(ModifierFlag.Gliding)] | ||
| [TestCase(ModifierFlag.All)] | ||
| public void NotBeEverythingEnabled_WhenAnyFlagDisabled(ModifierFlag flag) | ||
| { | ||
| var component = new InputModifierComponent(); | ||
| Set(ref component, flag, true); | ||
|
|
||
| Assert.IsFalse(component.EverythingEnabled); | ||
| } | ||
|
|
||
| [TestCase(ModifierFlag.Walk)] | ||
| [TestCase(ModifierFlag.Jog)] | ||
| [TestCase(ModifierFlag.Run)] | ||
| [TestCase(ModifierFlag.Jump)] | ||
| [TestCase(ModifierFlag.Emote)] | ||
| [TestCase(ModifierFlag.DoubleJump)] | ||
| [TestCase(ModifierFlag.Gliding)] | ||
| public void ReportEveryFlagDisabled_WhenDisableAllIsSet(ModifierFlag flag) | ||
| { | ||
| // DisableAll must dominate every individual flag getter. | ||
| var component = new InputModifierComponent { DisableAll = true }; | ||
|
|
||
| Assert.IsTrue(Get(in component, flag)); | ||
| } | ||
|
|
||
| [TestCase(ModifierFlag.Walk)] | ||
| [TestCase(ModifierFlag.Jog)] | ||
| [TestCase(ModifierFlag.Run)] | ||
| [TestCase(ModifierFlag.Jump)] | ||
| [TestCase(ModifierFlag.Emote)] | ||
| [TestCase(ModifierFlag.DoubleJump)] | ||
| [TestCase(ModifierFlag.Gliding)] | ||
| public void SetOnlyTheTargetedFlag_WhenDisabledIndividually(ModifierFlag flag) | ||
| { | ||
| // Each setter must map to its own bit and leave the others untouched. | ||
| var component = new InputModifierComponent(); | ||
| Set(ref component, flag, true); | ||
|
|
||
| foreach (ModifierFlag other in System.Enum.GetValues(typeof(ModifierFlag))) | ||
| { | ||
| if (other == flag) continue; | ||
|
|
||
| Assert.IsFalse(Get(in component, other), $"{other} must stay enabled when only {flag} is disabled"); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void ClearOnlyTheTargetedFlag_WhenSetBackToFalse() | ||
| { | ||
| var component = new InputModifierComponent(); | ||
| component.DisableWalk = true; | ||
| component.DisableGliding = true; | ||
|
|
||
| component.DisableWalk = false; | ||
|
|
||
| Assert.IsFalse(component.DisableWalk); | ||
| Assert.IsTrue(component.DisableGliding); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BeEverythingEnabled_AfterRemoveAllModifiers() | ||
| { | ||
| var component = new InputModifierComponent(); | ||
| component.DisableWalk = true; | ||
| component.DisableGliding = true; | ||
| component.DisableDoubleJump = true; | ||
|
|
||
| component.RemoveAllModifiers(); | ||
|
|
||
| Assert.IsTrue(component.EverythingEnabled); | ||
| Assert.IsFalse(component.DisableWalk); | ||
| Assert.IsFalse(component.DisableGliding); | ||
| Assert.IsFalse(component.DisableDoubleJump); | ||
| } | ||
|
|
||
| private static void Set(ref InputModifierComponent component, ModifierFlag flag, bool value) | ||
| { | ||
| switch (flag) | ||
| { | ||
| case ModifierFlag.Walk: | ||
| component.DisableWalk = value; | ||
| break; | ||
| case ModifierFlag.Jog: | ||
| component.DisableJog = value; | ||
| break; | ||
| case ModifierFlag.Run: | ||
| component.DisableRun = value; | ||
| break; | ||
| case ModifierFlag.Jump: | ||
| component.DisableJump = value; | ||
| break; | ||
| case ModifierFlag.Emote: | ||
| component.DisableEmote = value; | ||
| break; | ||
| case ModifierFlag.DoubleJump: | ||
| component.DisableDoubleJump = value; | ||
| break; | ||
| case ModifierFlag.Gliding: | ||
| component.DisableGliding = value; | ||
| break; | ||
| case ModifierFlag.All: | ||
| component.DisableAll = value; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| private static bool Get(in InputModifierComponent component, ModifierFlag flag) => | ||
| flag switch | ||
| { | ||
| ModifierFlag.Walk => component.DisableWalk, | ||
| ModifierFlag.Jog => component.DisableJog, | ||
| ModifierFlag.Run => component.DisableRun, | ||
| ModifierFlag.Jump => component.DisableJump, | ||
| ModifierFlag.Emote => component.DisableEmote, | ||
| ModifierFlag.DoubleJump => component.DisableDoubleJump, | ||
| ModifierFlag.Gliding => component.DisableGliding, | ||
| ModifierFlag.All => component.DisableAll, | ||
| _ => false, | ||
| }; | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
Explorer/Assets/DCL/SDKComponents/InputModifier/Tests/InputModifierComponentShould.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
...ssets/DCL/SDKComponents/InputModifier/Tests/InputModifierHandlerSystemCrossSceneShould.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,132 @@ | ||
| using Arch.Core; | ||
| using CRDT; | ||
| using CrdtEcsBridge.Components; | ||
| using DCL.ECSComponents; | ||
| using DCL.SceneRestrictionBusController.SceneRestriction; | ||
| using DCL.SceneRestrictionBusController.SceneRestrictionBus; | ||
| using DCL.SDKComponents.InputModifier.Components; | ||
| using DCL.SDKComponents.PlayerInputMovement.Systems; | ||
| using NSubstitute; | ||
| using NUnit.Framework; | ||
| using SceneRunner.Scene; | ||
|
|
||
| namespace DCL.SDKComponents.InputModifier.Tests | ||
| { | ||
| /// <summary> | ||
| /// Integration coverage for the production topology: several per-scene | ||
| /// <see cref="InputModifierHandlerSystem" /> instances mutating a single shared | ||
| /// <see cref="InputModifierComponent" /> on the global player entity. | ||
| /// These are the scenarios the single-system unit tests cannot express. | ||
| /// </summary> | ||
| public class InputModifierHandlerSystemCrossSceneShould | ||
| { | ||
| private World globalWorld; | ||
| private Entity playerEntity; | ||
| private ISceneRestrictionBusController busController; | ||
|
|
||
| private World sceneWorldA; | ||
| private ISceneStateProvider sceneStateA; | ||
| private InputModifierHandlerSystem systemA; | ||
|
|
||
| private World sceneWorldB; | ||
| private ISceneStateProvider sceneStateB; | ||
| private InputModifierHandlerSystem systemB; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| globalWorld = World.Create(); | ||
| playerEntity = globalWorld.Create(new InputModifierComponent()); | ||
| busController = Substitute.For<ISceneRestrictionBusController>(); | ||
|
|
||
| sceneWorldA = World.Create(); | ||
| sceneStateA = Substitute.For<ISceneStateProvider>(); | ||
| systemA = new InputModifierHandlerSystem(sceneWorldA, globalWorld, playerEntity, sceneStateA, busController); | ||
|
|
||
| sceneWorldB = World.Create(); | ||
| sceneStateB = Substitute.For<ISceneStateProvider>(); | ||
| systemB = new InputModifierHandlerSystem(sceneWorldB, globalWorld, playerEntity, sceneStateB, busController); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| systemA.Dispose(); | ||
| systemB.Dispose(); | ||
| sceneWorldA.Dispose(); | ||
| sceneWorldB.Dispose(); | ||
| globalWorld.Dispose(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ClearGlider_WhenTeleportingFromRestrictingSceneToUnrestrictedScene() | ||
| { | ||
| // Faithful repro of the playtest bug: scene A (Shroom Zoom) disables gliding, | ||
| // player teleports to scene B (Eternal Vortex) which imposes no restriction. | ||
| sceneStateA.IsCurrent.Returns(true); | ||
| AddPlayerModifier(sceneWorldA, new PBInputModifier.Types.StandardInput { DisableGliding = true }); | ||
| systemA.Update(0); | ||
| Assert.IsTrue(globalWorld.Get<InputModifierComponent>(playerEntity).DisableGliding); | ||
|
|
||
| // Teleport A -> B | ||
| sceneStateA.IsCurrent.Returns(false); | ||
| systemA.OnSceneIsCurrentChanged(false); | ||
|
|
||
| sceneStateB.IsCurrent.Returns(true); | ||
| systemB.OnSceneIsCurrentChanged(true); | ||
| systemB.Update(0); | ||
|
|
||
| // The glider must be available again in scene B | ||
| Assert.IsFalse(globalWorld.Get<InputModifierComponent>(playerEntity).DisableGliding); | ||
| } | ||
|
|
||
| [Test] | ||
| public void NotClobberActiveSceneRestriction_WhenAnotherSceneUnloadsWithoutApplying() | ||
| { | ||
| // Scene A is current and restricts walking. Scene B is loaded in the background, | ||
| // never applied anything, and now unloads. Its teardown must leave A's restriction intact. | ||
| sceneStateA.IsCurrent.Returns(true); | ||
| AddPlayerModifier(sceneWorldA, new PBInputModifier.Types.StandardInput { DisableWalk = true }); | ||
| systemA.Update(0); | ||
| Assert.IsTrue(globalWorld.Get<InputModifierComponent>(playerEntity).DisableWalk); | ||
|
|
||
| // Scene B unloads and transitions to non-current without ever asserting a modifier | ||
| systemB.OnSceneIsCurrentChanged(false); | ||
| systemB.FinalizeComponents(default); | ||
|
|
||
| Assert.IsTrue(globalWorld.Get<InputModifierComponent>(playerEntity).DisableWalk); | ||
| } | ||
|
|
||
| [Test] | ||
| public void HandOverRestrictionCleanly_WhenTeleportingBetweenRestrictingScenes() | ||
| { | ||
| // Scene A disables gliding, scene B disables jumping. After the teleport the global | ||
| // state must reflect B only: A's gliding lifted, B's jump applied. | ||
| sceneStateA.IsCurrent.Returns(true); | ||
| AddPlayerModifier(sceneWorldA, new PBInputModifier.Types.StandardInput { DisableGliding = true }); | ||
| systemA.Update(0); | ||
|
|
||
| // Teleport A -> B | ||
| sceneStateA.IsCurrent.Returns(false); | ||
| systemA.OnSceneIsCurrentChanged(false); | ||
|
|
||
| sceneStateB.IsCurrent.Returns(true); | ||
| AddPlayerModifier(sceneWorldB, new PBInputModifier.Types.StandardInput { DisableJump = true }); | ||
| systemB.OnSceneIsCurrentChanged(true); | ||
| systemB.Update(0); | ||
|
|
||
| InputModifierComponent global = globalWorld.Get<InputModifierComponent>(playerEntity); | ||
| Assert.IsTrue(global.DisableJump); | ||
| Assert.IsFalse(global.DisableGliding); | ||
|
|
||
| // The movement-blocking indicator reflects B's jump restriction | ||
| busController.Received().PushSceneRestriction(Arg.Is<SceneRestriction>(r => r.Action == SceneRestrictionsAction.Applied)); | ||
| } | ||
|
|
||
| private static void AddPlayerModifier(World sceneWorld, PBInputModifier.Types.StandardInput standard) | ||
| { | ||
| Entity entity = sceneWorld.Create(); | ||
| sceneWorld.Add(entity, new PBInputModifier { Standard = standard, IsDirty = true }, new CRDTEntity(SpecialEntitiesID.PLAYER_ENTITY)); | ||
| } | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
.../DCL/SDKComponents/InputModifier/Tests/InputModifierHandlerSystemCrossSceneShould.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.
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.