Skip to content

Commit

Permalink
[FIX] Cloning sound components
Browse files Browse the repository at this point in the history
  • Loading branch information
vkalpias committed Mar 4, 2016
1 parent ca82ab1 commit 370c698
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/framework/components/sound/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,47 @@ pc.extend(pc, function () {
SoundComponentSystem._super.initializeComponentData.call(this, component, data, properties);
},

cloneComponent: function (entity, clone) {
var oldData = entity.sound.data;
var newData = {};

// copy old data to new data
for (var key in oldData) {
if (oldData.hasOwnProperty(key)) {
newData[key] = oldData[key];
}
}

// convert 'slots' back to
// simple option objects
newData.slots = {};

for (var key in oldData.slots) {
var oldSlot = oldData.slots[key];
if (oldSlot instanceof pc.SoundSlot) {
newData.slots[key] = {
name: oldSlot.name,
volume: oldSlot.volume,
pitch: oldSlot.pitch,
loop: oldSlot.loop,
duration: oldSlot.duration,
startTime: oldSlot.startTime,
overlap: oldSlot.overlap,
autoPlay: oldSlot.autoPlay,
asset: oldSlot.asset
};
} else {
newData.slots[key] = oldSlot;
}
}

// reset playingBeforeDisable
newData.playingBeforeDisable = {};

// add component with new data
return this.addComponent(clone, newData);
},

onUpdate: function(dt) {
var store = this.store;

Expand Down

0 comments on commit 370c698

Please sign in to comment.