Skip to content

Commit

Permalink
Merge branch 'decentraland:main' into Event-API
Browse files Browse the repository at this point in the history
  • Loading branch information
CansyLand authored Sep 25, 2023
2 parents 93ef555 + b7e687b commit bc1fefe
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 42 deletions.
22 changes: 18 additions & 4 deletions Portal-Puzzle/src/gun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
AudioSource,
AvatarAnchorPointType,
AvatarAttach,
CameraModeArea,
CameraType,
Entity,
GltfContainer,
Transform,
Expand All @@ -11,6 +13,7 @@ import { Quaternion, Vector3 } from '@dcl/sdk/math'
import * as utils from '@dcl-sdk/utils'
import { colorSystem, gunSystem } from './systems'
import { GlowColor, PortalColor } from './components'
import { OnlyInScene, onlyInSceneSystem } from './onlyRenderInScene'

export let HOLDING_GUN = false

Expand Down Expand Up @@ -46,11 +49,22 @@ export function pickUpGun(gun: Entity) {
AudioSource.createOrReplace(gun, { audioClipUrl: 'sounds/gunPickup.mp3', playing: true, loop: false })

const gunParent = engine.addEntity()
AvatarAttach.create(gunParent, { anchorPointId: AvatarAnchorPointType.AAPT_NAME_TAG })
const gunTranform = Transform.getMutable(gun)
gunTranform.parent = gunParent
gunTranform.position = Vector3.create(0.45, -0.625, 0.9)
;(gunTranform.parent = engine.CameraEntity), (gunTranform.position = Vector3.create(0.45, -0.625, 0.9))
gunTranform.rotation = Quaternion.fromEulerDegrees(0, 0, 0)

utils.triggers.removeTrigger(gun)

// render gun only in scene
OnlyInScene.create(gun)
engine.addSystem(onlyInSceneSystem)

// keep camera in 1st person while in scene
const modEntity = engine.addEntity()
Transform.create(modEntity, {
position: Vector3.create(8, 4, 8)
})
CameraModeArea.create(modEntity, {
area: Vector3.create(16, 8, 16),
mode: CameraType.CT_FIRST_PERSON
})
}
1 change: 1 addition & 0 deletions Portal-Puzzle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as utils from '@dcl-sdk/utils'
import { gunSystem, colorSystem } from './systems'

import { spawnGun } from './gun'
import { onlyInSceneSystem } from './onlyRenderInScene'

export function main() {
const card = engine.getEntityOrNullByName('card.glb')
Expand Down
38 changes: 38 additions & 0 deletions Portal-Puzzle/src/onlyRenderInScene.ts
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,38 @@ import { Quaternion, Vector3 } from '@dcl/sdk/math'
import { showUI } from './denyUI'
import { hasWornPE, isWearingPE } from './peTracking'

/**
* Handle door states
*/
export function addChest() {
/**
* Handle door states
*/

const denySound = engine.addEntity()
const openClip = engine.addEntity()
const closeClip = engine.addEntity()
const denySound = engine.addEntity()
const openClip = engine.addEntity()
const closeClip = engine.addEntity()

// Create AudioSource component
AudioSource.create(denySound, {
audioClipUrl: 'sounds/navigationBackward.mp3',
playing: false
})
// Create AudioSource component
AudioSource.create(denySound, {
audioClipUrl: 'sounds/navigationBackward.mp3',
playing: false
})

AudioSource.create(openClip, {
audioClipUrl: 'sounds/open.mp3',
playing: false
})
AudioSource.create(closeClip, {
audioClipUrl: 'sounds/close.mp3',
playing: false
})
// Define a simple function
function playSound(entity: Entity) {
// fetch mutable version of audio source component
const audioSource = AudioSource.getMutable(entity)
AudioSource.create(openClip, {
audioClipUrl: 'sounds/open.mp3',
playing: false
})
AudioSource.create(closeClip, {
audioClipUrl: 'sounds/close.mp3',
playing: false
})
// Define a simple function
function playSound(entity: Entity) {
// fetch mutable version of audio source component
const audioSource = AudioSource.getMutable(entity)

// modify its playing value
audioSource.playing = true
}
// modify its playing value
audioSource.playing = true
}

export function doorSystem(dt: number) {
const chest = engine.addEntity()
Transform.create(chest, {
position: Vector3.create(6.5, 5, 7.5),
Expand Down Expand Up @@ -85,8 +85,7 @@ export function doorSystem(dt: number) {
showUI()
playSound(denySound)
} else {
console.log('no PE accepted')
Animator.playSingleAnimation(chest, 'Close', true)
console.log('ALLOWED: no Portable Experience was detected')
Animator.playSingleAnimation(chest, 'Open', true)
playSound(openClip)
}
Expand Down
5 changes: 2 additions & 3 deletions block-portable-experiences/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { engine, InputAction, inputSystem, Material, MeshCollider, pointerEvents
import { Color4 } from '@dcl/sdk/math'

import { addPlatforms } from './platforms'
import { doorSystem } from './systems'
import { addChest } from './chest'
import { showUI } from './denyUI'
import { checkPortableExperience } from './peTracking'

engine.addSystem(doorSystem)

export function main() {
addPlatforms()
checkPortableExperience()
addChest()
}
13 changes: 10 additions & 3 deletions light-bounce-puzzle/src/onlyRenderInScene.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { Schemas, VisibilityComponent, engine } from '@dcl/sdk/ecs'
import { Schemas, Transform, VisibilityComponent, engine } from '@dcl/sdk/ecs'
import * as utils from '@dcl-sdk/utils'
import { Vector3 } from '~system/EngineApi'
import { Vector3 } from '@dcl/sdk/math'

const SCENE_SIZE_X = 1
const SCENE_SIZE_Y = 1

export const OnlyInScene = engine.defineComponent('OnlyInScene', {})
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
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions tin-can-alley/src/modules/onlyRenderInScene.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { Schemas, VisibilityComponent, engine } from '@dcl/sdk/ecs'
import { Schemas, Transform, VisibilityComponent, engine } from '@dcl/sdk/ecs'
import * as utils from '@dcl-sdk/utils'
import { Vector3 } from '~system/EngineApi'
import { Vector3 } from '@dcl/sdk/math'

const SCENE_SIZE_X = 1
const SCENE_SIZE_Y = 1

export const OnlyInScene = engine.defineComponent('OnlyInScene', {})
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
}
}
}
Expand Down

0 comments on commit bc1fefe

Please sign in to comment.