From 370c6980fcd35fdded5d105f47f942b827bc53c6 Mon Sep 17 00:00:00 2001 From: Vaios Kalpias-Ilias Date: Fri, 4 Mar 2016 19:41:27 +0200 Subject: [PATCH] [FIX] Cloning sound components --- src/framework/components/sound/system.js | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/framework/components/sound/system.js b/src/framework/components/sound/system.js index 096510d66c4..514c376f61f 100644 --- a/src/framework/components/sound/system.js +++ b/src/framework/components/sound/system.js @@ -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;