Skip to content

Commit 86c9c78

Browse files
Merge pull request #111 from decentraland/feat/use-events-library
feat: Use Events library for Emote events
2 parents 4b0742b + e564dab commit 86c9c78

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"decentraland-ui": "^3.49.0",
2323
"deep-equal": "^2.0.5",
2424
"fp-future": "^1.0.1",
25+
"mitt": "^3.0.1",
2526
"prettier": "^2.4.1",
2627
"raw-loader": "^4.0.2",
2728
"react": "^17.0.2",

src/lib/babylon/emote.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventEmitter } from 'events'
1+
import mitt from 'mitt'
22
import {
33
AnimationGroup,
44
ArcRotateCamera,
@@ -22,7 +22,14 @@ import { startAutoRotateBehavior } from './camera'
2222
import { Asset, loadAssetContainer, loadSound } from './scene'
2323
import { getEmoteRepresentation } from '../representation'
2424

25-
const loopedEmotes = [PreviewEmote.IDLE, PreviewEmote.MONEY, PreviewEmote.CLAP, PreviewEmote.WALK, PreviewEmote.RUN, PreviewEmote.JUMP]
25+
const loopedEmotes = [
26+
PreviewEmote.IDLE,
27+
PreviewEmote.MONEY,
28+
PreviewEmote.CLAP,
29+
PreviewEmote.WALK,
30+
PreviewEmote.RUN,
31+
PreviewEmote.JUMP,
32+
]
2633

2734
let intervalId: number | undefined
2835

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

67-
export async function playEmote(scene: Scene, assets: Asset[], config: PreviewConfig) {
74+
export async function playEmote(
75+
scene: Scene,
76+
assets: Asset[],
77+
config: PreviewConfig
78+
): Promise<IEmoteController | undefined> {
6879
// load asset container for emote
6980
let container: AssetContainer | undefined
7081
let loop = !!config.emote && isLooped(config.emote)
@@ -234,7 +245,16 @@ function createController(animationGroup: AnimationGroup, loop: boolean, sound:
234245
Engine.audioEngine.setGlobalVolume(0)
235246
}
236247

237-
const events = new EventEmitter()
248+
// Temporary typed events.
249+
type Events = {
250+
[PreviewEmoteEventType.ANIMATION_PLAY]: void
251+
[PreviewEmoteEventType.ANIMATION_PAUSE]: void
252+
[PreviewEmoteEventType.ANIMATION_LOOP]: void
253+
[PreviewEmoteEventType.ANIMATION_END]: void
254+
[PreviewEmoteEventType.ANIMATION_PLAYING]: { length: number }
255+
}
256+
257+
const events = mitt<Events>()
238258

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

0 commit comments

Comments
 (0)