UNPKG

pixi-dragonbones-runtime

Version:
3 lines (2 loc) 2.58 kB
import"../core/BaseObject.mjs";import{DragonBones as e}from"../core/DragonBones.mjs";import{Container as t,Graphics as r}from"pixi.js";class a extends t{constructor(){super(),this.debugDraw=!1,this._debugDraw=!1,this._armature=null,this._debugDrawer=null,this._debugDrawerChildren=new Map}dbInit(e){this._armature=e}dbClear(){null!==this._debugDrawer&&(this._debugDrawerChildren.clear(),this._debugDrawer.destroy()),this._armature=null,this._debugDrawer=null,super.destroy()}dbUpdate(){const a=e.debugDraw||this.debugDraw;if(a||this._debugDraw)if(this._debugDraw=a,this._debugDraw){if(null===this._debugDrawer){this._debugDrawer=new t;const e=new r;this._debugDrawer.addChild(e)}this.addChild(this._debugDrawer);const e=this._debugDrawer.getChildAt(0);e.clear();const a=this._armature.getBones();for(let t=0,r=a.length;t<r;++t){const r=a[t],i=r.boneData.length,s=r.globalTransformMatrix.tx,h=r.globalTransformMatrix.ty,o=s+r.globalTransformMatrix.a*i,n=h+r.globalTransformMatrix.b*i;e.moveTo(s,h),e.lineTo(o,n),e.stroke({width:2,color:65535,alpha:.7}),e.circle(s,h,3),e.fill({color:65535,alpha:.7})}const i=this._armature.getSlots();for(let t=0,a=i.length;t<a;++t){const a=i[t],s=a.boundingBoxData;if(s){let t=this._debugDrawerChildren.get(a.name);switch(t||(t=new r,this._debugDrawerChildren.set(a.name,t),this._debugDrawer.addChild(t)),t.clear(),s.type){case 0:t.rect(.5*-s.width,.5*-s.height,s.width,s.height);break;case 1:t.ellipse(.5*-s.width,.5*-s.height,s.width,s.height);break;case 2:const e=s.vertices;for(let r=0,a=e.length;r<a;r+=2){const a=e[r],i=e[r+1];0===r?t.moveTo(a,i):t.lineTo(a,i)}t.lineTo(e[0],e[1])}e.stroke({width:2,color:65535,alpha:.7}),a.updateTransformAndMatrix(),a.updateGlobalTransform();const i=a.global;t.updateTransform({x:i.x,y:i.y,scaleX:i.scaleX,scaleY:i.scaleY,rotation:i.rotation,skewX:i.skew,skewY:0,pivotX:a._pivotX,pivotY:a._pivotY})}else{const e=this._debugDrawerChildren.get(a.name);e&&(this._debugDrawerChildren.delete(a.name),this._debugDrawer.removeChild(e))}}}else null!==this._debugDrawer&&this._debugDrawer.parent===this&&this.removeChild(this._debugDrawer)}dispose(e=!0){null!==this._armature&&(this._armature.dispose(),this._armature=null)}destroy(){this.dispose()}dispatchDBEvent(e,t){this.emit(e,t)}hasDBEventListener(e){return this.listenerCount(e)>0}addDBEventListener(e,t,r){this.addListener(e,t,r)}removeDBEventListener(e,t,r){this.removeListener(e,t,r)}get armature(){return this._armature}get animation(){return this._armature.animation}}export{a as PixiArmatureDisplay}; //# sourceMappingURL=PixiArmatureDisplay.mjs.map