Skip to content

Commit 0e58a85

Browse files
committed
v1.1.1: fix serializing chain with loop
1 parent b4d7ffa commit 0e58a85

15 files changed

+43
-39
lines changed

dist/planck-with-testbed.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.planck = {}));
33
})(this, function(exports2) {
44
"use strict";/**
5-
* Planck.js v1.1.0
5+
* Planck.js v1.1.1
66
* @license The MIT license
77
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
88
*
@@ -6782,7 +6782,7 @@
67826782
ChainShape2.prototype._serialize = function() {
67836783
var data = {
67846784
type: this.m_type,
6785-
vertices: this.m_vertices,
6785+
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
67866786
isLoop: this.m_isLoop,
67876787
hasPrevVertex: this.m_hasPrevVertex,
67886788
hasNextVertex: this.m_hasNextVertex,
@@ -6844,19 +6844,20 @@
68446844
vertices[i - 1];
68456845
vertices[i];
68466846
}
6847+
this.m_vertices = [];
68476848
this.m_count = vertices.length;
68486849
for (var i = 0; i < vertices.length; ++i) {
68496850
this.m_vertices[i] = Vec2.clone(vertices[i]);
68506851
}
6851-
this.m_hasPrevVertex = false;
6852-
this.m_hasNextVertex = false;
68536852
this.m_prevVertex = null;
68546853
this.m_nextVertex = null;
6854+
this.m_hasPrevVertex = false;
6855+
this.m_hasNextVertex = false;
68556856
return this;
68566857
};
68576858
ChainShape2.prototype._reset = function() {
68586859
if (this.m_isLoop) {
6859-
this._createLoop(this.m_vertices);
6860+
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
68606861
} else {
68616862
this._createChain(this.m_vertices);
68626863
}

dist/planck-with-testbed.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck-with-testbed.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck-with-testbed.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck-with-testbed.mjs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Planck.js v1.1.0
2+
* Planck.js v1.1.1
33
* @license The MIT license
44
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
55
*
@@ -6778,7 +6778,7 @@ var ChainShape = (
67786778
ChainShape2.prototype._serialize = function() {
67796779
var data = {
67806780
type: this.m_type,
6781-
vertices: this.m_vertices,
6781+
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
67826782
isLoop: this.m_isLoop,
67836783
hasPrevVertex: this.m_hasPrevVertex,
67846784
hasNextVertex: this.m_hasNextVertex,
@@ -6840,19 +6840,20 @@ var ChainShape = (
68406840
vertices[i - 1];
68416841
vertices[i];
68426842
}
6843+
this.m_vertices = [];
68436844
this.m_count = vertices.length;
68446845
for (var i = 0; i < vertices.length; ++i) {
68456846
this.m_vertices[i] = Vec2.clone(vertices[i]);
68466847
}
6847-
this.m_hasPrevVertex = false;
6848-
this.m_hasNextVertex = false;
68496848
this.m_prevVertex = null;
68506849
this.m_nextVertex = null;
6850+
this.m_hasPrevVertex = false;
6851+
this.m_hasNextVertex = false;
68516852
return this;
68526853
};
68536854
ChainShape2.prototype._reset = function() {
68546855
if (this.m_isLoop) {
6855-
this._createLoop(this.m_vertices);
6856+
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
68566857
} else {
68576858
this._createChain(this.m_vertices);
68586859
}

dist/planck-with-testbed.mjs.map

+1-1
Large diffs are not rendered by default.

dist/planck.js

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.mjs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Planck.js v1.1.0
2+
* Planck.js v1.1.1
33
* @license The MIT license
44
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
55
*
@@ -6778,7 +6778,7 @@ var ChainShape = (
67786778
ChainShape2.prototype._serialize = function() {
67796779
var data = {
67806780
type: this.m_type,
6781-
vertices: this.m_vertices,
6781+
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
67826782
isLoop: this.m_isLoop,
67836783
hasPrevVertex: this.m_hasPrevVertex,
67846784
hasNextVertex: this.m_hasNextVertex,
@@ -6840,19 +6840,20 @@ var ChainShape = (
68406840
vertices[i - 1];
68416841
vertices[i];
68426842
}
6843+
this.m_vertices = [];
68436844
this.m_count = vertices.length;
68446845
for (var i = 0; i < vertices.length; ++i) {
68456846
this.m_vertices[i] = Vec2.clone(vertices[i]);
68466847
}
6847-
this.m_hasPrevVertex = false;
6848-
this.m_hasNextVertex = false;
68496848
this.m_prevVertex = null;
68506849
this.m_nextVertex = null;
6850+
this.m_hasPrevVertex = false;
6851+
this.m_hasNextVertex = false;
68516852
return this;
68526853
};
68536854
ChainShape2.prototype._reset = function() {
68546855
if (this.m_isLoop) {
6855-
this._createLoop(this.m_vertices);
6856+
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
68566857
} else {
68576858
this._createChain(this.m_vertices);
68586859
}

dist/planck.mjs.map

+1-1
Large diffs are not rendered by default.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "planck",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "2D JavaScript/TypeScript physics engine for cross-platform HTML5 game development",
55
"homepage": "https://github.com/piqnt/planck.js",
66
"keywords": [

src/collision/shape/ChainShape.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class ChainShape extends Shape {
8686
_serialize(): object {
8787
const data = {
8888
type: this.m_type,
89-
vertices: this.m_vertices,
89+
vertices: this.m_isLoop ? this.m_vertices.slice(0, this.m_vertices.length - 1) : this.m_vertices,
9090
isLoop: this.m_isLoop,
9191
hasPrevVertex: this.m_hasPrevVertex,
9292
hasNextVertex: this.m_hasNextVertex,
@@ -138,7 +138,6 @@ export class ChainShape extends Shape {
138138
* Create a loop. This automatically adjusts connectivity.
139139
*
140140
* @param vertices an array of vertices, these are copied
141-
* @param count the vertex count
142141
*/
143142
_createLoop(vertices: Vec2Value[]): ChainShape {
144143
_ASSERT && console.assert(this.m_vertices.length == 0 && this.m_count == 0);
@@ -178,28 +177,29 @@ export class ChainShape extends Shape {
178177
_ASSERT && console.assert(this.m_vertices.length == 0 && this.m_count == 0);
179178
_ASSERT && console.assert(vertices.length >= 2);
180179
for (let i = 1; i < vertices.length; ++i) {
181-
// If the code crashes here, it means your vertices are too close together.
182180
const v1 = vertices[i - 1];
183181
const v2 = vertices[i];
182+
// If the code crashes here, it means your vertices are too close together.
184183
_ASSERT && console.assert(Vec2.distanceSquared(v1, v2) > Settings.linearSlopSquared);
185184
}
186185

186+
this.m_vertices = [];
187187
this.m_count = vertices.length;
188188
for (let i = 0; i < vertices.length; ++i) {
189189
this.m_vertices[i] = Vec2.clone(vertices[i]);
190190
}
191191

192-
this.m_hasPrevVertex = false;
193-
this.m_hasNextVertex = false;
194192
this.m_prevVertex = null;
195193
this.m_nextVertex = null;
194+
this.m_hasPrevVertex = false;
195+
this.m_hasNextVertex = false;
196196
return this;
197197
}
198198

199199
/** @hidden */
200200
_reset(): void {
201201
if (this.m_isLoop) {
202-
this._createLoop(this.m_vertices);
202+
this._createLoop(this.m_vertices.slice(0, this.m_vertices.length - 1));
203203
} else {
204204
this._createChain(this.m_vertices);
205205
}

0 commit comments

Comments
 (0)