forked from decentraland/sdk7-goerli-plaza
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'decentraland:main' into Event-API
- Loading branch information
Showing
7 changed files
with
107 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
import { Schemas, Transform, VisibilityComponent, engine } from '@dcl/sdk/ecs' | ||
import * as utils from '@dcl-sdk/utils' | ||
import { Vector3 } from '@dcl/sdk/math' | ||
|
||
const SCENE_SIZE_X = 1 | ||
const SCENE_SIZE_Y = 1 | ||
|
||
export const OnlyInScene = engine.defineComponent( | ||
'OnlyInScene', | ||
{ scale: Schemas.Vector3 }, | ||
{ scale: { x: 1, y: 1, z: 1 } } | ||
) | ||
|
||
// check if entities are inside the scene parcels, even if attached to player | ||
export function onlyInSceneSystem(dt: number) { | ||
for (const [entity, _onlyInScene] of engine.getEntitiesWith(OnlyInScene)) { | ||
const finalPos = utils.getWorldPosition(entity) | ||
const MutableTransform = Transform.getMutable(entity) | ||
if (!isInScene(finalPos)) { | ||
if (!VisibilityComponent.has(entity)) { | ||
VisibilityComponent.createOrReplace(entity, { visible: false }) | ||
MutableTransform.scale = Vector3.Zero() | ||
} | ||
} else if (VisibilityComponent.has(entity)) { | ||
VisibilityComponent.deleteFrom(entity) | ||
MutableTransform.scale = _onlyInScene.scale | ||
} | ||
} | ||
} | ||
|
||
// check if any position is inside the scene parcels | ||
export function isInScene(position: Vector3) { | ||
if (position.x < 0 || position.x >= SCENE_SIZE_X * 16 || position.z < 0 || position.z >= SCENE_SIZE_Y * 16) { | ||
return false | ||
} else { | ||
return true | ||
} | ||
} |
This file contains 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 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 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 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