1
- import { EventEmitter } from 'events '
1
+ import mitt from 'mitt '
2
2
import {
3
3
AnimationGroup ,
4
4
ArcRotateCamera ,
@@ -22,7 +22,14 @@ import { startAutoRotateBehavior } from './camera'
22
22
import { Asset , loadAssetContainer , loadSound } from './scene'
23
23
import { getEmoteRepresentation } from '../representation'
24
24
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
+ ]
26
33
27
34
let intervalId : number | undefined
28
35
@@ -64,7 +71,11 @@ export function loadEmoteSound(scene: Scene, emote: EmoteDefinition, config: Pre
64
71
return loadSound ( scene , representation )
65
72
}
66
73
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 > {
68
79
// load asset container for emote
69
80
let container : AssetContainer | undefined
70
81
let loop = ! ! config . emote && isLooped ( config . emote )
@@ -234,7 +245,16 @@ function createController(animationGroup: AnimationGroup, loop: boolean, sound:
234
245
Engine . audioEngine . setGlobalVolume ( 0 )
235
246
}
236
247
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 > ( )
238
258
239
259
// Emit the PreviewEmoteEventType.ANIMATION_PLAYING event with the current playing frame
240
260
const emitPlayingEvent = ( ) => {
0 commit comments