@litecanvas/utils 0.3.1 → 0.3.2
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/all.js +20 -16
- package/dist/all.min.js +1 -1
- package/dist/camera.js +20 -16
- package/dist/camera.min.js +1 -1
- package/package.json +1 -1
- package/src/camera/index.js +26 -19
package/dist/all.js
CHANGED
|
@@ -126,6 +126,26 @@
|
|
|
126
126
|
engine = engine || globalThis;
|
|
127
127
|
this._engine = engine;
|
|
128
128
|
this.size(engine.WIDTH || 0, engine.HEIGHT || 0);
|
|
129
|
+
this.x = this.width / 2;
|
|
130
|
+
this.y = this.height / 2;
|
|
131
|
+
}
|
|
132
|
+
size(width, height) {
|
|
133
|
+
this.width = width;
|
|
134
|
+
this.height = height;
|
|
135
|
+
}
|
|
136
|
+
start(clip = false) {
|
|
137
|
+
const centerX = this.width / 2, centerY = this.height / 2;
|
|
138
|
+
this._engine.push();
|
|
139
|
+
this._engine.translate(centerX, centerY);
|
|
140
|
+
this._engine.scale(this.scale);
|
|
141
|
+
this._engine.rotate(this.rotation);
|
|
142
|
+
this._engine.translate(-this.x + this._shake.x, -this.y + this._shake.y);
|
|
143
|
+
if (clip) {
|
|
144
|
+
this._engine.cliprect(this.x, this.y, this.width, this.height);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
end() {
|
|
148
|
+
this._engine.pop();
|
|
129
149
|
}
|
|
130
150
|
/**
|
|
131
151
|
* @param {number} x
|
|
@@ -176,22 +196,6 @@
|
|
|
176
196
|
shaking() {
|
|
177
197
|
return this._shake.removeListener !== null;
|
|
178
198
|
}
|
|
179
|
-
size(width, height) {
|
|
180
|
-
this.width = width;
|
|
181
|
-
this.height = height;
|
|
182
|
-
}
|
|
183
|
-
start(clip = false) {
|
|
184
|
-
this._engine.push();
|
|
185
|
-
this._engine.translate(-this.x + this._shake.x, -this.y + this._shake.y);
|
|
186
|
-
this._engine.scale(this.scale);
|
|
187
|
-
this._engine.rotate(this.rotation);
|
|
188
|
-
if (clip) {
|
|
189
|
-
this._engine.cliprect(this.x, this.y, this.width, this.height);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
end() {
|
|
193
|
-
this._engine.pop();
|
|
194
|
-
}
|
|
195
199
|
};
|
|
196
200
|
|
|
197
201
|
// src/vector/index.js
|
package/dist/all.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var N=Object.defineProperty;var P=(e,t)=>{for(var s in t)N(e,s,{get:t[s],enumerable:!0})};var T={};P(T,{Camera:()=>a,DOWN:()=>K,LEFT:()=>Q,ONE:()=>B,RIGHT:()=>J,UP:()=>C,Vector:()=>l,ZERO:()=>j,diff:()=>
|
|
1
|
+
(()=>{var N=Object.defineProperty;var P=(e,t)=>{for(var s in t)N(e,s,{get:t[s],enumerable:!0})};var T={};P(T,{Camera:()=>a,DOWN:()=>K,LEFT:()=>Q,ONE:()=>B,RIGHT:()=>J,UP:()=>C,Vector:()=>l,ZERO:()=>j,diff:()=>L,fract:()=>q,intersection:()=>y,isvector:()=>h,resolve:()=>z,vec:()=>i,vecadd:()=>I,vecconfig:()=>k,veccopy:()=>R,veccross:()=>S,vecdir:()=>A,vecdist:()=>$,vecdist2:()=>b,vecdiv:()=>d,vecdot:()=>F,veceq:()=>E,veclerp:()=>U,veclimit:()=>Y,vecmag:()=>D,vecmag2:()=>G,vecmult:()=>M,vecnorm:()=>X,vecrand:()=>Z,vecrot:()=>W,vecset:()=>H,vecsub:()=>O,wave:()=>v});var L=(e,t)=>Math.abs(t-e)||0;var q=e=>e%1||0;var v=(e,t,s,o=Math.sin)=>e+(o(s)+1)/2*(t-e);var y=(e,t,s,o,r,n,x,p)=>{let u=Math.max(e,r),w=Math.min(e+s,r+x)-u,f=Math.max(t,n),g=Math.min(t+o,n+p)-f;return[u,f,w,g]};var z=(e,t,s,o,r,n,x,p)=>{let[u,w,f,g]=y(e,t,s,o,r,n,x,p),c="",m=e,_=t;return f<g?e<r?(c="right",m=r-s):(c="left",m=r+x):t<n?(c="bottom",_=n-o):(c="top",_=n+p),{direction:c,x:m,y:_}};var a=class{_engine=null;x=0;y=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null){t=t||globalThis,this._engine=t,this.size(t.WIDTH||0,t.HEIGHT||0),this.x=this.width/2,this.y=this.height/2}size(t,s){this.width=t,this.height=s}start(t=!1){let s=this.width/2,o=this.height/2;this._engine.push(),this._engine.translate(s,o),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y),t&&this._engine.cliprect(this.x,this.y,this.width,this.height)}end(){this._engine.pop()}lookAt(t,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}shake(t=.3,s=1){this.shaking()||(this._shake.removeListener=this._engine.listen("update",o=>{this._shake.x=this._engine.randi(-s,s),this._shake.y=this._engine.randi(-s,s),t-=o,t<=0&&this.unshake()}))}unshake(){this.shaking()&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}shaking(){return this._shake.removeListener!==null}};var l=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},i=(e=0,t=e)=>new l(e,t),E=(e,t,s=t)=>h(t)?E(e,t.x,t.y):e.x===t&&e.y===(s||t),R=e=>i(e.x,e.y),H=(e,t,s=t)=>{h(t)?H(e,t.x,t.y):(e.x=t,e.y=s)},I=(e,t,s=t)=>{h(t)?I(e,t.x,t.y):(e.x+=t,e.y+=s)},O=(e,t,s=t)=>{h(t)?O(e,t.x,t.y):(e.x-=t,e.y-=s)},M=(e,t,s=t)=>{h(t)?M(e,t.x,t.y):(e.x*=t,e.y*=s)},d=(e,t,s=t)=>{h(t)?d(e,t.x,t.y):(e.x/=t,e.y/=s)},W=(e,t)=>{let s=Math.cos(t),o=Math.sin(t);e.x=s*e.x-o*e.y,e.y=o*e.x+s*e.y},D=e=>Math.sqrt(e.x*e.x+e.y*e.y),G=e=>e.x*e.x+e.y*e.y,X=e=>{let t=D(e);t>0&&d(e,t)},Y=(e,t)=>{let s=G(e);s>t*t&&(d(e,Math.sqrt(s)),M(e,t))},$=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return Math.sqrt(s*s+o*o)},b=(e,t)=>{let s=e.x-t.x,o=e.y-t.y;return s*s+o*o},A=e=>Math.atan2(e.y,e.x),F=(e,t)=>e.x*t.x+e.y*t.y,S=(e,t)=>e.x*t.y-e.y*t.x,U=(e,t,s)=>{e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0},Z=(e=1,t=e)=>{let s=k.random()*2*Math.PI,o=k.random()*(t-e)+e;return i(Math.cos(s)*o,Math.sin(s)*o)},h=e=>e instanceof l,k={random:()=>globalThis.rand?rand():Math.random()},j=i(0,0),B=i(1,1),C=i(0,-1),J=i(1,0),K=i(0,1),Q=i(-1,0);globalThis.utils=T;})();
|
package/dist/camera.js
CHANGED
|
@@ -27,6 +27,26 @@
|
|
|
27
27
|
engine = engine || globalThis;
|
|
28
28
|
this._engine = engine;
|
|
29
29
|
this.size(engine.WIDTH || 0, engine.HEIGHT || 0);
|
|
30
|
+
this.x = this.width / 2;
|
|
31
|
+
this.y = this.height / 2;
|
|
32
|
+
}
|
|
33
|
+
size(width, height) {
|
|
34
|
+
this.width = width;
|
|
35
|
+
this.height = height;
|
|
36
|
+
}
|
|
37
|
+
start(clip = false) {
|
|
38
|
+
const centerX = this.width / 2, centerY = this.height / 2;
|
|
39
|
+
this._engine.push();
|
|
40
|
+
this._engine.translate(centerX, centerY);
|
|
41
|
+
this._engine.scale(this.scale);
|
|
42
|
+
this._engine.rotate(this.rotation);
|
|
43
|
+
this._engine.translate(-this.x + this._shake.x, -this.y + this._shake.y);
|
|
44
|
+
if (clip) {
|
|
45
|
+
this._engine.cliprect(this.x, this.y, this.width, this.height);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
end() {
|
|
49
|
+
this._engine.pop();
|
|
30
50
|
}
|
|
31
51
|
/**
|
|
32
52
|
* @param {number} x
|
|
@@ -77,22 +97,6 @@
|
|
|
77
97
|
shaking() {
|
|
78
98
|
return this._shake.removeListener !== null;
|
|
79
99
|
}
|
|
80
|
-
size(width, height) {
|
|
81
|
-
this.width = width;
|
|
82
|
-
this.height = height;
|
|
83
|
-
}
|
|
84
|
-
start(clip = false) {
|
|
85
|
-
this._engine.push();
|
|
86
|
-
this._engine.translate(-this.x + this._shake.x, -this.y + this._shake.y);
|
|
87
|
-
this._engine.scale(this.scale);
|
|
88
|
-
this._engine.rotate(this.rotation);
|
|
89
|
-
if (clip) {
|
|
90
|
-
this._engine.cliprect(this.x, this.y, this.width, this.height);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
end() {
|
|
94
|
-
this._engine.pop();
|
|
95
|
-
}
|
|
96
100
|
};
|
|
97
101
|
|
|
98
102
|
// src/camera/_web.js
|
package/dist/camera.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var i=class{_engine=null;x=0;y=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(
|
|
1
|
+
(()=>{var i=class{_engine=null;x=0;y=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null){t=t||globalThis,this._engine=t,this.size(t.WIDTH||0,t.HEIGHT||0),this.x=this.width/2,this.y=this.height/2}size(t,s){this.width=t,this.height=s}start(t=!1){let s=this.width/2,h=this.height/2;this._engine.push(),this._engine.translate(s,h),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y),t&&this._engine.cliprect(this.x,this.y,this.width,this.height)}end(){this._engine.pop()}lookAt(t,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}shake(t=.3,s=1){this.shaking()||(this._shake.removeListener=this._engine.listen("update",h=>{this._shake.x=this._engine.randi(-s,s),this._shake.y=this._engine.randi(-s,s),t-=h,t<=0&&this.unshake()}))}unshake(){this.shaking()&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}shaking(){return this._shake.removeListener!==null}};globalThis.utils=Object.assign(globalThis.utils||{},{Camera:i});})();
|
package/package.json
CHANGED
package/src/camera/index.js
CHANGED
|
@@ -29,6 +29,32 @@ export default class Camera {
|
|
|
29
29
|
engine = engine || globalThis
|
|
30
30
|
this._engine = engine
|
|
31
31
|
this.size(engine.WIDTH || 0, engine.HEIGHT || 0)
|
|
32
|
+
this.x = this.width / 2
|
|
33
|
+
this.y = this.height / 2
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
size(width, height) {
|
|
37
|
+
this.width = width
|
|
38
|
+
this.height = height
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
start(clip = false) {
|
|
42
|
+
const centerX = this.width / 2,
|
|
43
|
+
centerY = this.height / 2
|
|
44
|
+
|
|
45
|
+
this._engine.push()
|
|
46
|
+
this._engine.translate(centerX, centerY)
|
|
47
|
+
this._engine.scale(this.scale)
|
|
48
|
+
this._engine.rotate(this.rotation)
|
|
49
|
+
this._engine.translate(-this.x + this._shake.x, -this.y + this._shake.y)
|
|
50
|
+
|
|
51
|
+
if (clip) {
|
|
52
|
+
this._engine.cliprect(this.x, this.y, this.width, this.height)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
end() {
|
|
57
|
+
this._engine.pop()
|
|
32
58
|
}
|
|
33
59
|
|
|
34
60
|
/**
|
|
@@ -89,23 +115,4 @@ export default class Camera {
|
|
|
89
115
|
shaking() {
|
|
90
116
|
return this._shake.removeListener !== null
|
|
91
117
|
}
|
|
92
|
-
|
|
93
|
-
size(width, height) {
|
|
94
|
-
this.width = width
|
|
95
|
-
this.height = height
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
start(clip = false) {
|
|
99
|
-
this._engine.push()
|
|
100
|
-
this._engine.translate(-this.x + this._shake.x, -this.y + this._shake.y)
|
|
101
|
-
this._engine.scale(this.scale)
|
|
102
|
-
this._engine.rotate(this.rotation)
|
|
103
|
-
if (clip) {
|
|
104
|
-
this._engine.cliprect(this.x, this.y, this.width, this.height)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
end() {
|
|
109
|
-
this._engine.pop()
|
|
110
|
-
}
|
|
111
118
|
}
|