@leafer-in/robot 1.0.10 → 1.1.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/robot.cjs CHANGED
@@ -79,15 +79,18 @@ exports.Robot = class Robot extends draw.UI {
79
79
  if (typeof action === 'number') {
80
80
  this.now = action;
81
81
  }
82
- else if (action instanceof Array) {
83
- const { length } = action;
82
+ else if (typeof action === 'object') {
83
+ const isArray = action instanceof Array;
84
+ const keyframes = isArray ? action : action.keyframes;
85
+ this.__action = isArray ? undefined : action;
86
+ const { length } = keyframes;
84
87
  if (length > 1) {
85
- const start = this.now = action[0], end = action[action.length - 1];
88
+ const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1];
86
89
  this.play();
87
90
  this.__runAction(start, end);
88
91
  }
89
92
  else if (length)
90
- this.now = action[0];
93
+ this.now = keyframes[0];
91
94
  }
92
95
  }
93
96
  __loadRobot(frame, start, end) {
@@ -115,16 +118,26 @@ exports.Robot = class Robot extends draw.UI {
115
118
  this.emitEvent(new draw.ImageEvent(draw.ImageEvent.LOADED, { image }));
116
119
  }
117
120
  __runAction(start, end) {
121
+ let { FPS, loop, __action: a } = this;
122
+ if (a) {
123
+ if (a.FPS)
124
+ FPS = a.FPS;
125
+ if (a.loop !== undefined)
126
+ loop = a.loop;
127
+ }
118
128
  this.__timer = setTimeout(() => {
119
129
  if (this.running) {
120
- if (this.now === end)
130
+ if (this.now === end) {
131
+ if (!loop)
132
+ return this.stop();
121
133
  this.now = start;
134
+ }
122
135
  else
123
136
  this.now++;
124
137
  this.__updateRobotBounds();
125
138
  }
126
139
  this.__runAction(start, end);
127
- }, 1000 / this.FPS);
140
+ }, 1000 / FPS);
128
141
  }
129
142
  __updateRobotBounds() {
130
143
  const { nowFrame } = this;
package/dist/robot.esm.js CHANGED
@@ -77,15 +77,18 @@ let Robot = class Robot extends UI {
77
77
  if (typeof action === 'number') {
78
78
  this.now = action;
79
79
  }
80
- else if (action instanceof Array) {
81
- const { length } = action;
80
+ else if (typeof action === 'object') {
81
+ const isArray = action instanceof Array;
82
+ const keyframes = isArray ? action : action.keyframes;
83
+ this.__action = isArray ? undefined : action;
84
+ const { length } = keyframes;
82
85
  if (length > 1) {
83
- const start = this.now = action[0], end = action[action.length - 1];
86
+ const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1];
84
87
  this.play();
85
88
  this.__runAction(start, end);
86
89
  }
87
90
  else if (length)
88
- this.now = action[0];
91
+ this.now = keyframes[0];
89
92
  }
90
93
  }
91
94
  __loadRobot(frame, start, end) {
@@ -113,16 +116,26 @@ let Robot = class Robot extends UI {
113
116
  this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
114
117
  }
115
118
  __runAction(start, end) {
119
+ let { FPS, loop, __action: a } = this;
120
+ if (a) {
121
+ if (a.FPS)
122
+ FPS = a.FPS;
123
+ if (a.loop !== undefined)
124
+ loop = a.loop;
125
+ }
116
126
  this.__timer = setTimeout(() => {
117
127
  if (this.running) {
118
- if (this.now === end)
128
+ if (this.now === end) {
129
+ if (!loop)
130
+ return this.stop();
119
131
  this.now = start;
132
+ }
120
133
  else
121
134
  this.now++;
122
135
  this.__updateRobotBounds();
123
136
  }
124
137
  this.__runAction(start, end);
125
- }, 1000 / this.FPS);
138
+ }, 1000 / FPS);
126
139
  }
127
140
  __updateRobotBounds() {
128
141
  const { nowFrame } = this;
@@ -1 +1 @@
1
- import{UIData as t,dataProcessor as o,boundsType as e,dataType as i,surfaceType as r,registerUI as s,UI as n,ImageManager as h,ImageEvent as a}from"@leafer-ui/draw";function _(t,o,e,i){var r,s=arguments.length,n=s<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,o,e,i);else for(var h=t.length-1;h>=0;h--)(r=t[h])&&(n=(s<3?r(n):s>3?r(o,e,n):r(o,e))||n);return s>3&&n&&Object.defineProperty(o,e,n),n}"function"==typeof SuppressedError&&SuppressedError;class d extends t{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}let p=class extends n{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;t instanceof Array?t.forEach((t=>this.__loadRobot(t,o,o+=t.total||1))):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),void 0!==t)if("number"==typeof t)this.now=t;else if(t instanceof Array){const{length:o}=t;if(o>1){const o=this.now=t[0],e=t[t.length-1];this.play(),this.__runAction(o,e)}else o&&(this.now=t[0])}}__loadRobot(t,o,e){for(let t=o;t<e;t++)this.robotFrames.push(void 0);const i=h.get(t);i.ready?this.__createFrames(i,t,o,e):i.load((()=>this.__createFrames(i,t,o,e)))}__createFrames(t,o,e,i){const{offset:r,size:s,total:n}=o,{width:h,height:_}=s&&("number"==typeof s?{width:s,height:s}:s)||(n>1?this:t);let d=r?r.x:0,p=r?r.y:0;for(let o=e;o<i;o++)this.robotFrames[o]={view:t.view,x:d,y:p,width:h,height:_},d+h>=t.width?(d=0,p+=_):d+=h;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new a(a.LOADED,{image:t}))}__runAction(t,o){this.__timer=setTimeout((()=>{this.running&&(this.now===o?this.now=t:this.now++,this.__updateRobotBounds()),this.__runAction(t,o)}),1e3/this.FPS)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:r}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,r)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}};_([o(d)],p.prototype,"__",void 0),_([e()],p.prototype,"robot",void 0),_([i()],p.prototype,"actions",void 0),_([i("")],p.prototype,"action",void 0),_([r(0)],p.prototype,"now",void 0),_([i(12)],p.prototype,"FPS",void 0),_([i(!0)],p.prototype,"loop",void 0),p=_([s()],p);export{p as Robot,d as RobotData};
1
+ import{UIData as t,dataProcessor as o,boundsType as e,dataType as i,surfaceType as s,registerUI as r,UI as n,ImageManager as h,ImageEvent as a}from"@leafer-ui/draw";function _(t,o,e,i){var s,r=arguments.length,n=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,o,e,i);else for(var h=t.length-1;h>=0;h--)(s=t[h])&&(n=(r<3?s(n):r>3?s(o,e,n):s(o,e))||n);return r>3&&n&&Object.defineProperty(o,e,n),n}"function"==typeof SuppressedError&&SuppressedError;class p extends t{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}let d=class extends n{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;t instanceof Array?t.forEach((t=>this.__loadRobot(t,o,o+=t.total||1))):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),void 0!==t)if("number"==typeof t)this.now=t;else if("object"==typeof t){const o=t instanceof Array,e=o?t:t.keyframes;this.__action=o?void 0:t;const{length:i}=e;if(i>1){const t=this.now=e[0],o=e[e.length-1];this.play(),this.__runAction(t,o)}else i&&(this.now=e[0])}}__loadRobot(t,o,e){for(let t=o;t<e;t++)this.robotFrames.push(void 0);const i=h.get(t);i.ready?this.__createFrames(i,t,o,e):i.load((()=>this.__createFrames(i,t,o,e)))}__createFrames(t,o,e,i){const{offset:s,size:r,total:n}=o,{width:h,height:_}=r&&("number"==typeof r?{width:r,height:r}:r)||(n>1?this:t);let p=s?s.x:0,d=s?s.y:0;for(let o=e;o<i;o++)this.robotFrames[o]={view:t.view,x:p,y:d,width:h,height:_},p+h>=t.width?(p=0,d+=_):p+=h;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new a(a.LOADED,{image:t}))}__runAction(t,o){let{FPS:e,loop:i,__action:s}=this;s&&(s.FPS&&(e=s.FPS),void 0!==s.loop&&(i=s.loop)),this.__timer=setTimeout((()=>{if(this.running){if(this.now===o){if(!i)return this.stop();this.now=t}else this.now++;this.__updateRobotBounds()}this.__runAction(t,o)}),1e3/e)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:s}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,s)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}};_([o(p)],d.prototype,"__",void 0),_([e()],d.prototype,"robot",void 0),_([i()],d.prototype,"actions",void 0),_([i("")],d.prototype,"action",void 0),_([s(0)],d.prototype,"now",void 0),_([i(12)],d.prototype,"FPS",void 0),_([i(!0)],d.prototype,"loop",void 0),d=_([r()],d);export{d as Robot,p as RobotData};
package/dist/robot.js CHANGED
@@ -1,5 +1,5 @@
1
1
  this.LeaferIN = this.LeaferIN || {};
2
- this.LeaferIN.Robot = (function (exports, draw) {
2
+ this.LeaferIN.robot = (function (exports, draw) {
3
3
  'use strict';
4
4
 
5
5
  /******************************************************************************
@@ -79,15 +79,18 @@ this.LeaferIN.Robot = (function (exports, draw) {
79
79
  if (typeof action === 'number') {
80
80
  this.now = action;
81
81
  }
82
- else if (action instanceof Array) {
83
- const { length } = action;
82
+ else if (typeof action === 'object') {
83
+ const isArray = action instanceof Array;
84
+ const keyframes = isArray ? action : action.keyframes;
85
+ this.__action = isArray ? undefined : action;
86
+ const { length } = keyframes;
84
87
  if (length > 1) {
85
- const start = this.now = action[0], end = action[action.length - 1];
88
+ const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1];
86
89
  this.play();
87
90
  this.__runAction(start, end);
88
91
  }
89
92
  else if (length)
90
- this.now = action[0];
93
+ this.now = keyframes[0];
91
94
  }
92
95
  }
93
96
  __loadRobot(frame, start, end) {
@@ -115,16 +118,26 @@ this.LeaferIN.Robot = (function (exports, draw) {
115
118
  this.emitEvent(new draw.ImageEvent(draw.ImageEvent.LOADED, { image }));
116
119
  }
117
120
  __runAction(start, end) {
121
+ let { FPS, loop, __action: a } = this;
122
+ if (a) {
123
+ if (a.FPS)
124
+ FPS = a.FPS;
125
+ if (a.loop !== undefined)
126
+ loop = a.loop;
127
+ }
118
128
  this.__timer = setTimeout(() => {
119
129
  if (this.running) {
120
- if (this.now === end)
130
+ if (this.now === end) {
131
+ if (!loop)
132
+ return this.stop();
121
133
  this.now = start;
134
+ }
122
135
  else
123
136
  this.now++;
124
137
  this.__updateRobotBounds();
125
138
  }
126
139
  this.__runAction(start, end);
127
- }, 1000 / this.FPS);
140
+ }, 1000 / FPS);
128
141
  }
129
142
  __updateRobotBounds() {
130
143
  const { nowFrame } = this;
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/draw");function o(t,o,e,i){var r,s=arguments.length,a=s<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,o,e,i);else for(var n=t.length-1;n>=0;n--)(r=t[n])&&(a=(s<3?r(a):s>3?r(o,e,a):r(o,e))||a);return s>3&&a&&Object.defineProperty(o,e,a),a}"function"==typeof SuppressedError&&SuppressedError;class e extends t.UIData{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}exports.Robot=class extends t.UI{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;t instanceof Array?t.forEach((t=>this.__loadRobot(t,o,o+=t.total||1))):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),void 0!==t)if("number"==typeof t)this.now=t;else if(t instanceof Array){const{length:o}=t;if(o>1){const o=this.now=t[0],e=t[t.length-1];this.play(),this.__runAction(o,e)}else o&&(this.now=t[0])}}__loadRobot(o,e,i){for(let t=e;t<i;t++)this.robotFrames.push(void 0);const r=t.ImageManager.get(o);r.ready?this.__createFrames(r,o,e,i):r.load((()=>this.__createFrames(r,o,e,i)))}__createFrames(o,e,i,r){const{offset:s,size:a,total:n}=e,{width:h,height:p}=a&&("number"==typeof a?{width:a,height:a}:a)||(n>1?this:o);let _=s?s.x:0,d=s?s.y:0;for(let t=i;t<r;t++)this.robotFrames[t]={view:o.view,x:_,y:d,width:h,height:p},_+h>=o.width?(_=0,d+=p):_+=h;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new t.ImageEvent(t.ImageEvent.LOADED,{image:o}))}__runAction(t,o){this.__timer=setTimeout((()=>{this.running&&(this.now===o?this.now=t:this.now++,this.__updateRobotBounds()),this.__runAction(t,o)}),1e3/this.FPS)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:r}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,r)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}},o([t.dataProcessor(e)],exports.Robot.prototype,"__",void 0),o([t.boundsType()],exports.Robot.prototype,"robot",void 0),o([t.dataType()],exports.Robot.prototype,"actions",void 0),o([t.dataType("")],exports.Robot.prototype,"action",void 0),o([t.surfaceType(0)],exports.Robot.prototype,"now",void 0),o([t.dataType(12)],exports.Robot.prototype,"FPS",void 0),o([t.dataType(!0)],exports.Robot.prototype,"loop",void 0),exports.Robot=o([t.registerUI()],exports.Robot),exports.RobotData=e;
1
+ "use strict";var t=require("@leafer-ui/draw");function o(t,o,e,i){var s,r=arguments.length,a=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,o,e,i);else for(var n=t.length-1;n>=0;n--)(s=t[n])&&(a=(r<3?s(a):r>3?s(o,e,a):s(o,e))||a);return r>3&&a&&Object.defineProperty(o,e,a),a}"function"==typeof SuppressedError&&SuppressedError;class e extends t.UIData{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}exports.Robot=class extends t.UI{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;t instanceof Array?t.forEach((t=>this.__loadRobot(t,o,o+=t.total||1))):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),void 0!==t)if("number"==typeof t)this.now=t;else if("object"==typeof t){const o=t instanceof Array,e=o?t:t.keyframes;this.__action=o?void 0:t;const{length:i}=e;if(i>1){const t=this.now=e[0],o=e[e.length-1];this.play(),this.__runAction(t,o)}else i&&(this.now=e[0])}}__loadRobot(o,e,i){for(let t=e;t<i;t++)this.robotFrames.push(void 0);const s=t.ImageManager.get(o);s.ready?this.__createFrames(s,o,e,i):s.load((()=>this.__createFrames(s,o,e,i)))}__createFrames(o,e,i,s){const{offset:r,size:a,total:n}=e,{width:h,height:p}=a&&("number"==typeof a?{width:a,height:a}:a)||(n>1?this:o);let _=r?r.x:0,d=r?r.y:0;for(let t=i;t<s;t++)this.robotFrames[t]={view:o.view,x:_,y:d,width:h,height:p},_+h>=o.width?(_=0,d+=p):_+=h;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new t.ImageEvent(t.ImageEvent.LOADED,{image:o}))}__runAction(t,o){let{FPS:e,loop:i,__action:s}=this;s&&(s.FPS&&(e=s.FPS),void 0!==s.loop&&(i=s.loop)),this.__timer=setTimeout((()=>{if(this.running){if(this.now===o){if(!i)return this.stop();this.now=t}else this.now++;this.__updateRobotBounds()}this.__runAction(t,o)}),1e3/e)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:s}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,s)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}},o([t.dataProcessor(e)],exports.Robot.prototype,"__",void 0),o([t.boundsType()],exports.Robot.prototype,"robot",void 0),o([t.dataType()],exports.Robot.prototype,"actions",void 0),o([t.dataType("")],exports.Robot.prototype,"action",void 0),o([t.surfaceType(0)],exports.Robot.prototype,"now",void 0),o([t.dataType(12)],exports.Robot.prototype,"FPS",void 0),o([t.dataType(!0)],exports.Robot.prototype,"loop",void 0),exports.Robot=o([t.registerUI()],exports.Robot),exports.RobotData=e;
package/dist/robot.min.js CHANGED
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.Robot=function(t,o){"use strict";function e(t,o,e,i){var s,r=arguments.length,a=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,o,e,i);else for(var n=t.length-1;n>=0;n--)(s=t[n])&&(a=(r<3?s(a):r>3?s(o,e,a):s(o,e))||a);return r>3&&a&&Object.defineProperty(o,e,a),a}"function"==typeof SuppressedError&&SuppressedError;class i extends o.UIData{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}return t.Robot=class extends o.UI{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;t instanceof Array?t.forEach((t=>this.__loadRobot(t,o,o+=t.total||1))):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),void 0!==t)if("number"==typeof t)this.now=t;else if(t instanceof Array){const{length:o}=t;if(o>1){const o=this.now=t[0],e=t[t.length-1];this.play(),this.__runAction(o,e)}else o&&(this.now=t[0])}}__loadRobot(t,e,i){for(let t=e;t<i;t++)this.robotFrames.push(void 0);const s=o.ImageManager.get(t);s.ready?this.__createFrames(s,t,e,i):s.load((()=>this.__createFrames(s,t,e,i)))}__createFrames(t,e,i,s){const{offset:r,size:a,total:n}=e,{width:h,height:_}=a&&("number"==typeof a?{width:a,height:a}:a)||(n>1?this:t);let d=r?r.x:0,p=r?r.y:0;for(let o=i;o<s;o++)this.robotFrames[o]={view:t.view,x:d,y:p,width:h,height:_},d+h>=t.width?(d=0,p+=_):d+=h;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new o.ImageEvent(o.ImageEvent.LOADED,{image:t}))}__runAction(t,o){this.__timer=setTimeout((()=>{this.running&&(this.now===o?this.now=t:this.now++,this.__updateRobotBounds()),this.__runAction(t,o)}),1e3/this.FPS)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:s}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,s)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}},e([o.dataProcessor(i)],t.Robot.prototype,"__",void 0),e([o.boundsType()],t.Robot.prototype,"robot",void 0),e([o.dataType()],t.Robot.prototype,"actions",void 0),e([o.dataType("")],t.Robot.prototype,"action",void 0),e([o.surfaceType(0)],t.Robot.prototype,"now",void 0),e([o.dataType(12)],t.Robot.prototype,"FPS",void 0),e([o.dataType(!0)],t.Robot.prototype,"loop",void 0),t.Robot=e([o.registerUI()],t.Robot),t.RobotData=i,t}({},LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.robot=function(t,o){"use strict";function e(t,o,e,i){var s,r=arguments.length,a=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,o,e,i);else for(var n=t.length-1;n>=0;n--)(s=t[n])&&(a=(r<3?s(a):r>3?s(o,e,a):s(o,e))||a);return r>3&&a&&Object.defineProperty(o,e,a),a}"function"==typeof SuppressedError&&SuppressedError;class i extends o.UIData{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}return t.Robot=class extends o.UI{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;t instanceof Array?t.forEach((t=>this.__loadRobot(t,o,o+=t.total||1))):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),void 0!==t)if("number"==typeof t)this.now=t;else if("object"==typeof t){const o=t instanceof Array,e=o?t:t.keyframes;this.__action=o?void 0:t;const{length:i}=e;if(i>1){const t=this.now=e[0],o=e[e.length-1];this.play(),this.__runAction(t,o)}else i&&(this.now=e[0])}}__loadRobot(t,e,i){for(let t=e;t<i;t++)this.robotFrames.push(void 0);const s=o.ImageManager.get(t);s.ready?this.__createFrames(s,t,e,i):s.load((()=>this.__createFrames(s,t,e,i)))}__createFrames(t,e,i,s){const{offset:r,size:a,total:n}=e,{width:h,height:_}=a&&("number"==typeof a?{width:a,height:a}:a)||(n>1?this:t);let p=r?r.x:0,d=r?r.y:0;for(let o=i;o<s;o++)this.robotFrames[o]={view:t.view,x:p,y:d,width:h,height:_},p+h>=t.width?(p=0,d+=_):p+=h;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new o.ImageEvent(o.ImageEvent.LOADED,{image:t}))}__runAction(t,o){let{FPS:e,loop:i,__action:s}=this;s&&(s.FPS&&(e=s.FPS),void 0!==s.loop&&(i=s.loop)),this.__timer=setTimeout((()=>{if(this.running){if(this.now===o){if(!i)return this.stop();this.now=t}else this.now++;this.__updateRobotBounds()}this.__runAction(t,o)}),1e3/e)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:s}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,s)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}},e([o.dataProcessor(i)],t.Robot.prototype,"__",void 0),e([o.boundsType()],t.Robot.prototype,"robot",void 0),e([o.dataType()],t.Robot.prototype,"actions",void 0),e([o.dataType("")],t.Robot.prototype,"action",void 0),e([o.surfaceType(0)],t.Robot.prototype,"now",void 0),e([o.dataType(12)],t.Robot.prototype,"FPS",void 0),e([o.dataType(!0)],t.Robot.prototype,"loop",void 0),t.Robot=e([o.registerUI()],t.Robot),t.RobotData=i,t}({},LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/robot",
3
- "version": "1.0.10",
3
+ "version": "1.1.1",
4
4
  "description": "@leafer-in/robot",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/draw": "^1.0.10",
38
- "@leafer-ui/interface": "^1.0.10",
39
- "@leafer-in/interface": "^1.0.10"
37
+ "@leafer-ui/draw": "^1.1.1",
38
+ "@leafer-ui/interface": "^1.1.1",
39
+ "@leafer-in/interface": "^1.1.1"
40
40
  }
41
41
  }
package/src/Robot.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaferCanvas, IRenderOptions, ILeaferImage, IRobot, IRobotData, IRobotInputData, IRobotKeyframe, IRobotActions, IRobotActionName, IRobotComputedKeyframe } from '@leafer-ui/interface'
1
+ import { ILeaferCanvas, IRenderOptions, ILeaferImage, IRobot, IRobotData, IRobotInputData, IRobotKeyframe, IRobotActions, IRobotActionName, IRobotComputedKeyframe, IRobotAnimation } from '@leafer-ui/interface'
2
2
  import { UI, registerUI, dataProcessor, ImageEvent, surfaceType, ImageManager, dataType, boundsType } from '@leafer-ui/draw'
3
3
 
4
4
  import { RobotData } from './data/RobotData'
@@ -35,9 +35,10 @@ export class Robot extends UI implements IRobot {
35
35
  public FPS?: number
36
36
 
37
37
  @dataType(true)
38
- public loop?: boolean
38
+ public loop?: boolean | number
39
39
 
40
40
 
41
+ protected __action?: IRobotAnimation
41
42
  protected __timer: any
42
43
 
43
44
 
@@ -81,14 +82,18 @@ export class Robot extends UI implements IRobot {
81
82
 
82
83
  this.now = action
83
84
 
84
- } else if (action instanceof Array) {
85
+ } else if (typeof action === 'object') {
85
86
 
86
- const { length } = action
87
+ const isArray = action instanceof Array
88
+ const keyframes = isArray ? action : action.keyframes
89
+ this.__action = isArray ? undefined : action
90
+
91
+ const { length } = keyframes
87
92
  if (length > 1) {
88
- const start = this.now = action[0], end = action[action.length - 1]
93
+ const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1]
89
94
  this.play()
90
95
  this.__runAction(start, end)
91
- } else if (length) this.now = action[0]
96
+ } else if (length) this.now = keyframes[0]
92
97
 
93
98
  }
94
99
  }
@@ -121,15 +126,24 @@ export class Robot extends UI implements IRobot {
121
126
 
122
127
 
123
128
  protected __runAction(start: number, end: number): void {
129
+ let { FPS, loop, __action: a } = this
130
+ if (a) {
131
+ if (a.FPS) FPS = a.FPS
132
+ if (a.loop !== undefined) loop = a.loop
133
+ }
134
+
124
135
  this.__timer = setTimeout(() => {
136
+
125
137
  if (this.running) {
126
- if (this.now === end) this.now = start
127
- else this.now++
138
+ if (this.now === end) {
139
+ if (!loop) return this.stop()
140
+ this.now = start
141
+ } else this.now++
128
142
  this.__updateRobotBounds()
129
143
  }
130
144
 
131
145
  this.__runAction(start, end)
132
- }, 1000 / this.FPS)
146
+ }, 1000 / FPS)
133
147
  }
134
148
 
135
149
  protected __updateRobotBounds(): void {
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IRobot, IRobotComputedKeyframe, IRobotData, IRobotKeyframe, IRobotActions, IRobotActionName, IRobotInputData, ILeaferImage, ILeaferCanvas, IRenderOptions } from '@leafer-ui/interface';
1
+ import { IRobot, IRobotComputedKeyframe, IRobotData, IRobotKeyframe, IRobotActions, IRobotActionName, IRobotAnimation, IRobotInputData, ILeaferImage, ILeaferCanvas, IRenderOptions } from '@leafer-ui/interface';
2
2
  import { UI, UIData } from '@leafer-ui/draw';
3
3
 
4
4
  declare class Robot extends UI implements IRobot {
@@ -12,7 +12,8 @@ declare class Robot extends UI implements IRobot {
12
12
  action?: IRobotActionName;
13
13
  now?: number;
14
14
  FPS?: number;
15
- loop?: boolean;
15
+ loop?: boolean | number;
16
+ protected __action?: IRobotAnimation;
16
17
  protected __timer: any;
17
18
  constructor(data?: IRobotInputData);
18
19
  play(): void;