@eva/plugin-renderer-sprite-animation 1.2.1-type.2 → 1.2.2-mini.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.renderer.spriteAnimation.js +6 -7
- package/dist/EVA.plugin.renderer.spriteAnimation.min.js +1 -1
- package/dist/miniprogram.js +347 -0
- package/dist/plugin-renderer-sprite-animation.cjs.js +0 -3
- package/dist/plugin-renderer-sprite-animation.cjs.prod.js +1 -1
- package/dist/plugin-renderer-sprite-animation.d.ts +0 -1
- package/dist/plugin-renderer-sprite-animation.esm.js +1 -4
- package/package.json +4 -4
- package/dist/global.d.ts +0 -6
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
window.EVA = window.EVA || {};
|
|
4
|
+
window.EVA.plugin = window.EVA.plugin || {};
|
|
5
|
+
window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
10
|
var _extendStatics = function extendStatics(d, b) {
|
|
@@ -327,9 +327,6 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
|
|
|
327
327
|
|
|
328
328
|
var SpriteAnimation$3 = SpriteAnimation$2;
|
|
329
329
|
var resourceKeySplit = '_s|r|c_';
|
|
330
|
-
Object.defineProperty(eva_js.RESOURCE_TYPE, 'SPRITE_ANIMATION', {
|
|
331
|
-
value: 'SPRITE_ANIMATION'
|
|
332
|
-
});
|
|
333
330
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
334
331
|
var name = _a.name,
|
|
335
332
|
data = _a.data;
|
|
@@ -576,3 +573,5 @@ this.EVA.plugin.renderer.spriteAnimation = function (exports, eva_js, pluginRend
|
|
|
576
573
|
});
|
|
577
574
|
return exports;
|
|
578
575
|
}({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter, PIXI);
|
|
576
|
+
|
|
577
|
+
window.EVA.plugin.renderer.spriteAnimation = window.EVA.plugin.renderer.spriteAnimation || _EVA_IIFE_spriteAnimation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return
|
|
1
|
+
function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}var _EVA_IIFE_spriteAnimation=function(t,e,n,r,o){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function a(t,e){function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function s(t,e,n,r){var o,i=arguments.length,a=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function c(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((r=r.apply(t,e||[])).next())}))}function p(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function u(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function l(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}function f(t){return function(e,n){var r=l(e,n);r.key=n,r.type=t}}function m(t){return function(e,n){l(e,n).step=t}}var h=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.autoPlay=!0,e.speed=100,e.waitPlay=!1,e.waitStop=!1,e.times=1/0,e.count=0,e}return a(e,t),e.prototype.init=function(t){var e=this;t&&_extends(this,t),this.on("loop",(function(){++e.count>=e.times&&(e.animate.stop(),e.emit("complete"))}))},e.prototype.play=function(t){void 0===t&&(t=1/0),0!==t&&(this.times=t,this.animate?(this.animate.play(),this.count=0):this.waitPlay=!0)},e.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(e.prototype,"animate",{get:function(){return this._animate},set:function(t){this._animate=t,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),e.prototype.gotoAndPlay=function(t){this.animate.gotoAndPlay(t)},e.prototype.gotoAndStop=function(t){this.animate.gotoAndStop(t)},e.componentName="SpriteAnimation",s([f("string")],e.prototype,"resource",void 0),s([f("boolean")],e.prototype,"autoPlay",void 0),s([f("number"),m(10)],e.prototype,"speed",void 0),e}(e.Component),d="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e=t.name,n=t.data;return new Promise((function(t){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},p=a.animations||{},l={};for(var f in c){l[e+d+f]=c[f]}for(var f in p){var m=[];if(p[f]&&p[f].length>=0)try{for(var h=(r=void 0,u(p[f])),y=h.next();!y.done;y=h.next()){var v=y.value,g=e+d+v;m.push(g)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}p[f]=m}a.frames=l;var b=new o.Spritesheet(s,a);b.parse((function(){var e=b.textures,n=[];for(var r in e)n.push(e[r]);t(n)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e,n,r=t.instance;if(r)try{for(var o=u(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}}));var y=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(t){var e=t.transform.size,n=e.width,r=e.height;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=n,this.animates[t.id].animatedSprite.height=r)},o.prototype.componentChanged=function(t){return c(this,void 0,void 0,(function(){var n,r,o;return p(this,(function(i){switch(i.label){case 0:return"SpriteAnimation"!==t.componentName?[3,7]:(n=t.component,this.autoPlay[t.gameObject.id]=n.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:[4,e.resource.getResource(n.resource)]);case 1:return(r=i.sent().instance)||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:r,id:t.gameObject.id,component:n}),[3,7];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/n.speed,[3,5]):[3,3];case 3:return[4,e.resource.getResource(n.resource)];case 4:(o=i.sent().instance)||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:o,id:t.gameObject.id,component:n}),i.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t.gameObject.id),i.label=7;case 7:return[2]}}))}))},o.prototype.add=function(t){var e=t.frames,n=t.id,o=t.component,i=new r.SpriteAnimation({frames:e});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(t){var e=t.frames,n=t.id,r=t.component;this.remove(n,!0),this.add({frames:e,id:n,component:r})},o.prototype.remove=function(t,e){var n=this.animates[t];this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[t],e||delete this.autoPlay[t]},o.systemName="SpriteAnimation",o=s([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer);return t.SpriteAnimation=h,t.SpriteAnimationSystem=y,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import { __extends, __decorate, __values, __awaiter, __generator } from 'tslib';
|
|
4
|
+
import { Component, resource, RESOURCE_TYPE, OBSERVER_TYPE, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
5
|
+
import { type, step } from '@eva/inspector-decorator';
|
|
6
|
+
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
7
|
+
import { SpriteAnimation as SpriteAnimation$4 } from '@eva/renderer-adapter/dist/miniprogram';
|
|
8
|
+
import { BaseTexture, Spritesheet } from '@eva/miniprogram-pixi';
|
|
9
|
+
|
|
10
|
+
var SpriteAnimation$2 = function (_super) {
|
|
11
|
+
__extends(SpriteAnimation, _super);
|
|
12
|
+
|
|
13
|
+
function SpriteAnimation() {
|
|
14
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
15
|
+
|
|
16
|
+
_this.resource = '';
|
|
17
|
+
_this.autoPlay = true;
|
|
18
|
+
_this.speed = 100;
|
|
19
|
+
_this.waitPlay = false;
|
|
20
|
+
_this.waitStop = false;
|
|
21
|
+
_this.times = Infinity;
|
|
22
|
+
_this.count = 0;
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
SpriteAnimation.prototype.init = function (obj) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
|
|
29
|
+
obj && _extends(this, obj);
|
|
30
|
+
this.on('loop', function () {
|
|
31
|
+
if (++_this.count >= _this.times) {
|
|
32
|
+
_this.animate.stop();
|
|
33
|
+
|
|
34
|
+
_this.emit('complete');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
SpriteAnimation.prototype.play = function (times) {
|
|
40
|
+
if (times === void 0) {
|
|
41
|
+
times = Infinity;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (times === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.times = times;
|
|
49
|
+
|
|
50
|
+
if (!this.animate) {
|
|
51
|
+
this.waitPlay = true;
|
|
52
|
+
} else {
|
|
53
|
+
this.animate.play();
|
|
54
|
+
this.count = 0;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
SpriteAnimation.prototype.stop = function () {
|
|
59
|
+
if (!this.animate) {
|
|
60
|
+
this.waitStop = true;
|
|
61
|
+
} else {
|
|
62
|
+
this.animate.stop();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
Object.defineProperty(SpriteAnimation.prototype, "animate", {
|
|
67
|
+
get: function get() {
|
|
68
|
+
return this._animate;
|
|
69
|
+
},
|
|
70
|
+
set: function set(val) {
|
|
71
|
+
this._animate = val;
|
|
72
|
+
|
|
73
|
+
if (this.waitPlay) {
|
|
74
|
+
this.waitPlay = false;
|
|
75
|
+
this.play(this.times);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (this.waitStop) {
|
|
79
|
+
this.waitStop = false;
|
|
80
|
+
this.stop();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
SpriteAnimation.prototype.gotoAndPlay = function (frameNumber) {
|
|
88
|
+
this.animate.gotoAndPlay(frameNumber);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
|
|
92
|
+
this.animate.gotoAndStop(frameNumber);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
SpriteAnimation.componentName = 'SpriteAnimation';
|
|
96
|
+
|
|
97
|
+
__decorate([type('string')], SpriteAnimation.prototype, "resource", void 0);
|
|
98
|
+
|
|
99
|
+
__decorate([type('boolean')], SpriteAnimation.prototype, "autoPlay", void 0);
|
|
100
|
+
|
|
101
|
+
__decorate([type('number'), step(10)], SpriteAnimation.prototype, "speed", void 0);
|
|
102
|
+
|
|
103
|
+
return SpriteAnimation;
|
|
104
|
+
}(Component);
|
|
105
|
+
|
|
106
|
+
var SpriteAnimation$3 = SpriteAnimation$2;
|
|
107
|
+
var resourceKeySplit = '_s|r|c_';
|
|
108
|
+
resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
109
|
+
var name = _a.name,
|
|
110
|
+
data = _a.data;
|
|
111
|
+
return new Promise(function (r) {
|
|
112
|
+
var e_1, _a;
|
|
113
|
+
|
|
114
|
+
var textureObj = data.json;
|
|
115
|
+
var texture = BaseTexture.from(data.image);
|
|
116
|
+
var frames = textureObj.frames || {};
|
|
117
|
+
var animations = textureObj.animations || {};
|
|
118
|
+
var newFrames = {};
|
|
119
|
+
|
|
120
|
+
for (var key in frames) {
|
|
121
|
+
var newKey = name + resourceKeySplit + key;
|
|
122
|
+
newFrames[newKey] = frames[key];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (var key in animations) {
|
|
126
|
+
var spriteList = [];
|
|
127
|
+
|
|
128
|
+
if (animations[key] && animations[key].length >= 0) {
|
|
129
|
+
try {
|
|
130
|
+
for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
131
|
+
var spriteName = _c.value;
|
|
132
|
+
var newSpriteName = name + resourceKeySplit + spriteName;
|
|
133
|
+
spriteList.push(newSpriteName);
|
|
134
|
+
}
|
|
135
|
+
} catch (e_1_1) {
|
|
136
|
+
e_1 = {
|
|
137
|
+
error: e_1_1
|
|
138
|
+
};
|
|
139
|
+
} finally {
|
|
140
|
+
try {
|
|
141
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
142
|
+
} finally {
|
|
143
|
+
if (e_1) throw e_1.error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
animations[key] = spriteList;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
textureObj.frames = newFrames;
|
|
152
|
+
var spriteSheet = new Spritesheet(texture, textureObj);
|
|
153
|
+
spriteSheet.parse(function () {
|
|
154
|
+
var textures = spriteSheet.textures;
|
|
155
|
+
var spriteFrames = [];
|
|
156
|
+
|
|
157
|
+
for (var key in textures) {
|
|
158
|
+
spriteFrames.push(textures[key]);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
r(spriteFrames);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
166
|
+
var e_2, _b;
|
|
167
|
+
|
|
168
|
+
var instance = _a.instance;
|
|
169
|
+
if (!instance) return;
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
for (var instance_1 = __values(instance), instance_1_1 = instance_1.next(); !instance_1_1.done; instance_1_1 = instance_1.next()) {
|
|
173
|
+
var texture = instance_1_1.value;
|
|
174
|
+
texture.destroy(true);
|
|
175
|
+
}
|
|
176
|
+
} catch (e_2_1) {
|
|
177
|
+
e_2 = {
|
|
178
|
+
error: e_2_1
|
|
179
|
+
};
|
|
180
|
+
} finally {
|
|
181
|
+
try {
|
|
182
|
+
if (instance_1_1 && !instance_1_1.done && (_b = instance_1.return)) _b.call(instance_1);
|
|
183
|
+
} finally {
|
|
184
|
+
if (e_2) throw e_2.error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
var SpriteAnimation = function (_super) {
|
|
190
|
+
__extends(SpriteAnimation, _super);
|
|
191
|
+
|
|
192
|
+
function SpriteAnimation() {
|
|
193
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
194
|
+
|
|
195
|
+
_this.name = 'SpriteAnimation';
|
|
196
|
+
_this.animates = {};
|
|
197
|
+
_this.autoPlay = {};
|
|
198
|
+
return _this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
SpriteAnimation.prototype.init = function () {
|
|
202
|
+
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
203
|
+
this.renderSystem.rendererManager.register(this);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
SpriteAnimation.prototype.rendererUpdate = function (gameObject) {
|
|
207
|
+
var _a = gameObject.transform.size,
|
|
208
|
+
width = _a.width,
|
|
209
|
+
height = _a.height;
|
|
210
|
+
|
|
211
|
+
if (this.animates[gameObject.id]) {
|
|
212
|
+
this.animates[gameObject.id].animatedSprite.width = width;
|
|
213
|
+
this.animates[gameObject.id].animatedSprite.height = height;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
SpriteAnimation.prototype.componentChanged = function (changed) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
var component, frames_1, frames_2;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
|
|
224
|
+
component = changed.component;
|
|
225
|
+
this.autoPlay[changed.gameObject.id] = component.autoPlay;
|
|
226
|
+
if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
|
|
227
|
+
return [4, resource.getResource(component.resource)];
|
|
228
|
+
|
|
229
|
+
case 1:
|
|
230
|
+
frames_1 = _a.sent().instance;
|
|
231
|
+
|
|
232
|
+
if (!frames_1) {
|
|
233
|
+
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
this.add({
|
|
237
|
+
frames: frames_1,
|
|
238
|
+
id: changed.gameObject.id,
|
|
239
|
+
component: component
|
|
240
|
+
});
|
|
241
|
+
return [3, 7];
|
|
242
|
+
|
|
243
|
+
case 2:
|
|
244
|
+
if (!(changed.type === OBSERVER_TYPE.CHANGE)) return [3, 6];
|
|
245
|
+
if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
|
|
246
|
+
this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
|
|
247
|
+
return [3, 5];
|
|
248
|
+
|
|
249
|
+
case 3:
|
|
250
|
+
return [4, resource.getResource(component.resource)];
|
|
251
|
+
|
|
252
|
+
case 4:
|
|
253
|
+
frames_2 = _a.sent().instance;
|
|
254
|
+
|
|
255
|
+
if (!frames_2) {
|
|
256
|
+
console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
this.change({
|
|
260
|
+
frames: frames_2,
|
|
261
|
+
id: changed.gameObject.id,
|
|
262
|
+
component: component
|
|
263
|
+
});
|
|
264
|
+
_a.label = 5;
|
|
265
|
+
|
|
266
|
+
case 5:
|
|
267
|
+
return [3, 7];
|
|
268
|
+
|
|
269
|
+
case 6:
|
|
270
|
+
if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
271
|
+
this.remove(changed.gameObject.id);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
_a.label = 7;
|
|
275
|
+
|
|
276
|
+
case 7:
|
|
277
|
+
return [2];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
SpriteAnimation.prototype.add = function (_a) {
|
|
284
|
+
var frames = _a.frames,
|
|
285
|
+
id = _a.id,
|
|
286
|
+
component = _a.component;
|
|
287
|
+
var animate = new SpriteAnimation$4({
|
|
288
|
+
frames: frames
|
|
289
|
+
});
|
|
290
|
+
this.animates[id] = animate;
|
|
291
|
+
this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
|
|
292
|
+
|
|
293
|
+
animate.animatedSprite.onComplete = function () {
|
|
294
|
+
component.emit('complete');
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
animate.animatedSprite.onFrameChange = function () {
|
|
298
|
+
component.emit('frameChange');
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
animate.animatedSprite.onLoop = function () {
|
|
302
|
+
component.emit('loop');
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
component.animate = this.animates[id];
|
|
306
|
+
this.animates[id].speed = 1000 / 60 / component.speed;
|
|
307
|
+
|
|
308
|
+
if (this.autoPlay[id]) {
|
|
309
|
+
animate.animatedSprite.play();
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
SpriteAnimation.prototype.change = function (_a) {
|
|
314
|
+
var frames = _a.frames,
|
|
315
|
+
id = _a.id,
|
|
316
|
+
component = _a.component;
|
|
317
|
+
this.remove(id, true);
|
|
318
|
+
this.add({
|
|
319
|
+
frames: frames,
|
|
320
|
+
id: id,
|
|
321
|
+
component: component
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
SpriteAnimation.prototype.remove = function (id, isChange) {
|
|
326
|
+
var animate = this.animates[id];
|
|
327
|
+
this.autoPlay[id] = animate.animatedSprite.playing;
|
|
328
|
+
this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
|
|
329
|
+
animate.animatedSprite.destroy({
|
|
330
|
+
children: true
|
|
331
|
+
});
|
|
332
|
+
delete this.animates[id];
|
|
333
|
+
|
|
334
|
+
if (!isChange) {
|
|
335
|
+
delete this.autoPlay[id];
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
SpriteAnimation.systemName = 'SpriteAnimation';
|
|
340
|
+
SpriteAnimation = __decorate([decorators.componentObserver({
|
|
341
|
+
SpriteAnimation: ['speed', 'resource']
|
|
342
|
+
})], SpriteAnimation);
|
|
343
|
+
return SpriteAnimation;
|
|
344
|
+
}(Renderer);
|
|
345
|
+
|
|
346
|
+
var SpriteAnimation$1 = SpriteAnimation;
|
|
347
|
+
export { SpriteAnimation$3 as SpriteAnimation, SpriteAnimation$1 as SpriteAnimationSystem };
|
|
@@ -177,9 +177,6 @@ var SpriteAnimation$2 = (function (_super) {
|
|
|
177
177
|
var SpriteAnimation$3 = SpriteAnimation$2;
|
|
178
178
|
|
|
179
179
|
var resourceKeySplit = '_s|r|c_';
|
|
180
|
-
Object.defineProperty(eva_js.RESOURCE_TYPE, 'SPRITE_ANIMATION', {
|
|
181
|
-
value: 'SPRITE_ANIMATION'
|
|
182
|
-
});
|
|
183
180
|
eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
184
181
|
var name = _a.name, data = _a.data;
|
|
185
182
|
return new Promise(function (r) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),n=require("@eva/plugin-renderer"),r=require("@eva/renderer-adapter"),o=require("pixi.js"),i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function s(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function c(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function p(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}var u=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.autoPlay=!0,t.speed=100,t.waitPlay=!1,t.waitStop=!1,t.times=1/0,t.count=0,t}return a(n,e),n.prototype.init=function(e){var t=this;e&&Object.assign(this,e),this.on("loop",(function(){++t.count>=t.times&&(t.animate.stop(),t.emit("complete"))}))},n.prototype.play=function(e){void 0===e&&(e=1/0),0!==e&&(this.times=e,this.animate?(this.animate.play(),this.count=0):this.waitPlay=!0)},n.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(n.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),n.prototype.gotoAndPlay=function(e){this.animate.gotoAndPlay(e)},n.prototype.gotoAndStop=function(e){this.animate.gotoAndStop(e)},n.componentName="SpriteAnimation",s([t.type("string")],n.prototype,"resource",void 0),s([t.type("boolean")],n.prototype,"autoPlay",void 0),s([t.type("number"),t.step(10)],n.prototype,"speed",void 0),n}(e.Component);e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t=e.name,n=e.data;return new Promise((function(e){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},u=a.animations||{},l={};for(var m in c){l[t+"_s|r|c_"+m]=c[m]}for(var m in u){var f=[];if(u[m]&&u[m].length>=0)try{for(var h=(r=void 0,p(u[m])),d=h.next();!d.done;d=h.next()){var y=d.value,v=t+"_s|r|c_"+y;f.push(v)}}catch(e){r={error:e}}finally{try{d&&!d.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}u[m]=f}a.frames=l;var g=new o.Spritesheet(s,a);g.parse((function(){var t=g.textures,n=[];for(var r in t)n.push(t[r]);e(n)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(e){var t,n,r=e.instance;if(r)try{for(var o=p(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}}));var l=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(e){var t=e.transform.size,n=t.width,r=t.height;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=n,this.animates[e.id].animatedSprite.height=r)},o.prototype.componentChanged=function(t){return n=this,r=void 0,i=function(){var n,r,o;return c(this,(function(i){switch(i.label){case 0:return"SpriteAnimation"!==t.componentName?[3,7]:(n=t.component,this.autoPlay[t.gameObject.id]=n.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:[4,e.resource.getResource(n.resource)]);case 1:return(r=i.sent().instance)||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:r,id:t.gameObject.id,component:n}),[3,7];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/n.speed,[3,5]):[3,3];case 3:return[4,e.resource.getResource(n.resource)];case 4:(o=i.sent().instance)||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:o,id:t.gameObject.id,component:n}),i.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t.gameObject.id),i.label=7;case 7:return[2]}}))},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(i.next(e))}catch(e){t(e)}}function s(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new o((function(e){e(t.value)})).then(a,s)}c((i=i.apply(n,r||[])).next())}));var n,r,o,i},o.prototype.add=function(e){var t=e.frames,n=e.id,o=e.component,i=new r.SpriteAnimation({frames:t});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(e){var t=e.frames,n=e.id,r=e.component;this.remove(n,!0),this.add({frames:t,id:n,component:r})},o.prototype.remove=function(e,t){var n=this.animates[e];this.autoPlay[e]=n.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[e],t||delete this.autoPlay[e]},o.systemName="SpriteAnimation",o=s([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer);exports.SpriteAnimation=u,exports.SpriteAnimationSystem=l;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component,
|
|
1
|
+
import { Component, resource, RESOURCE_TYPE, decorators, OBSERVER_TYPE } from '@eva/eva.js';
|
|
2
2
|
import { type, step } from '@eva/inspector-decorator';
|
|
3
3
|
import { RendererSystem, Renderer } from '@eva/plugin-renderer';
|
|
4
4
|
import { SpriteAnimation as SpriteAnimation$4 } from '@eva/renderer-adapter';
|
|
@@ -173,9 +173,6 @@ var SpriteAnimation$2 = (function (_super) {
|
|
|
173
173
|
var SpriteAnimation$3 = SpriteAnimation$2;
|
|
174
174
|
|
|
175
175
|
var resourceKeySplit = '_s|r|c_';
|
|
176
|
-
Object.defineProperty(RESOURCE_TYPE, 'SPRITE_ANIMATION', {
|
|
177
|
-
value: 'SPRITE_ANIMATION'
|
|
178
|
-
});
|
|
179
176
|
resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
|
|
180
177
|
var name = _a.name, data = _a.data;
|
|
181
178
|
return new Promise(function (r) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-sprite-animation",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2-mini.1",
|
|
4
4
|
"description": "@eva/plugin-renderer-sprite-animation",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-sprite-animation.esm.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eva/inspector-decorator": "^0.0.5",
|
|
22
|
-
"@eva/plugin-renderer": "1.2.
|
|
23
|
-
"@eva/renderer-adapter": "1.2.
|
|
24
|
-
"@eva/eva.js": "1.2.
|
|
22
|
+
"@eva/plugin-renderer": "1.2.2-mini.1",
|
|
23
|
+
"@eva/renderer-adapter": "1.2.2-mini.1",
|
|
24
|
+
"@eva/eva.js": "1.2.2-mini.1",
|
|
25
25
|
"pixi.js": "^4.8.7"
|
|
26
26
|
}
|
|
27
27
|
}
|