jigsawpuzzlegame 1.0.5 → 1.0.6
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/jigsaw-puzzle-game.js +20 -2
- package/package.json +1 -1
package/jigsaw-puzzle-game.js
CHANGED
|
@@ -394,6 +394,7 @@ class PolyPiece {
|
|
|
394
394
|
this.canvas.classList.add("polypiece");
|
|
395
395
|
this.ctx = this.canvas.getContext("2d");
|
|
396
396
|
this.rot = 0;
|
|
397
|
+
this.rotationDegrees = 0; // Cumulative rotation in degrees for smooth animation
|
|
397
398
|
}
|
|
398
399
|
|
|
399
400
|
merge(otherPoly) {
|
|
@@ -723,7 +724,7 @@ class PolyPiece {
|
|
|
723
724
|
this.ctx.stroke(path);
|
|
724
725
|
|
|
725
726
|
this.ctx.restore();
|
|
726
|
-
this.canvas.style.transform = `rotate(${
|
|
727
|
+
this.canvas.style.transform = `rotate(${this.rotationDegrees}deg)`;
|
|
727
728
|
});
|
|
728
729
|
}
|
|
729
730
|
|
|
@@ -743,7 +744,20 @@ class PolyPiece {
|
|
|
743
744
|
}
|
|
744
745
|
|
|
745
746
|
rotate(angle) {
|
|
747
|
+
// Calculate the change in rotation
|
|
748
|
+
const oldRot = this.rot;
|
|
746
749
|
this.rot = angle;
|
|
750
|
+
|
|
751
|
+
// Always rotate forward (add 90 degrees for each increment)
|
|
752
|
+
// If we're wrapping from 3 to 0, we need to go 270->360 instead of 270->0
|
|
753
|
+
if (this.rot === 0 && oldRot === 3) {
|
|
754
|
+
// Going from 270° (rot=3) to 0° (rot=0), add 90° to go to 360°
|
|
755
|
+
this.rotationDegrees += 90;
|
|
756
|
+
} else {
|
|
757
|
+
// Normal case: calculate the difference and add it
|
|
758
|
+
const diff = this.rot - oldRot;
|
|
759
|
+
this.rotationDegrees += diff * 90;
|
|
760
|
+
}
|
|
747
761
|
}
|
|
748
762
|
|
|
749
763
|
isPointInPath(p) {
|
|
@@ -902,7 +916,10 @@ class InternalPuzzle {
|
|
|
902
916
|
);
|
|
903
917
|
arrayShuffle(this.polyPieces);
|
|
904
918
|
if (this.rotationAllowed)
|
|
905
|
-
this.polyPieces.forEach((pp) =>
|
|
919
|
+
this.polyPieces.forEach((pp) => {
|
|
920
|
+
pp.rot = intAlea(4);
|
|
921
|
+
pp.rotationDegrees = pp.rot * 90;
|
|
922
|
+
});
|
|
906
923
|
} else {
|
|
907
924
|
const pps = baseData[8];
|
|
908
925
|
const offs = this.rotationAllowed ? 3 : 2;
|
|
@@ -911,6 +928,7 @@ class InternalPuzzle {
|
|
|
911
928
|
polyp.x = ppData[0];
|
|
912
929
|
polyp.y = ppData[1];
|
|
913
930
|
polyp.rot = this.rotationAllowed ? ppData[2] : 0;
|
|
931
|
+
polyp.rotationDegrees = polyp.rot * 90;
|
|
914
932
|
for (let k = offs + 2; k < ppData.length; k += 2) {
|
|
915
933
|
let kx = ppData[k];
|
|
916
934
|
let ky = ppData[k + 1];
|