@awayjs/scene 0.13.252 → 0.13.254

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- console.debug('AwayJS - Scene - 0.13.252');
1
+ console.debug('AwayJS - Scene - 0.13.254');
2
2
  export { Timeline } from './lib/base/Timeline';
3
3
  export { ControllerBase } from './lib/controllers/ControllerBase';
4
4
  export { FirstPersonController } from './lib/controllers/FirstPersonController';
@@ -336,16 +336,16 @@ var Timeline = /** @class */ (function () {
336
336
  for (var i = start_index; i < end_index; i++) {
337
337
  var audioProps = this.audioPool[this.add_sounds_stream[i]];
338
338
  if (audioProps) {
339
+ var sound = audioProps.sound;
340
+ if (!sound) {
341
+ console.warn('[Timeline] Missing sound in audioProps!', audioProps);
342
+ return;
343
+ }
339
344
  if (audioProps.cmd == 15) { // start sound
340
- var child = audioProps.sound;
341
- if (!child) {
342
- console.warn('[Timeline] Missed sound to start!', audioProps);
343
- return;
344
- }
345
- target_mc.startSound(audioProps.id, child, audioProps.props.loopCount || 0);
345
+ target_mc.startSound(sound, audioProps.props.loopCount || 0);
346
346
  }
347
347
  else if (audioProps.cmd == 16) { // stop sound
348
- target_mc.stopSound(audioProps.id);
348
+ target_mc.stopSound(sound);
349
349
  }
350
350
  //console.log("start sound:", child);
351
351
  }
@@ -1,4 +1,4 @@
1
- import { WaveAudio } from '@awayjs/core';
1
+ import { WaveAudio, EventBase } from '@awayjs/core';
2
2
  import { Timeline } from '../base/Timeline';
3
3
  import { DisplayObject } from './DisplayObject';
4
4
  import { Sprite } from './Sprite';
@@ -19,7 +19,6 @@ export declare class MovieClip extends Sprite {
19
19
  static avm1LoadedActions: any[];
20
20
  static movieClipSoundsManagerClass: any;
21
21
  private static _movieClips;
22
- private static _activeSounds;
23
22
  private static _activeSoundsOwners;
24
23
  static stopAllSounds(): void;
25
24
  static assetType: string;
@@ -45,8 +44,8 @@ export declare class MovieClip extends Sprite {
45
44
  private _isInit;
46
45
  _sessionID_childs: NumberMap<DisplayObject>;
47
46
  private _sounds;
47
+ private _activeSounds;
48
48
  _useHandCursor: boolean;
49
- private _parentSoundVolume;
50
49
  private _soundVolume;
51
50
  private _skipFramesForStream;
52
51
  private _soundStreams;
@@ -74,8 +73,8 @@ export declare class MovieClip extends Sprite {
74
73
  * Used for UIComponents, where timeline store more that 1 frame
75
74
  */
76
75
  transformToSprite(): void;
77
- startSound(id: any, sound: WaveAudio, loopsToPlay: number, onComplete?: () => void): void;
78
- stopSounds(soundID?: any): void;
76
+ startSound(sound: WaveAudio, loopsToPlay: number, onSoundComplete?: (event: EventBase) => void): void;
77
+ stopSounds(sound?: WaveAudio): void;
79
78
  /**
80
79
  * Compute scene index by global frame index
81
80
  * @param frameIndex
@@ -91,8 +90,7 @@ export declare class MovieClip extends Sprite {
91
90
  get isPlaying(): boolean;
92
91
  get soundVolume(): number;
93
92
  set soundVolume(value: number);
94
- stopSound(id: number): void;
95
- stopAllSounds(): void;
93
+ stopSound(sound: WaveAudio): void;
96
94
  buttonReset(): void;
97
95
  getMouseCursor(): string;
98
96
  queueFrameScripts(timeline: Timeline, frame_idx: number, scriptPass1: boolean): void;
@@ -149,6 +147,7 @@ export declare class MovieClip extends Sprite {
149
147
  logHierarchy(depth?: number): void;
150
148
  printHierarchyName(depth: number, target: DisplayObject): void;
151
149
  clear(): void;
150
+ private onSoundCompleteInternal;
152
151
  }
153
152
  export {};
154
153
  //# sourceMappingURL=MovieClip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MovieClip.d.ts","sourceRoot":"","sources":["../../../lib/display/MovieClip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAGxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,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} from '../managers/FrameScriptManager';
5
5
  import { Sprite } from './Sprite';
6
+ import { BaseAudioChannel } from '@awayjs/core/dist/lib/managers/BaseAudioChannel';
6
7
  var MovieClip = /** @class */ (function (_super) {
7
8
  __extends(MovieClip, _super);
8
9
  function MovieClip(timeline, spriteMode) {
@@ -24,6 +25,7 @@ var MovieClip = /** @class */ (function (_super) {
24
25
  _this._isInit = true;
25
26
  _this._sessionID_childs = {};
26
27
  _this._sounds = {};
28
+ _this._activeSounds = {};
27
29
  _this._skipFramesForStream = 0;
28
30
  /**
29
31
  * Mark that operation provided by timeline except a script, some operation not allowed from script
@@ -46,7 +48,6 @@ var MovieClip = /** @class */ (function (_super) {
46
48
  */
47
49
  _this.constructedKeyFrameIndex = -1;
48
50
  _this._soundVolume = 1;
49
- _this._parentSoundVolume = 1;
50
51
  _this._isButton = false;
51
52
  _this._buttonMode = false;
52
53
  _this._useHandCursor = true;
@@ -78,10 +79,11 @@ var MovieClip = /** @class */ (function (_super) {
78
79
  if (spriteMode) {
79
80
  _this.transformToSprite();
80
81
  }
82
+ _this.onSoundCompleteInternal = _this.onSoundCompleteInternal.bind(_this);
81
83
  return _this;
82
84
  }
83
85
  MovieClip.stopAllSounds = function () {
84
- MovieClip._activeSoundsOwners.forEach(function (e) { return e && e.stopAllSounds(); });
86
+ MovieClip._activeSoundsOwners.forEach(function (e) { return e && e.stopSounds(); });
85
87
  MovieClip._activeSoundsOwners.clear();
86
88
  };
87
89
  MovieClip.getNewMovieClip = function (timeline) {
@@ -154,46 +156,29 @@ var MovieClip = /** @class */ (function (_super) {
154
156
  timeline.keyframe_firstframes = [timeline.keyframe_firstframes[0]];
155
157
  timeline.keyframe_indices = [timeline.keyframe_indices[0]];
156
158
  };
157
- MovieClip.prototype.startSound = function (id, sound, loopsToPlay, onComplete) {
159
+ MovieClip.prototype.startSound = function (sound, loopsToPlay, onSoundComplete) {
158
160
  var channel = sound.play(0, loopsToPlay);
159
- channel.onSoundComplete = onComplete;
160
- this._sounds[id] = sound;
161
- if (!MovieClip._activeSounds[id]) {
162
- MovieClip._activeSounds[id] = [];
161
+ channel.volume = this._soundVolume;
162
+ if (onSoundComplete)
163
+ channel.addEventListener(BaseAudioChannel.COMPLETE, onSoundComplete);
164
+ //internal listener to clear
165
+ channel.addEventListener(BaseAudioChannel.COMPLETE, this.onSoundCompleteInternal);
166
+ this._sounds[sound.id] = sound;
167
+ if (!this._activeSounds[sound.id]) {
168
+ this._activeSounds[sound.id] = [];
163
169
  }
164
170
  // store channels, stop it instead of sounds
165
- MovieClip._activeSounds[id].push(channel);
171
+ this._activeSounds[sound.id].push(channel);
166
172
  MovieClip._activeSoundsOwners.add(this);
167
173
  };
168
- MovieClip.prototype.stopSounds = function (soundID) {
169
- if (soundID === void 0) { soundID = null; }
170
- if (soundID) {
171
- if (this._sounds[soundID]) {
172
- this._sounds[soundID].stop();
173
- delete this._sounds[soundID];
174
- var channels = MovieClip._activeSounds[soundID];
175
- if (channels) {
176
- for (var _i = 0, channels_1 = channels; _i < channels_1.length; _i++) {
177
- var c = channels_1[_i];
178
- c.stop();
179
- }
180
- }
181
- delete MovieClip._activeSounds[soundID];
182
- }
174
+ MovieClip.prototype.stopSounds = function (sound) {
175
+ if (sound === void 0) { sound = null; }
176
+ if (sound) {
177
+ this.stopSound(sound);
183
178
  }
184
179
  else {
185
- for (var key in this._sounds) {
186
- this._sounds[key].stop();
187
- var channels = MovieClip._activeSounds[soundID];
188
- if (channels) {
189
- for (var _a = 0, channels_2 = channels; _a < channels_2.length; _a++) {
190
- var c = channels_2[_a];
191
- c.stop();
192
- }
193
- }
194
- delete MovieClip._activeSounds[key];
195
- }
196
- this._sounds = {};
180
+ for (var key in this._sounds)
181
+ this.stopSound(this._sounds[key]);
197
182
  }
198
183
  if (Object.getOwnPropertyNames(this._sounds).length === 0) {
199
184
  MovieClip._activeSoundsOwners.delete(this);
@@ -203,13 +188,11 @@ var MovieClip = /** @class */ (function (_super) {
203
188
  for (var i = 0; i < len; ++i) {
204
189
  child = this._children[i];
205
190
  if (child.isAsset(MovieClip))
206
- child.stopSounds(soundID);
191
+ child.stopSounds(sound);
207
192
  }
208
193
  this.stopCurrentStream(this._currentFrameIndex);
209
- MovieClip._activeSounds = {};
210
- if (this._soundStreams) {
194
+ if (this._soundStreams)
211
195
  this._soundStreams.syncSounds(0, false, this.parent);
212
- }
213
196
  };
214
197
  /**
215
198
  * Compute scene index by global frame index
@@ -295,8 +278,13 @@ var MovieClip = /** @class */ (function (_super) {
295
278
  return;
296
279
  }
297
280
  this._soundVolume = value;
298
- for (var key in this._sounds) {
299
- this._sounds[key].volume = value;
281
+ for (var key in this._activeSounds) {
282
+ var channels = this._activeSounds[key];
283
+ if (channels)
284
+ for (var _i = 0, channels_1 = channels; _i < channels_1.length; _i++) {
285
+ var c = channels_1[_i];
286
+ c.volume = value;
287
+ }
300
288
  }
301
289
  var len = this._children.length;
302
290
  var child;
@@ -309,26 +297,21 @@ var MovieClip = /** @class */ (function (_super) {
309
297
  enumerable: true,
310
298
  configurable: true
311
299
  });
312
- MovieClip.prototype.stopSound = function (id) {
313
- if (this._sounds[id]) {
314
- this._sounds[id].stop();
315
- delete this._sounds[id];
316
- }
317
- if (Object.getOwnPropertyNames(this._sounds).length === 0) {
318
- MovieClip._activeSoundsOwners.delete(this);
319
- }
320
- if (MovieClip._activeSounds[id]) {
321
- for (var i = 0; i < MovieClip._activeSounds[id].length; i++) {
322
- MovieClip._activeSounds[id][i].stop();
300
+ MovieClip.prototype.stopSound = function (sound) {
301
+ if (this._sounds[sound.id]) {
302
+ this._sounds[sound.id].stop();
303
+ delete this._sounds[sound.id];
304
+ if (Object.getOwnPropertyNames(this._sounds).length === 0) {
305
+ MovieClip._activeSoundsOwners.delete(this);
306
+ }
307
+ var channels = this._activeSounds[sound.id];
308
+ if (channels) {
309
+ for (var _i = 0, channels_2 = channels; _i < channels_2.length; _i++) {
310
+ var c = channels_2[_i];
311
+ c.stop();
312
+ }
313
+ delete this._activeSounds[sound.id];
323
314
  }
324
- delete MovieClip._activeSounds[id];
325
- }
326
- };
327
- MovieClip.prototype.stopAllSounds = function () {
328
- var keys = Object.keys(this._sounds);
329
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
330
- var k = keys_1[_i];
331
- this.stopSounds(k);
332
315
  }
333
316
  };
334
317
  MovieClip.prototype.buttonReset = function () {
@@ -734,13 +717,25 @@ var MovieClip = /** @class */ (function (_super) {
734
717
  */
735
718
  _super.prototype.clear.call(this);
736
719
  };
720
+ MovieClip.prototype.onSoundCompleteInternal = function (event) {
721
+ var channel = event.target;
722
+ var sound = channel.owner;
723
+ var channels = this._activeSounds[sound.id];
724
+ var index = channels.indexOf(channel);
725
+ if (index != -1) {
726
+ channels.splice(index, 1);
727
+ }
728
+ if (channels.length === 0)
729
+ delete this._sounds[sound.id];
730
+ if (Object.getOwnPropertyNames(this._sounds).length === 0)
731
+ MovieClip._activeSoundsOwners.delete(this);
732
+ };
737
733
  //todo: this 3 are no longer used (?)
738
734
  MovieClip.avm1ScriptQueue = [];
739
735
  MovieClip.avm1ScriptQueueScripts = [];
740
736
  MovieClip.avm1LoadedActions = [];
741
737
  MovieClip.movieClipSoundsManagerClass = null;
742
738
  MovieClip._movieClips = new Array();
743
- MovieClip._activeSounds = {};
744
739
  MovieClip._activeSoundsOwners = new Set();
745
740
  MovieClip.assetType = '[asset MovieClip]';
746
741
  return MovieClip;
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- console.debug('AwayJS - Scene - 0.13.252');
1
+ console.debug('AwayJS - Scene - 0.13.254');
2
2
 
3
3
  export { IDisplayObjectAdapter } from './lib/adapters/IDisplayObjectAdapter';
4
4
  export { IMovieClipAdapter } from './lib/adapters/IMovieClipAdapter';
@@ -481,17 +481,17 @@ export class Timeline {
481
481
  for (let i: number = start_index; i < end_index; i++) {
482
482
  const audioProps: any = this.audioPool[this.add_sounds_stream[i]];
483
483
  if (audioProps) {
484
- if (audioProps.cmd == 15) {// start sound
485
- const child: WaveAudio = audioProps.sound;
484
+ const sound: WaveAudio = audioProps.sound;
486
485
 
487
- if (!child) {
488
- console.warn('[Timeline] Missed sound to start!', audioProps);
489
- return;
490
- }
486
+ if (!sound) {
487
+ console.warn('[Timeline] Missing sound in audioProps!', audioProps);
488
+ return;
489
+ }
491
490
 
492
- target_mc.startSound(audioProps.id, child, audioProps.props.loopCount || 0);
491
+ if (audioProps.cmd == 15) {// start sound
492
+ target_mc.startSound(sound, audioProps.props.loopCount || 0);
493
493
  } else if (audioProps.cmd == 16) {// stop sound
494
- target_mc.stopSound(audioProps.id);
494
+ target_mc.stopSound(sound);
495
495
  }
496
496
  //console.log("start sound:", child);
497
497
  }
@@ -1,4 +1,4 @@
1
- import { WaveAudio, IAudioChannel } from '@awayjs/core';
1
+ import { WaveAudio, IAudioChannel, EventBase } from '@awayjs/core';
2
2
  import { PartitionBase, EntityNode } from '@awayjs/view';
3
3
  import { IMovieClipAdapter } from '../adapters/IMovieClipAdapter';
4
4
  import { Timeline } from '../base/Timeline';
@@ -8,6 +8,7 @@ import { DisplayObject } from './DisplayObject';
8
8
  import { Sprite } from './Sprite';
9
9
  import { DisplayObjectContainer } from './DisplayObjectContainer';
10
10
  import { MouseButtons } from '../base/MouseButtons';
11
+ import { BaseAudioChannel } from '@awayjs/core/dist/lib/managers/BaseAudioChannel';
11
12
  interface IScene {
12
13
  offset: number;
13
14
  name: string;
@@ -29,11 +30,10 @@ export class MovieClip extends Sprite {
29
30
  public static movieClipSoundsManagerClass = null;
30
31
 
31
32
  private static _movieClips: Array<MovieClip> = new Array<MovieClip>();
32
- private static _activeSounds: Record<number, IAudioChannel[]> = {};
33
33
  private static _activeSoundsOwners: Set<MovieClip> = new Set<MovieClip>();
34
34
 
35
35
  public static stopAllSounds() {
36
- MovieClip._activeSoundsOwners.forEach(e => e && e.stopAllSounds());
36
+ MovieClip._activeSoundsOwners.forEach(e => e && e.stopSounds());
37
37
  MovieClip._activeSoundsOwners.clear();
38
38
  }
39
39
 
@@ -86,12 +86,11 @@ export class MovieClip extends Sprite {
86
86
 
87
87
  public _sessionID_childs: NumberMap<DisplayObject> = {};
88
88
 
89
- private _sounds: Object = {};
89
+ private _sounds: Record<number, WaveAudio> = {};
90
+ private _activeSounds: Record<number, IAudioChannel[]> = {};
90
91
 
91
92
  public _useHandCursor: boolean;
92
93
 
93
- private _parentSoundVolume: number;
94
-
95
94
  private _soundVolume: number;
96
95
 
97
96
  private _skipFramesForStream: number = 0;
@@ -156,7 +155,6 @@ export class MovieClip extends Sprite {
156
155
  super();
157
156
 
158
157
  this._soundVolume = 1;
159
- this._parentSoundVolume = 1;
160
158
  this._isButton = false;
161
159
  this._buttonMode = false;
162
160
  this._useHandCursor = true;
@@ -196,6 +194,8 @@ export class MovieClip extends Sprite {
196
194
  if (spriteMode) {
197
195
  this.transformToSprite();
198
196
  }
197
+
198
+ this.onSoundCompleteInternal = this.onSoundCompleteInternal.bind(this);
199
199
  }
200
200
 
201
201
  /**
@@ -225,52 +225,38 @@ export class MovieClip extends Sprite {
225
225
  }
226
226
 
227
227
  public startSound(
228
- id: any,
229
228
  sound: WaveAudio,
230
229
  loopsToPlay: number,
231
- onComplete?: () => void
230
+ onSoundComplete?: (event: EventBase) => void
232
231
  ) {
233
232
 
234
233
  const channel: IAudioChannel = sound.play(0, loopsToPlay);
235
234
 
236
- channel.onSoundComplete = onComplete;
235
+ channel.volume = this._soundVolume;
236
+
237
+ if (onSoundComplete)
238
+ channel.addEventListener(BaseAudioChannel.COMPLETE, onSoundComplete);
239
+
240
+ //internal listener to clear
241
+ channel.addEventListener(BaseAudioChannel.COMPLETE, this.onSoundCompleteInternal);
237
242
 
238
- this._sounds[id] = sound;
243
+ this._sounds[sound.id] = sound;
239
244
 
240
- if (!MovieClip._activeSounds[id]) {
241
- MovieClip._activeSounds[id] = [];
245
+ if (!this._activeSounds[sound.id]) {
246
+ this._activeSounds[sound.id] = [];
242
247
  }
243
248
 
244
249
  // store channels, stop it instead of sounds
245
- MovieClip._activeSounds[id].push(channel);
250
+ this._activeSounds[sound.id].push(channel);
246
251
  MovieClip._activeSoundsOwners.add(this);
247
252
  }
248
253
 
249
- public stopSounds(soundID: any = null) {
250
- if (soundID) {
251
- if (this._sounds[soundID]) {
252
- this._sounds[soundID].stop();
253
- delete this._sounds[soundID];
254
-
255
- const channels = MovieClip._activeSounds[soundID];
256
- if (channels) {
257
- for (const c of channels) c.stop();
258
- }
259
-
260
- delete MovieClip._activeSounds[soundID];
261
- }
254
+ public stopSounds(sound: WaveAudio = null) {
255
+ if (sound) {
256
+ this.stopSound(sound);
262
257
  } else {
263
- for (const key in this._sounds) {
264
- this._sounds[key].stop();
265
-
266
- const channels = MovieClip._activeSounds[soundID];
267
- if (channels) {
268
- for (const c of channels) c.stop();
269
- }
270
-
271
- delete MovieClip._activeSounds[key];
272
- }
273
- this._sounds = {};
258
+ for (const key in this._sounds)
259
+ this.stopSound(this._sounds[key]);
274
260
  }
275
261
 
276
262
  if (Object.getOwnPropertyNames(this._sounds).length === 0) {
@@ -282,15 +268,13 @@ export class MovieClip extends Sprite {
282
268
  for (let i: number = 0; i < len; ++i) {
283
269
  child = this._children[i];
284
270
  if (child.isAsset(MovieClip))
285
- (<MovieClip>child).stopSounds(soundID);
271
+ (<MovieClip>child).stopSounds(sound);
286
272
  }
287
273
 
288
274
  this.stopCurrentStream(this._currentFrameIndex);
289
- MovieClip._activeSounds = {};
290
275
 
291
- if (this._soundStreams) {
276
+ if (this._soundStreams)
292
277
  this._soundStreams.syncSounds(0, false, this.parent);
293
- }
294
278
  }
295
279
 
296
280
  /**
@@ -379,8 +363,10 @@ export class MovieClip extends Sprite {
379
363
  }
380
364
 
381
365
  this._soundVolume = value;
382
- for (const key in this._sounds) {
383
- this._sounds[key].volume = value;
366
+ for (const key in this._activeSounds) {
367
+ const channels = this._activeSounds[key];
368
+ if (channels)
369
+ for (const c of channels) c.volume = value;
384
370
  }
385
371
 
386
372
  const len: number = this._children.length;
@@ -392,28 +378,21 @@ export class MovieClip extends Sprite {
392
378
  }
393
379
  }
394
380
 
395
- public stopSound(id: number) {
396
- if (this._sounds[id]) {
397
- this._sounds[id].stop();
398
- delete this._sounds[id];
399
- }
400
-
401
- if (Object.getOwnPropertyNames(this._sounds).length === 0) {
402
- MovieClip._activeSoundsOwners.delete(this);
403
- }
381
+ public stopSound(sound: WaveAudio) {
382
+ if (this._sounds[sound.id]) {
383
+ this._sounds[sound.id].stop();
384
+ delete this._sounds[sound.id];
404
385
 
405
- if (MovieClip._activeSounds[id]) {
406
- for (let i: number = 0; i < MovieClip._activeSounds[id].length; i++) {
407
- MovieClip._activeSounds[id][i].stop();
386
+ if (Object.getOwnPropertyNames(this._sounds).length === 0) {
387
+ MovieClip._activeSoundsOwners.delete(this);
408
388
  }
409
- delete MovieClip._activeSounds[id];
410
- }
411
- }
412
389
 
413
- public stopAllSounds() {
414
- const keys = Object.keys(this._sounds);
415
- for (const k of keys) {
416
- this.stopSounds(k);
390
+ const channels = this._activeSounds[sound.id];
391
+ if (channels) {
392
+ for (const c of channels) c.stop();
393
+
394
+ delete this._activeSounds[sound.id];
395
+ }
417
396
  }
418
397
  }
419
398
 
@@ -887,6 +866,23 @@ export class MovieClip extends Sprite {
887
866
 
888
867
  super.clear();
889
868
  }
869
+
870
+ private onSoundCompleteInternal(event: EventBase): void {
871
+ const channel: IAudioChannel = event.target;
872
+ const sound = channel.owner;
873
+ const channels = this._activeSounds[sound.id];
874
+ const index = channels.indexOf(channel);
875
+
876
+ if (index != -1) {
877
+ channels.splice(index, 1);
878
+ }
879
+
880
+ if (channels.length === 0)
881
+ delete this._sounds[sound.id];
882
+
883
+ if (Object.getOwnPropertyNames(this._sounds).length === 0)
884
+ MovieClip._activeSoundsOwners.delete(this);
885
+ }
890
886
  }
891
887
 
892
888
  PartitionBase.registerAbstraction(EntityNode, MovieClip);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.252",
3
+ "version": "0.13.254",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",