Skip to content

Commit

Permalink
Merge pull request #111 from decentraland/feat/use-events-library
Browse files Browse the repository at this point in the history
feat: Use Events library for Emote events
  • Loading branch information
LautaroPetaccio authored Mar 22, 2024
2 parents 4b0742b + e564dab commit 86c9c78
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"decentraland-ui": "^3.49.0",
"deep-equal": "^2.0.5",
"fp-future": "^1.0.1",
"mitt": "^3.0.1",
"prettier": "^2.4.1",
"raw-loader": "^4.0.2",
"react": "^17.0.2",
Expand Down
28 changes: 24 additions & 4 deletions src/lib/babylon/emote.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from 'events'
import mitt from 'mitt'
import {
AnimationGroup,
ArcRotateCamera,
Expand All @@ -22,7 +22,14 @@ import { startAutoRotateBehavior } from './camera'
import { Asset, loadAssetContainer, loadSound } from './scene'
import { getEmoteRepresentation } from '../representation'

const loopedEmotes = [PreviewEmote.IDLE, PreviewEmote.MONEY, PreviewEmote.CLAP, PreviewEmote.WALK, PreviewEmote.RUN, PreviewEmote.JUMP]
const loopedEmotes = [
PreviewEmote.IDLE,
PreviewEmote.MONEY,
PreviewEmote.CLAP,
PreviewEmote.WALK,
PreviewEmote.RUN,
PreviewEmote.JUMP,
]

let intervalId: number | undefined

Expand Down Expand Up @@ -64,7 +71,11 @@ export function loadEmoteSound(scene: Scene, emote: EmoteDefinition, config: Pre
return loadSound(scene, representation)
}

export async function playEmote(scene: Scene, assets: Asset[], config: PreviewConfig) {
export async function playEmote(
scene: Scene,
assets: Asset[],
config: PreviewConfig
): Promise<IEmoteController | undefined> {
// load asset container for emote
let container: AssetContainer | undefined
let loop = !!config.emote && isLooped(config.emote)
Expand Down Expand Up @@ -234,7 +245,16 @@ function createController(animationGroup: AnimationGroup, loop: boolean, sound:
Engine.audioEngine.setGlobalVolume(0)
}

const events = new EventEmitter()
// Temporary typed events.
type Events = {
[PreviewEmoteEventType.ANIMATION_PLAY]: void
[PreviewEmoteEventType.ANIMATION_PAUSE]: void
[PreviewEmoteEventType.ANIMATION_LOOP]: void
[PreviewEmoteEventType.ANIMATION_END]: void
[PreviewEmoteEventType.ANIMATION_PLAYING]: { length: number }
}

const events = mitt<Events>()

// Emit the PreviewEmoteEventType.ANIMATION_PLAYING event with the current playing frame
const emitPlayingEvent = () => {
Expand Down

0 comments on commit 86c9c78

Please sign in to comment.