@litecanvas/utils 0.12.1 → 0.14.0
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/actor.js +19 -9
- package/dist/actor.min.js +1 -1
- package/dist/all.js +148 -89
- package/dist/all.min.js +3 -2
- package/dist/vector.js +142 -87
- package/dist/vector.min.js +1 -1
- package/package.json +1 -1
- package/src/_web.js +1 -0
- package/src/actor/index.js +9 -9
- package/src/vector/README.md +62 -75
- package/src/vector/index.js +205 -73
package/dist/actor.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// src/vector/index.js
|
|
29
|
+
var PI2 = 2 * Math.PI;
|
|
29
30
|
var Vector = class {
|
|
30
31
|
/** @type {number} */
|
|
31
32
|
x;
|
|
@@ -46,8 +47,17 @@
|
|
|
46
47
|
return `Vector (${this.x}, ${this.y})`;
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
|
-
var
|
|
50
|
-
var
|
|
50
|
+
var isVector = (v) => v instanceof Vector;
|
|
51
|
+
var vec = (x = 0, y = x) => {
|
|
52
|
+
if (isVector(x)) {
|
|
53
|
+
y = x.y;
|
|
54
|
+
x = x.x;
|
|
55
|
+
}
|
|
56
|
+
return new Vector(x, y);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// node_modules/litecanvas/src/zzfx.js
|
|
60
|
+
globalThis.zzfxV = 1;
|
|
51
61
|
|
|
52
62
|
// src/actor/index.js
|
|
53
63
|
var ANCHOR_CENTER = vec(0.5, 0.5);
|
|
@@ -78,7 +88,7 @@
|
|
|
78
88
|
constructor(sprite, position, anchor = ANCHOR_TOP_LEFT) {
|
|
79
89
|
this.sprite = sprite;
|
|
80
90
|
this.pos = position || vec(0);
|
|
81
|
-
this._o =
|
|
91
|
+
this._o = vec(anchor);
|
|
82
92
|
this._s = vec(1, 1);
|
|
83
93
|
}
|
|
84
94
|
/**
|
|
@@ -130,6 +140,12 @@
|
|
|
130
140
|
get height() {
|
|
131
141
|
return this.sprite.height * this._s.y;
|
|
132
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* @retuns {Vector}
|
|
145
|
+
*/
|
|
146
|
+
get scale() {
|
|
147
|
+
return this._s;
|
|
148
|
+
}
|
|
133
149
|
/**
|
|
134
150
|
* @returns {number[]}
|
|
135
151
|
*/
|
|
@@ -140,12 +156,6 @@
|
|
|
140
156
|
const y = this.pos.y - h * this.anchor.y;
|
|
141
157
|
return [x, y, w, h];
|
|
142
158
|
}
|
|
143
|
-
/**
|
|
144
|
-
* @retuns {Vector}
|
|
145
|
-
*/
|
|
146
|
-
get scale() {
|
|
147
|
-
return this._s;
|
|
148
|
-
}
|
|
149
159
|
/**
|
|
150
160
|
* Update the transformation matrix, sets the opacity and draw the actor sprite image.
|
|
151
161
|
*
|
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var p=Object.defineProperty;var u=(e,t)=>{for(var o in t)p(e,o,{get:t[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var a={};u(a,{ANCHOR_BOT_LEFT:()=>x,ANCHOR_BOT_RIGHT:()=>g,ANCHOR_CENTER:()=>d,ANCHOR_TOP_LEFT:()=>c,ANCHOR_TOP_RIGHT:()=>y,Actor:()=>i});var _=2*Math.PI,n=class{x;y;constructor(t=0,o=t){this.x=t,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},h=e=>e instanceof n,r=(e=0,t=e)=>(h(e)&&(t=e.y,e=e.x),new n(e,t));globalThis.zzfxV=1;var d=r(.5,.5),c=r(0,0),y=r(1,0),x=r(0,1),g=r(1,1),i=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,o,s=c){this.sprite=t,this.pos=o||r(0),this._o=r(s),this._s=r(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}getBounds(t=!0){let o=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),l=this.pos.x-o*this.anchor.x,f=this.pos.y-s*this.anchor.y;return[l,f,o,s]}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let o=this.sprite.width*this.anchor.x,s=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-o,-s,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},a);})();
|
package/dist/all.js
CHANGED
|
@@ -36,30 +36,37 @@
|
|
|
36
36
|
diff: () => diff_default,
|
|
37
37
|
fract: () => fract_default,
|
|
38
38
|
intersection: () => intersection_default,
|
|
39
|
-
isvector: () => isvector,
|
|
40
39
|
range: () => range_default,
|
|
41
40
|
resolve: () => resolve_default,
|
|
42
41
|
vec: () => vec,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
vecAbs: () => vecAbs,
|
|
43
|
+
vecAdd: () => vecAdd,
|
|
44
|
+
vecAngle: () => vecAngle,
|
|
45
|
+
vecAngleBetween: () => vecAngleBetween,
|
|
46
|
+
vecCeil: () => vecCeil,
|
|
47
|
+
vecClamp: () => vecClamp,
|
|
48
|
+
vecCross: () => vecCross,
|
|
49
|
+
vecDist: () => vecDist,
|
|
50
|
+
vecDist2: () => vecDist2,
|
|
51
|
+
vecDiv: () => vecDiv,
|
|
52
|
+
vecDot: () => vecDot,
|
|
53
|
+
vecEq: () => vecEq,
|
|
54
|
+
vecFloor: () => vecFloor,
|
|
55
|
+
vecIsZero: () => vecIsZero,
|
|
56
|
+
vecLerp: () => vecLerp,
|
|
57
|
+
vecLimit: () => vecLimit,
|
|
58
|
+
vecMag: () => vecMag,
|
|
59
|
+
vecMag2: () => vecMag2,
|
|
60
|
+
vecMove: () => vecMove,
|
|
61
|
+
vecMult: () => vecMult,
|
|
62
|
+
vecNorm: () => vecNorm,
|
|
63
|
+
vecRand: () => vecRand,
|
|
64
|
+
vecReflect: () => vecReflect,
|
|
65
|
+
vecRotate: () => vecRotate,
|
|
66
|
+
vecRound: () => vecRound,
|
|
67
|
+
vecSet: () => vecSet,
|
|
68
|
+
vecSetMag: () => vecSetMag,
|
|
69
|
+
vecSub: () => vecSub,
|
|
63
70
|
wave: () => wave_default
|
|
64
71
|
});
|
|
65
72
|
|
|
@@ -509,6 +516,10 @@
|
|
|
509
516
|
}
|
|
510
517
|
|
|
511
518
|
// src/vector/index.js
|
|
519
|
+
var sqrt = Math.sqrt;
|
|
520
|
+
var cos = Math.cos;
|
|
521
|
+
var sin = Math.sin;
|
|
522
|
+
var PI2 = 2 * Math.PI;
|
|
512
523
|
var Vector = class {
|
|
513
524
|
/** @type {number} */
|
|
514
525
|
x;
|
|
@@ -529,102 +540,146 @@
|
|
|
529
540
|
return `Vector (${this.x}, ${this.y})`;
|
|
530
541
|
}
|
|
531
542
|
};
|
|
532
|
-
var
|
|
533
|
-
var
|
|
534
|
-
if (
|
|
535
|
-
|
|
543
|
+
var isVector = (v) => v instanceof Vector;
|
|
544
|
+
var vec = (x = 0, y = x) => {
|
|
545
|
+
if (isVector(x)) {
|
|
546
|
+
y = x.y;
|
|
547
|
+
x = x.x;
|
|
548
|
+
}
|
|
549
|
+
return new Vector(x, y);
|
|
550
|
+
};
|
|
551
|
+
var vecEq = (v, x, y = x) => {
|
|
552
|
+
if (isVector(x)) {
|
|
553
|
+
return vecEq(v, x.x, x.y);
|
|
536
554
|
}
|
|
537
555
|
return v.x === x && v.y === y;
|
|
538
556
|
};
|
|
539
|
-
var
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
vecset(v, x.x, x.y);
|
|
557
|
+
var vecSet = (v, x, y = x) => {
|
|
558
|
+
if (isVector(x)) {
|
|
559
|
+
vecSet(v, x.x, x.y);
|
|
543
560
|
} else {
|
|
544
561
|
v.x = x;
|
|
545
562
|
v.y = y;
|
|
546
563
|
}
|
|
564
|
+
return v;
|
|
547
565
|
};
|
|
548
|
-
var
|
|
549
|
-
if (
|
|
550
|
-
|
|
551
|
-
} else {
|
|
552
|
-
v.x += x;
|
|
553
|
-
v.y += y;
|
|
566
|
+
var vecAdd = (v, x, y = x) => {
|
|
567
|
+
if (isVector(x)) {
|
|
568
|
+
return vecAdd(v, x.x, x.y);
|
|
554
569
|
}
|
|
570
|
+
v.x += x;
|
|
571
|
+
v.y += y;
|
|
572
|
+
return v;
|
|
555
573
|
};
|
|
556
|
-
var
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
} else {
|
|
560
|
-
v.x -= x;
|
|
561
|
-
v.y -= y;
|
|
574
|
+
var vecSub = (v, x, y = x) => {
|
|
575
|
+
if (isVector(x)) {
|
|
576
|
+
return vecSub(v, x.x, x.y);
|
|
562
577
|
}
|
|
578
|
+
v.x -= x;
|
|
579
|
+
v.y -= y;
|
|
580
|
+
return v;
|
|
563
581
|
};
|
|
564
|
-
var
|
|
565
|
-
if (
|
|
566
|
-
|
|
567
|
-
} else {
|
|
568
|
-
v.x *= x;
|
|
569
|
-
v.y *= y;
|
|
582
|
+
var vecMult = (v, x, y = x) => {
|
|
583
|
+
if (isVector(x)) {
|
|
584
|
+
return vecMult(v, x.x, x.y);
|
|
570
585
|
}
|
|
586
|
+
v.x *= x;
|
|
587
|
+
v.y *= y;
|
|
588
|
+
return v;
|
|
571
589
|
};
|
|
572
|
-
var
|
|
573
|
-
if (
|
|
574
|
-
|
|
575
|
-
} else {
|
|
576
|
-
v.x /= x;
|
|
577
|
-
v.y /= y;
|
|
590
|
+
var vecDiv = (v, x, y = x) => {
|
|
591
|
+
if (isVector(x)) {
|
|
592
|
+
return vecDiv(v, x.x, x.y);
|
|
578
593
|
}
|
|
594
|
+
v.x /= x;
|
|
595
|
+
v.y /= y;
|
|
596
|
+
return v;
|
|
597
|
+
};
|
|
598
|
+
var vecRotate = (v, radians) => {
|
|
599
|
+
const c = cos(radians), s = sin(radians);
|
|
600
|
+
v.x = c * v.x - s * v.y;
|
|
601
|
+
v.y = s * v.x + c * v.y;
|
|
602
|
+
return v;
|
|
579
603
|
};
|
|
580
|
-
var
|
|
581
|
-
const
|
|
582
|
-
v
|
|
583
|
-
v.y = sin * v.x + cos * v.y;
|
|
604
|
+
var vecReflect = (v, normal) => {
|
|
605
|
+
const normalCopy = vecNorm(vec(normal));
|
|
606
|
+
return vecSub(v, vecMult(normalCopy, 2 * vecDot(v, normalCopy)));
|
|
584
607
|
};
|
|
585
|
-
var
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
608
|
+
var vecSetMag = (v, value) => {
|
|
609
|
+
vecNorm(v);
|
|
610
|
+
vecMult(v, value);
|
|
611
|
+
return v;
|
|
612
|
+
};
|
|
613
|
+
var vecMag = (v) => sqrt(v.x * v.x + v.y * v.y);
|
|
614
|
+
var vecMag2 = (v) => v.x * v.x + v.y * v.y;
|
|
615
|
+
var vecNorm = (v) => {
|
|
616
|
+
const length = vecMag(v);
|
|
589
617
|
if (length > 0) {
|
|
590
|
-
|
|
618
|
+
vecDiv(v, length);
|
|
591
619
|
}
|
|
620
|
+
return v;
|
|
592
621
|
};
|
|
593
|
-
var
|
|
594
|
-
const sq =
|
|
622
|
+
var vecLimit = (v, max = 1) => {
|
|
623
|
+
const sq = vecMag2(v);
|
|
595
624
|
if (sq > max * max) {
|
|
596
|
-
|
|
597
|
-
|
|
625
|
+
vecDiv(v, sqrt(sq));
|
|
626
|
+
vecMult(v, max);
|
|
598
627
|
}
|
|
628
|
+
return v;
|
|
599
629
|
};
|
|
600
|
-
var
|
|
630
|
+
var vecDist = (a, b) => {
|
|
601
631
|
const dx = a.x - b.x;
|
|
602
632
|
const dy = a.y - b.y;
|
|
603
|
-
return
|
|
633
|
+
return sqrt(dx * dx + dy * dy);
|
|
604
634
|
};
|
|
605
|
-
var
|
|
635
|
+
var vecDist2 = (a, b) => {
|
|
606
636
|
const dx = a.x - b.x;
|
|
607
637
|
const dy = a.y - b.y;
|
|
608
638
|
return dx * dx + dy * dy;
|
|
609
639
|
};
|
|
610
|
-
var
|
|
611
|
-
var
|
|
612
|
-
var
|
|
613
|
-
var
|
|
640
|
+
var vecAngle = (v) => Math.atan2(v.y, v.x);
|
|
641
|
+
var vecAngleBetween = (v1, v2) => Math.atan2(v2.y - v1.y, v2.x - v1.x);
|
|
642
|
+
var vecDot = (a, b) => a.x * b.x + a.y * b.y;
|
|
643
|
+
var vecCross = (a, b) => a.x * b.y - a.y * b.x;
|
|
644
|
+
var vecLerp = (a, b, t) => {
|
|
614
645
|
a.x += (b.x - a.x) * t || 0;
|
|
615
646
|
a.y += (b.y - a.y) * t || 0;
|
|
647
|
+
return a;
|
|
616
648
|
};
|
|
617
|
-
var
|
|
618
|
-
const angle =
|
|
619
|
-
const radius =
|
|
620
|
-
return vec(
|
|
649
|
+
var vecRand = (minlength = 1, maxlength = minlength, randomFn = globalThis.rand || Math.random) => {
|
|
650
|
+
const angle = randomFn() * PI2;
|
|
651
|
+
const radius = randomFn() * (maxlength - minlength) + minlength;
|
|
652
|
+
return vec(cos(angle) * radius, sin(angle) * radius);
|
|
621
653
|
};
|
|
622
|
-
var
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
654
|
+
var vecAbs = (v) => {
|
|
655
|
+
v.x = Math.abs(v.x);
|
|
656
|
+
v.y = Math.abs(v.y);
|
|
657
|
+
return v;
|
|
658
|
+
};
|
|
659
|
+
var vecCeil = (v) => {
|
|
660
|
+
v.x = Math.ceil(v.x);
|
|
661
|
+
v.y = Math.ceil(v.y);
|
|
662
|
+
return v;
|
|
663
|
+
};
|
|
664
|
+
var vecFloor = (v) => {
|
|
665
|
+
v.x = Math.floor(v.x);
|
|
666
|
+
v.y = Math.floor(v.y);
|
|
667
|
+
return v;
|
|
668
|
+
};
|
|
669
|
+
var vecRound = (v) => {
|
|
670
|
+
v.x = Math.round(v.x);
|
|
671
|
+
v.y = Math.round(v.y);
|
|
672
|
+
return v;
|
|
673
|
+
};
|
|
674
|
+
var vecClamp = (v, min, max) => {
|
|
675
|
+
if (v.x < min.x) v.x = min.x;
|
|
676
|
+
if (v.x > max.x) v.x = max.x;
|
|
677
|
+
if (v.y < min.y) v.y = min.y;
|
|
678
|
+
if (v.y > max.y) v.y = max.y;
|
|
679
|
+
return v;
|
|
627
680
|
};
|
|
681
|
+
var vecMove = (v, to, delta = 1) => vecAdd(v, to.x * delta, to.y * delta);
|
|
682
|
+
var vecIsZero = (v) => vecEq(v, ZERO);
|
|
628
683
|
var ZERO = /* @__PURE__ */ vec(0, 0);
|
|
629
684
|
var ONE = /* @__PURE__ */ vec(1, 1);
|
|
630
685
|
var UP = /* @__PURE__ */ vec(0, -1);
|
|
@@ -632,6 +687,9 @@
|
|
|
632
687
|
var DOWN = /* @__PURE__ */ vec(0, 1);
|
|
633
688
|
var LEFT = /* @__PURE__ */ vec(-1, 0);
|
|
634
689
|
|
|
690
|
+
// node_modules/litecanvas/src/zzfx.js
|
|
691
|
+
globalThis.zzfxV = 1;
|
|
692
|
+
|
|
635
693
|
// src/actor/index.js
|
|
636
694
|
var ANCHOR_CENTER = vec(0.5, 0.5);
|
|
637
695
|
var ANCHOR_TOP_LEFT = vec(0, 0);
|
|
@@ -661,7 +719,7 @@
|
|
|
661
719
|
constructor(sprite, position, anchor = ANCHOR_TOP_LEFT) {
|
|
662
720
|
this.sprite = sprite;
|
|
663
721
|
this.pos = position || vec(0);
|
|
664
|
-
this._o =
|
|
722
|
+
this._o = vec(anchor);
|
|
665
723
|
this._s = vec(1, 1);
|
|
666
724
|
}
|
|
667
725
|
/**
|
|
@@ -713,6 +771,12 @@
|
|
|
713
771
|
get height() {
|
|
714
772
|
return this.sprite.height * this._s.y;
|
|
715
773
|
}
|
|
774
|
+
/**
|
|
775
|
+
* @retuns {Vector}
|
|
776
|
+
*/
|
|
777
|
+
get scale() {
|
|
778
|
+
return this._s;
|
|
779
|
+
}
|
|
716
780
|
/**
|
|
717
781
|
* @returns {number[]}
|
|
718
782
|
*/
|
|
@@ -723,12 +787,6 @@
|
|
|
723
787
|
const y = this.pos.y - h * this.anchor.y;
|
|
724
788
|
return [x, y, w, h];
|
|
725
789
|
}
|
|
726
|
-
/**
|
|
727
|
-
* @retuns {Vector}
|
|
728
|
-
*/
|
|
729
|
-
get scale() {
|
|
730
|
-
return this._s;
|
|
731
|
-
}
|
|
732
790
|
/**
|
|
733
791
|
* Update the transformation matrix, sets the opacity and draw the actor sprite image.
|
|
734
792
|
*
|
|
@@ -775,3 +833,4 @@
|
|
|
775
833
|
// src/_web.js
|
|
776
834
|
globalThis.utils = Object.assign(globalThis.utils || {}, src_exports);
|
|
777
835
|
})();
|
|
836
|
+
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|
package/dist/all.min.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`)}},
|
|
1
|
+
(()=>{var U=Object.defineProperty;var $=(e,t)=>{for(var s in t)U(e,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var k={};$(k,{ANCHOR_BOT_LEFT:()=>mt,ANCHOR_BOT_RIGHT:()=>Tt,ANCHOR_CENTER:()=>yt,ANCHOR_TOP_LEFT:()=>F,ANCHOR_TOP_RIGHT:()=>_t,Actor:()=>D,Camera:()=>u,DOWN:()=>xt,Grid:()=>y,LEFT:()=>gt,ONE:()=>ut,RIGHT:()=>dt,TypedGrid:()=>E,UP:()=>pt,Vector:()=>p,ZERO:()=>B,diff:()=>G,fract:()=>j,intersection:()=>g,range:()=>z,resolve:()=>S,vec:()=>n,vecAbs:()=>rt,vecAdd:()=>b,vecAngle:()=>tt,vecAngleBetween:()=>et,vecCeil:()=>nt,vecClamp:()=>ct,vecCross:()=>st,vecDist:()=>Q,vecDist2:()=>v,vecDiv:()=>_,vecDot:()=>W,vecEq:()=>H,vecFloor:()=>at,vecIsZero:()=>ft,vecLerp:()=>it,vecLimit:()=>K,vecMag:()=>R,vecMag2:()=>Y,vecMove:()=>lt,vecMult:()=>d,vecNorm:()=>A,vecRand:()=>ot,vecReflect:()=>Z,vecRotate:()=>q,vecRound:()=>ht,vecSet:()=>P,vecSetMag:()=>J,vecSub:()=>I,wave:()=>V});var g=(e,t,s,i,o,r,a,h)=>{let c=Math.max(e,o),C=Math.min(e+s,o+a)-c,x=Math.max(t,r),m=Math.min(t+i,r+h)-x;return[c,x,C,m]};var S=(e,t,s,i,o,r,a,h)=>{let[c,C,x,m]=g(e,t,s,i,o,r,a,h),f="",T=e,w=t;return x<m?e<o?(f="right",T=o-s):(f="left",T=o+a):t<r?(f="bottom",w=r-i):(f="top",w=r+h),{direction:f,x:T,y:w}};var u=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,s=0,i=0,o=null,r=null){this._engine=t||globalThis,this.ox=s,this.oy=i,this.resize(o||this._engine.WIDTH-s,r||this._engine.HEIGHT-i),this.x=this.width/2,this.y=this.height/2}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.cliprect(this.ox,this.oy,this.width,this.height);let s=this.ox+this.width/2,i=this.oy+this.height/2;this._engine.translate(s,i),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}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}getWorldPoint(t,s,i={}){let o=Math.cos(-this.rotation),r=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,i.x=o*t-r*s+this.x,i.y=r*t+o*s+this.y,i}getCameraPoint(t,s,i={}){let o=Math.cos(-this.rotation),r=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=o*t-r*s,s=r*t+o*s,i.x=t*this.scale+this.width/2+this.ox,i.y=s*this.scale+this.height/2+this.oy,i}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,s,i,o){let r=this.width/2-this.x,a=this.height/2-this.y,h=this.width/this.scale,c=this.height/this.scale;return this._engine.colrect(t,s,i,o,r,a,h,c)}shake(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",i=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),s-=i,s<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var y=class e{_w;_h;_c;constructor(t,s,i=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=i}clear(){this.forEach((t,s)=>this.set(t,s,void 0))}get width(){return this._w}get height(){return this._h}set(t,s,i){this._c[this.pointToIndex(t,s)]=i}get(t,s){return this._c[this.pointToIndex(t,s)]}has(t,s){return this.get(t,s)!=null}get length(){return this._w*this._h}pointToIndex(t,s){return this.clampX(~~t)+this.clampY(~~s)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,s=!1){let i=s?this.length-1:0,o=s?-1:this.length,r=s?-1:1;for(;i!==o;){let a=this.indexToPointX(i),h=this.indexToPointY(i),c=this._c[i];if(t(a,h,c,this)===!1)break;i+=r}}fill(t){this.forEach((s,i)=>{this.set(s,i,t)})}clone(){return e.fromArray(this._w,this._h,this._c)}clampX(t){return O(t,0,this._w-1)}clampY(t){return O(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let i=[];return this.forEach((o,r,a)=>{i[r]=i[r]||"",i[r]+=a+t}),i.join(`
|
|
2
|
+
`)}},E=class e extends y{constructor(t,s,i=Uint8Array){super(t,s,null),this._c=new i(this._w*this._h)}has(t,s){return this.get(t,s)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((s,i,o)=>{t.set(s,i,o)}),t}};function O(e,t,s){return e<t?t:e>s?s:e}var M=Math.sqrt,X=Math.cos,L=Math.sin,N=2*Math.PI,p=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},l=e=>e instanceof p,n=(e=0,t=e)=>(l(e)&&(t=e.y,e=e.x),new p(e,t)),H=(e,t,s=t)=>l(t)?H(e,t.x,t.y):e.x===t&&e.y===s,P=(e,t,s=t)=>(l(t)?P(e,t.x,t.y):(e.x=t,e.y=s),e),b=(e,t,s=t)=>l(t)?b(e,t.x,t.y):(e.x+=t,e.y+=s,e),I=(e,t,s=t)=>l(t)?I(e,t.x,t.y):(e.x-=t,e.y-=s,e),d=(e,t,s=t)=>l(t)?d(e,t.x,t.y):(e.x*=t,e.y*=s,e),_=(e,t,s=t)=>l(t)?_(e,t.x,t.y):(e.x/=t,e.y/=s,e),q=(e,t)=>{let s=X(t),i=L(t);return e.x=s*e.x-i*e.y,e.y=i*e.x+s*e.y,e},Z=(e,t)=>{let s=A(n(t));return I(e,d(s,2*W(e,s)))},J=(e,t)=>(A(e),d(e,t),e),R=e=>M(e.x*e.x+e.y*e.y),Y=e=>e.x*e.x+e.y*e.y,A=e=>{let t=R(e);return t>0&&_(e,t),e},K=(e,t=1)=>{let s=Y(e);return s>t*t&&(_(e,M(s)),d(e,t)),e},Q=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return M(s*s+i*i)},v=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return s*s+i*i},tt=e=>Math.atan2(e.y,e.x),et=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),W=(e,t)=>e.x*t.x+e.y*t.y,st=(e,t)=>e.x*t.y-e.y*t.x,it=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),ot=(e=1,t=e,s=globalThis.rand||Math.random)=>{let i=s()*N,o=s()*(t-e)+e;return n(X(i)*o,L(i)*o)},rt=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),nt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),at=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),ht=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),ct=(e,t,s)=>(e.x<t.x&&(e.x=t.x),e.x>s.x&&(e.x=s.x),e.y<t.y&&(e.y=t.y),e.y>s.y&&(e.y=s.y),e),lt=(e,t,s=1)=>b(e,t.x*s,t.y*s),ft=e=>H(e,B),B=n(0,0),ut=n(1,1),pt=n(0,-1),dt=n(1,0),xt=n(0,1),gt=n(-1,0);globalThis.zzfxV=1;var yt=n(.5,.5),F=n(0,0),_t=n(1,0),mt=n(0,1),Tt=n(1,1),D=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,s,i=F){this.sprite=t,this.pos=s||n(0),this._o=n(i),this._s=n(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),i=this.sprite.height*(t?this._s.y:1),o=this.pos.x-s*this.anchor.x,r=this.pos.y-i*this.anchor.y;return[o,r,s,i]}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let s=this.sprite.width*this.anchor.x,i=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-s,-i,this.sprite)}};var G=(e,t)=>Math.abs(t-e)||0;var V=(e,t,s,i=Math.sin)=>e+(i(s)+1)/2*(t-e);var j=e=>e%1||0;var z=e=>Array.from(Array(e).keys());globalThis.utils=Object.assign(globalThis.utils||{},k);})();
|
|
3
|
+
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */
|