Skip to content

Commit

Permalink
fix: sdk7 smart wearable restricted actions call from ui (#6012)
Browse files Browse the repository at this point in the history
Removed unneeded scene tick check for allowing a restricted action to be called from ui.
  • Loading branch information
pravusjif authored Dec 8, 2023
1 parent 85907e6 commit 0e600db
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,13 @@ public struct InternalEngineInfo : IInternalComponent
public uint SceneTick;
public float SceneInitialRunTime;
public int SceneInitialFrameCount;
public uint EnableRestrictedActionTick;

public InternalEngineInfo(uint sceneTick, float sceneInitialRunTime)
{
this.dirty = false;
this.SceneTick = sceneTick;
this.SceneInitialRunTime = sceneInitialRunTime;
this.SceneInitialFrameCount = Time.frameCount;
this.EnableRestrictedActionTick = 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ internal bool IsSceneRestrictedActionEnabled(int sceneNumber)
{
InternalEngineInfo engineInfo = engineInfoComponent.GetFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY)!.Value.model;
uint sceneTick = engineInfo.SceneTick;

const uint TICK_THRESHOLD = 2;

return sceneTick != 0
&& engineInfo.EnableRestrictedActionTick != 0
&& sceneTick <= (engineInfo.EnableRestrictedActionTick + TICK_THRESHOLD);
return sceneTick != 0;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void Update()
if (IsValidInputForRestrictedActions(entityId, actionButton, evtType, hit))
{
restrictedActionEnabled = true;
engineInfoModel.EnableRestrictedActionTick = engineInfoModel.SceneTick;
engineInfoComponent.PutFor(currentSceneNumber, SpecialEntityId.SCENE_ROOT_ENTITY, engineInfoModel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,107 +155,5 @@ public void StoreSceneTickInResult()
(result) => result.TickNumber == 3
);
}

[Test]
public void EnableRestrictedActionsOnValidInput()
{
const uint CURRENT_TICK = 823;

inputResultComponent.AddEvent(scene, new InternalInputEventResults.EventData()
{
button = InputAction.IaPrimary,
type = PointerEventType.PetDown,
hit = new RaycastHit()
{
EntityId = 66
}
});

internalComponents.EngineInfo.PutFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY, new InternalEngineInfo()
{
SceneTick = CURRENT_TICK,
EnableRestrictedActionTick = 0
});

updateSystems();

var engineInfo = internalComponents.EngineInfo.GetFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY)!.Value.model;
Assert.AreEqual(CURRENT_TICK, engineInfo.EnableRestrictedActionTick);
}

[Test]
public void NotEnableRestrictedActionsOnInvalidInputType()
{
inputResultComponent.AddEvent(scene, new InternalInputEventResults.EventData()
{
button = InputAction.IaPrimary,
type = PointerEventType.PetHoverEnter,
hit = new RaycastHit()
{
EntityId = 66
}
});

internalComponents.EngineInfo.PutFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY, new InternalEngineInfo()
{
SceneTick = 823,
EnableRestrictedActionTick = 0
});

updateSystems();

var engineInfo = internalComponents.EngineInfo.GetFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY)!.Value.model;
Assert.AreEqual(0, engineInfo.EnableRestrictedActionTick);
}

[Test]
public void NotEnableRestrictedActionsOnInvalidInputHit()
{
inputResultComponent.AddEvent(scene, new InternalInputEventResults.EventData()
{
button = InputAction.IaPrimary,
type = PointerEventType.PetDown,
hit = null
});

internalComponents.EngineInfo.PutFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY, new InternalEngineInfo()
{
SceneTick = 823,
EnableRestrictedActionTick = 0
});

updateSystems();

var engineInfo = internalComponents.EngineInfo.GetFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY)!.Value.model;
Assert.AreEqual(0, engineInfo.EnableRestrictedActionTick);
}

[Test]
public void NotEnableRestrictedActionsOnValidInputFromOtherScene()
{
const uint CURRENT_TICK = 823;
var sceneWherePlayerIsNotCurrentlyOn = testUtils.CreateScene(667);

inputResultComponent.AddEvent(sceneWherePlayerIsNotCurrentlyOn, new InternalInputEventResults.EventData()
{
button = InputAction.IaPrimary,
type = PointerEventType.PetDown,
hit = new RaycastHit()
{
EntityId = 66
}
});

internalComponents.EngineInfo.PutFor(sceneWherePlayerIsNotCurrentlyOn, SpecialEntityId.SCENE_ROOT_ENTITY, new InternalEngineInfo()
{
SceneTick = CURRENT_TICK,
EnableRestrictedActionTick = 0
});

updateSystems();

var engineInfo = internalComponents.EngineInfo.GetFor(sceneWherePlayerIsNotCurrentlyOn, SpecialEntityId.SCENE_ROOT_ENTITY)!.Value.model;
Assert.AreEqual(0, engineInfo.EnableRestrictedActionTick);
}
}
}

0 comments on commit 0e600db

Please sign in to comment.