Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Hummingbirds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"version": "1.0.0",
"dependencies": {
"@dcl-sdk/utils": "next",
"@dcl/sdk": "next"
"@dcl/js-runtime": "latest",
"@dcl/sdk": "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/sync-scenes/dcl-sdk-7.3.13-6053273103.commit-ef40f02.tgz"
},
"devDependencies": {},
"scripts": {
"build": "sdk-commands build --skip-install",
"deploy": "sdk-commands deploy",
Expand Down
5 changes: 4 additions & 1 deletion Hummingbirds/scene.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@
"76,-9"
]
},
"name": "Hummingbirds"
"name": "Hummingbirds",
"worldConfiguration" : {
"name": "boedo.dcl.eth"
}
}
53 changes: 47 additions & 6 deletions Hummingbirds/src/hummingBird.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
import { Animator, CameraMode, engine, Entity, GltfContainer, Schemas, Transform } from '@dcl/sdk/ecs'
import {
Animator,
ColliderLayer,
Entity,
GltfContainer,
InputAction,
MeshCollider,
PointerEventType,
PointerEvents,
SyncEntity,
Transform,
engine,
inputSystem
} from '@dcl/sdk/ecs'
import { Quaternion } from '@dcl/sdk/math'
import * as utils from '@dcl-sdk/utils'
import { NetworkEntityFactory } from '@dcl/sdk/network-transport/types'

export function createHummingBird() {
export const Bird = engine.defineComponent('bird', {})

engine.addSystem(() => {
for (const [entity] of engine.getEntitiesWith(Bird, PointerEvents)) {
if (inputSystem.isTriggered(InputAction.IA_POINTER, PointerEventType.PET_DOWN, entity)) {
engine.removeEntity(entity)
}
}
})

export function createHummingBird(engine: NetworkEntityFactory) {
const bird = engine.addEntity()
Bird.create(bird)
SyncEntity.create(bird, { componentIds: [Transform.componentId, Animator.componentId] })
Transform.create(bird, {
position: { x: 13, y: 3.5, z: 5 },
rotation: { x: 0, y: 0, z: 0, w: 1 },
scale: { x: 0.2, y: 0.2, z: 0.2 }
})

GltfContainer.create(bird, {
src: 'models/hummingbird.glb'
src: 'models/hummingbird.glb',
visibleMeshesCollisionMask: ColliderLayer.CL_POINTER,
invisibleMeshesCollisionMask: ColliderLayer.CL_POINTER
})

MeshCollider.setSphere(bird, ColliderLayer.CL_POINTER)

Animator.create(bird, {
states: [
{
Expand Down Expand Up @@ -39,9 +71,16 @@ export function createHummingBird() {
]
})

PointerEvents.create(bird, {
pointerEvents: [
{ eventType: PointerEventType.PET_DOWN, eventInfo: { button: InputAction.IA_POINTER, hoverText: 'KILL' } }
]
})

// fly pattern
utils.timers.setInterval(() => {
const birdTransform = Transform.getMutable(bird)
const birdTransform = Transform.getMutableOrNull(bird)
if (!birdTransform) return

// next target
const nextPos = {
Expand Down Expand Up @@ -75,10 +114,12 @@ export function createHummingBird() {
export function randomHeadMovement(bird: Entity) {
const anim = Math.random()
if (anim < 0.2) {
const look = Animator.getClip(bird, 'look')
const look = Animator.getClipOrNull(bird, 'look')
if (!look) return
look.playing = true
} else if (anim > 0.8) {
const shake = Animator.getClip(bird, 'shake')
const shake = Animator.getClipOrNull(bird, 'shake')
if (!shake) return
shake.playing = true
}
}
15 changes: 13 additions & 2 deletions Hummingbirds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@ import {
pointerEventsSystem,
Transform
} from '@dcl/sdk/ecs'
import { getRealm } from '~system/Runtime'
import { createNetworkTransport } from '@dcl/sdk/network-transport'

import { createHummingBird } from './hummingBird'
import { setupUi } from './ui'

export async function main() {
const realm = await getRealm({})
const serverUrl = realm.realmInfo?.isPreview ? 'ws://127.0.0.1:3000/ws' : 'wss://scene-state-server.decentraland.org/ws'
const networkEntityFactory = await createNetworkTransport(serverUrl)
setupUi()

export function main() {
const ground = engine.addEntity()

Transform.create(ground, {
position: { x: 8, y: 0, z: 8 },
rotation: { x: 0, y: 0, z: 0, w: 0 },
scale: { x: 1.6, y: 1.6, z: 1.6 }
})

GltfContainer.create(ground, {
src: 'models/Ground.gltf'
})
Expand Down Expand Up @@ -60,7 +71,7 @@ export function main() {
}
},
function () {
createHummingBird()
createHummingBird(networkEntityFactory)
const anim = Animator.getMutable(tree)
anim.states[0].playing = true
const audioSource = AudioSource.getMutable(tree)
Expand Down
49 changes: 49 additions & 0 deletions Hummingbirds/src/ui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { engine, PointerEvents } from '@dcl/sdk/ecs'
import { Color4 } from '@dcl/sdk/math'
import ReactEcs, { Label, ReactEcsRenderer, UiEntity } from '@dcl/sdk/react-ecs'
import { Bird } from './hummingBird'

export function setupUi() {
ReactEcsRenderer.setUiRenderer(() => (
<UiEntity
uiTransform={{
width: 300,
height: 130,
margin: '16px 0 8px 270px',
padding: 4
}}
uiBackground={{ color: Color4.create(0.5, 0.8, 0.1, 0.6) }}
>
<UiEntity
uiTransform={{
width: '100%',
height: '100%',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'space-between'
}}
uiBackground={{ color: Color4.fromHexString('#70ac76ff') }}
>
<UiEntity
uiTransform={{
width: '100%',
height: 50,
margin: '8px 0'
}}
uiBackground={{
textureMode: 'center',
texture: {
src: 'images/scene-thumbnail.png'
}
}}
uiText={{ value: 'HummingBirds Sync', fontSize: 18 }}
/>
<Label
value={`# Birds: ${[...engine.getEntitiesWith(Bird, PointerEvents)].length}`}
fontSize={18}
uiTransform={{ width: '100%', height: 100 }}
/>
</UiEntity>
</UiEntity>
))
}
2 changes: 1 addition & 1 deletion moving-platforms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"dependencies": {
"@dcl-sdk/utils": "next",
"@dcl/sdk": "next"
"@dcl/sdk": "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/sync-scenes/dcl-sdk-7.3.13-6050811236.commit-c2a836a.tgz"
},
"scripts": {
"build": "sdk-commands build --skip-install",
Expand Down
3 changes: 3 additions & 0 deletions moving-platforms/scene.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"title": "moving-platforms",
"favicon": "favicon_asset"
},
"worldConfiguration" : {
"name": "maximocossetti.dcl.eth"
},
"contact": {
"name": "decentraland",
"email": ""
Expand Down
Loading