@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.42 kB
JavaScript
import{Component as t}from"../component.js";import{ComponentSystem as n}from"../system.js";import{AnimationComponent as o}from"./component.js";import{AnimationComponentData as a}from"./data.js";const e=["enabled"];class i extends n{constructor(t){super(t),this.id="animation",this.ComponentType=o,this.DataType=a,this.schema=e,this.on("beforeremove",this.onBeforeRemove,this),this.app.systems.on("update",this.onUpdate,this)}initializeComponentData(t,n,o){o=["activate","enabled","loop","speed","assets"];for(const a of o)n.hasOwnProperty(a)&&(t[a]=n[a]);super.initializeComponentData(t,n,e)}cloneComponent(t,n){this.addComponent(n,{}),n.animation.assets=t.animation.assets.slice(),n.animation.speed=t.animation.speed,n.animation.loop=t.animation.loop,n.animation.activate=t.animation.activate,n.animation.enabled=t.animation.enabled;const o={},a=t.animation.animations;for(const t in a)a.hasOwnProperty(t)&&(o[t]=a[t]);n.animation.animations=o;const e={},i=t.animation.animationsIndex;for(const t in i)i.hasOwnProperty(t)&&(e[t]=i[t]);return n.animation.animationsIndex=e,n.animation}onBeforeRemove(t,n){n.onBeforeRemove()}onUpdate(t){const n=this.store;for(const o in n)if(n.hasOwnProperty(o)){const a=n[o];a.data.enabled&&a.entity.enabled&&a.entity.animation.update(t)}}destroy(){super.destroy(),this.app.systems.off("update",this.onUpdate,this)}}t._buildAccessors(o.prototype,e);export{i as AnimationComponentSystem};