pixi-dragonbones-runtime
Version:
DragonBones Runtime for Pixi.js
3 lines (2 loc) • 6.68 kB
JavaScript
import{Animation as t}from"../animation/Animation.mjs";import"../animation/AnimationState.mjs";import{BaseObject as s}from"../core/BaseObject.mjs";import"../core/DragonBones.mjs";import"../event/EventObject.mjs";import"../geom/Transform.mjs";class e extends s{constructor(){super(...arguments),this.stopped=!1,this._bones=[],this._slots=[],this._constraints=[],this._actions=[],this._animation=null,this._proxy=null,this._replaceTextureAtlasData=null,this._clock=null}static toString(){return"[class dragonBones.Armature]"}static _onSortSlots(t,s){return 1e3*t._zIndex+t._zOrder>1e3*s._zIndex+s._zOrder?1:-1}_onClear(){null!==this._clock&&this._clock.remove(this);for(const t of this._bones)t.returnToPool();for(const t of this._slots)t.returnToPool();for(const t of this._constraints)t.returnToPool();for(const t of this._actions)t.returnToPool();null!==this._animation&&this._animation.returnToPool(),null!==this._proxy&&this._proxy.dbClear(),null!==this._replaceTextureAtlasData&&this._replaceTextureAtlasData.returnToPool(),this.inheritAnimation=!0,this.userData=null,this._lockUpdate=!1,this._slotsDirty=!0,this._zOrderDirty=!1,this._zIndexDirty=!1,this._alphaDirty=!0,this._flipX=!1,this._flipY=!1,this._cacheFrameIndex=-1,this._alpha=1,this._globalAlpha=1,this._bones.length=0,this._slots.length=0,this._constraints.length=0,this._actions.length=0,this._armatureData=null,this._animation=null,this._proxy=null,this._display=null,this._replaceTextureAtlasData=null,this._replacedTexture=null,this._dragonBones=null,this._clock=null,this._parent=null}_sortZOrder(t,s){const e=this._armatureData.sortedSlots,i=null===t;if(this._zOrderDirty||!i){for(let n=0,a=e.length;n<a;++n){const l=i?n:t[s+n];if(l<0||l>=a)continue;const o=e[l],r=this.getSlot(o.name);null!==r&&r._setZOrder(n)}this._slotsDirty=!0,this._zOrderDirty=!i}}_addBone(t){this._bones.indexOf(t)<0&&this._bones.push(t)}_addSlot(t){this._slots.indexOf(t)<0&&this._slots.push(t)}_addConstraint(t){this._constraints.indexOf(t)<0&&this._constraints.push(t)}_bufferAction(t,s){this._actions.indexOf(t)<0&&(s?this._actions.push(t):this._actions.unshift(t))}dispose(){null!==this._armatureData&&(this._lockUpdate=!0,this._dragonBones.bufferObject(this))}init(e,i,n,a){null===this._armatureData&&(this._armatureData=e,this._animation=s.borrowObject(t),this._proxy=i,this._display=n,this._dragonBones=a,this._proxy.dbInit(this),this._animation.init(this),this._animation.animations=this._armatureData.animations)}advanceTime(t){if(this._lockUpdate)return;if(this._lockUpdate=!0,null===this._armatureData)return void console.warn("The armature has been disposed.");if(null===this._armatureData.parent)return void console.warn("The armature data has been disposed.\nPlease make sure dispose armature before call factory.clear().");const s=this._cacheFrameIndex;if(this._animation.advanceTime(t),this._slotsDirty||this._zIndexDirty){if(this._slots.sort(e._onSortSlots),this._zIndexDirty)for(let t=0,s=this._slots.length;t<s;++t)this._slots[t]._setZOrder(t);this._slotsDirty=!1,this._zIndexDirty=!1}if(this._alphaDirty){this._alphaDirty=!1,this._globalAlpha=this._alpha*(null!==this._parent?this._parent._globalAlpha:1);for(const t of this._bones)t._updateAlpha();for(const t of this._slots)t._updateAlpha()}if(this._cacheFrameIndex<0||this._cacheFrameIndex!==s){let t=0,s=0;for(t=0,s=this._bones.length;t<s;++t)this._bones[t].update(this._cacheFrameIndex);for(t=0,s=this._slots.length;t<s;++t)this._slots[t].update(this._cacheFrameIndex)}if(this._actions.length>0){for(const t of this._actions){const s=t.actionData;if(null!==s&&0===s.type)if(null!==t.slot){const e=t.slot.childArmature;null!==e&&e.animation.fadeIn(s.name)}else if(null!==t.bone){for(const e of this.getSlots())if(e.parent===t.bone){const t=e.childArmature;null!==t&&t.animation.fadeIn(s.name)}}else this._animation.fadeIn(s.name);t.returnToPool()}this._actions.length=0}if(null==this.clock)for(const s of this._slots){const e=s.childArmature;null===e||null!=e.clock||e.stopped||e.advanceTime(t)}this._lockUpdate=!1,this._proxy.dbUpdate()}invalidUpdate(t=null,s=!1){if(null!==t&&t.length>0){const e=this.getBone(t);if(null!==e&&(e.invalidUpdate(),s))for(const t of this._slots)t.parent===e&&t.invalidUpdate()}else{for(const t of this._bones)t.invalidUpdate();if(s)for(const t of this._slots)t.invalidUpdate()}}containsPoint(t,s){for(const e of this._slots)if(e.containsPoint(t,s))return e;return null}intersectsSegment(t,s,e,i,n=null,a=null,l=null){const o=t===e;let r=0,h=0,_=0,u=0,c=0,p=0,f=0,d=0,m=null,x=null;for(const g of this._slots){if(g.intersectsSegment(t,s,e,i,n,a,l)>0){if(null===n&&null===a){m=g;break}if(null!==n){let e=o?n.y-s:n.x-t;e<0&&(e=-e),(null===m||e<r)&&(r=e,_=n.x,u=n.y,m=g,l&&(f=l.x))}if(null!==a){let s=a.x-t;s<0&&(s=-s),(null===x||s>h)&&(h=s,c=a.x,p=a.y,x=g,null!==l&&(d=l.y))}}}return null!==m&&null!==n&&(n.x=_,n.y=u,null!==l&&(l.x=f)),null!==x&&null!==a&&(a.x=c,a.y=p,null!==l&&(l.y=d)),m}getBone(t){for(const s of this._bones)if(s.name===t)return s;return null}getBoneByDisplay(t){const s=this.getSlotByDisplay(t);return null!==s?s.parent:null}getSlot(t){for(const s of this._slots)if(s.name===t)return s;return null}getSlotByDisplay(t){if(null!==t)for(const s of this._slots)if(s.display===t)return s;return null}getBones(){return this._bones}getSlots(){return this._slots}get flipX(){return this._flipX}set flipX(t){this._flipX!==t&&(this._flipX=t,this.invalidUpdate())}get flipY(){return this._flipY}set flipY(t){this._flipY!==t&&(this._flipY=t,this.invalidUpdate())}get cacheFrameRate(){return this._armatureData.cacheFrameRate}set cacheFrameRate(t){if(this._armatureData.cacheFrameRate!==t){this._armatureData.cacheFrames(t);for(const s of this._slots){const e=s.childArmature;null!==e&&(e.cacheFrameRate=t)}}}get name(){return this._armatureData.name}get armatureData(){return this._armatureData}get animation(){return this._animation}get proxy(){return this._proxy}get eventDispatcher(){return this._proxy}get display(){return this._display}get replacedTexture(){return this._replacedTexture}set replacedTexture(t){if(this._replacedTexture!==t){null!==this._replaceTextureAtlasData&&(this._replaceTextureAtlasData.returnToPool(),this._replaceTextureAtlasData=null),this._replacedTexture=t;for(const t of this._slots)t.invalidUpdate(),t.update(-1)}}get clock(){return this._clock}set clock(t){if(this._clock!==t){null!==this._clock&&this._clock.remove(this),this._clock=t,this._clock&&this._clock.add(this);for(const t of this._slots){const s=t.childArmature;null!==s&&(s.clock=this._clock)}}}get parent(){return this._parent}getDisplay(){return this._display}}export{e as Armature};
//# sourceMappingURL=Armature.mjs.map