Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override void Update(float t)

private void SendBusMessage(in InputModifierComponent inputModifier)
{
SceneRestrictionsAction currentAction = inputModifier is { DisableAll: false, DisableWalk: false, DisableJog: false, DisableRun: false, DisableJump: false, DisableEmote: false } ? SceneRestrictionsAction.Removed : SceneRestrictionsAction.Applied;
SceneRestrictionsAction currentAction = inputModifier.EverythingEnabled ? SceneRestrictionsAction.Removed : SceneRestrictionsAction.Applied;
Comment thread
popuz marked this conversation as resolved.

if (currentAction == lastBusMessageAction) return;

Expand Down
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,
};
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading