Skip to content

Commit a971fb7

Browse files
committed
refactor testbed api
1 parent ce047fa commit a971fb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+16562
-16244
lines changed

dist/planck-with-testbed.d.ts

+2,087-2,099
Large diffs are not rendered by default.

dist/planck-with-testbed.d.ts.map

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

dist/planck-with-testbed.js

+5,496-5,436
Large diffs are not rendered by default.

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

+5,495-5,435
Large diffs are not rendered by default.

dist/planck-with-testbed.mjs.map

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

dist/planck.d.ts

+2,129-2,007
Large diffs are not rendered by default.

dist/planck.d.ts.map

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

dist/planck.js

+110-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Planck.js v1.0.0-beta.9
2+
* Planck.js v1.0.0-beta.10
33
* @license The MIT license
44
* @copyright Copyright (c) 2021 Erin Catto, Ali Shakiba
55
*
@@ -14873,6 +14873,109 @@
1487314873
Serializer.toJson = serializer.toJson;
1487414874
Serializer.fromJson = serializer.fromJson;
1487514875

14876+
var Testbed = /** @class */ (function () {
14877+
function Testbed() {
14878+
/** World viewbox width. */
14879+
this.width = 80;
14880+
/** World viewbox height. */
14881+
this.height = 60;
14882+
/** World viewbox center vertical offset. */
14883+
this.x = 0;
14884+
/** World viewbox center horizontal offset. */
14885+
this.y = -10;
14886+
this.scaleY = -1;
14887+
/** World simulation step frequency */
14888+
this.hz = 60;
14889+
/** World simulation speed, default is 1 */
14890+
this.speed = 1;
14891+
this.ratio = 16;
14892+
this.background = '#222222';
14893+
this.activeKeys = {};
14894+
/** callback, to be implemented by user */
14895+
this.step = function (dt, t) {
14896+
return;
14897+
};
14898+
/** callback, to be implemented by user */
14899+
this.keydown = function (keyCode, label) {
14900+
return;
14901+
};
14902+
/** callback, to be implemented by user */
14903+
this.keyup = function (keyCode, label) {
14904+
return;
14905+
};
14906+
this.statusText = '';
14907+
this.statusMap = {};
14908+
}
14909+
Testbed.mount = function (options) {
14910+
throw new Error('Not implemented');
14911+
};
14912+
Testbed.prototype.status = function (a, b) {
14913+
if (typeof b !== 'undefined') {
14914+
var key_1 = a;
14915+
var value_1 = b;
14916+
if (typeof value_1 !== 'function' && typeof value_1 !== 'object') {
14917+
this.statusMap[key_1] = value_1;
14918+
}
14919+
}
14920+
else if (a && typeof a === 'object') {
14921+
// tslint:disable-next-line:no-for-in
14922+
for (var key_2 in a) {
14923+
var value_2 = a[key_2];
14924+
if (typeof value_2 !== 'function' && typeof value_2 !== 'object') {
14925+
this.statusMap[key_2] = value_2;
14926+
}
14927+
}
14928+
}
14929+
else if (typeof a === 'string') {
14930+
this.statusText = a;
14931+
}
14932+
var newline = '\n';
14933+
var text = this.statusText || '';
14934+
for (var key in this.statusMap) {
14935+
var value = this.statusMap[key];
14936+
if (typeof value === 'function')
14937+
continue;
14938+
text += (text && newline) + key + ': ' + value;
14939+
}
14940+
this._status(text);
14941+
};
14942+
Testbed.prototype.info = function (text) {
14943+
this._info(text);
14944+
};
14945+
Testbed.prototype.color = function (r, g, b) {
14946+
r = r * 256 | 0;
14947+
g = g * 256 | 0;
14948+
b = b * 256 | 0;
14949+
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
14950+
};
14951+
return Testbed;
14952+
}());
14953+
/** @internal */
14954+
function testbed(a, b) {
14955+
var callback;
14956+
var options;
14957+
if (typeof a === 'function') {
14958+
callback = a;
14959+
options = b;
14960+
}
14961+
else if (typeof b === 'function') {
14962+
callback = b;
14963+
options = a;
14964+
}
14965+
else {
14966+
options = a !== null && a !== void 0 ? a : b;
14967+
}
14968+
var testbed = Testbed.mount(options);
14969+
if (callback) {
14970+
// this is for backwards compatibility
14971+
var world = callback(testbed) || testbed.world;
14972+
testbed.start(world);
14973+
}
14974+
else {
14975+
return testbed;
14976+
}
14977+
}
14978+
1487614979
/*
1487714980
* Planck.js
1487814981
* The MIT License
@@ -15854,9 +15957,10 @@
1585415957

1585515958
var planck = /*#__PURE__*/Object.freeze({
1585615959
__proto__: null,
15857-
internal: internal,
1585815960
Math: math,
1585915961
Serializer: Serializer,
15962+
Testbed: Testbed,
15963+
testbed: testbed,
1586015964
Vec2: Vec2,
1586115965
Vec3: Vec3,
1586215966
Mat22: Mat22,
@@ -15931,7 +16035,8 @@
1593116035
TimeOfImpact: TimeOfImpact,
1593216036
TreeNode: TreeNode,
1593316037
DynamicTree: DynamicTree,
15934-
stats: stats
16038+
stats: stats,
16039+
internal: internal
1593516040
});
1593616041

1593716042
exports.AABB = AABB;
@@ -15991,6 +16096,7 @@
1599116096
exports.Sweep = Sweep;
1599216097
exports.TOIInput = TOIInput;
1599316098
exports.TOIOutput = TOIOutput;
16099+
exports.Testbed = Testbed;
1599416100
exports.TimeOfImpact = TimeOfImpact;
1599516101
exports.Transform = Transform;
1599616102
exports.TreeNode = TreeNode;
@@ -16009,6 +16115,7 @@
1600916115
exports.mixRestitution = mixRestitution;
1601016116
exports.stats = stats;
1601116117
exports.testOverlap = testOverlap;
16118+
exports.testbed = testbed;
1601216119

1601316120
Object.defineProperty(exports, '__esModule', { value: true });
1601416121

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

+109-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Planck.js v1.0.0-beta.9
2+
* Planck.js v1.0.0-beta.10
33
* @license The MIT license
44
* @copyright Copyright (c) 2021 Erin Catto, Ali Shakiba
55
*
@@ -14867,6 +14867,109 @@ var serializer = new Serializer();
1486714867
Serializer.toJson = serializer.toJson;
1486814868
Serializer.fromJson = serializer.fromJson;
1486914869

14870+
var Testbed = /** @class */ (function () {
14871+
function Testbed() {
14872+
/** World viewbox width. */
14873+
this.width = 80;
14874+
/** World viewbox height. */
14875+
this.height = 60;
14876+
/** World viewbox center vertical offset. */
14877+
this.x = 0;
14878+
/** World viewbox center horizontal offset. */
14879+
this.y = -10;
14880+
this.scaleY = -1;
14881+
/** World simulation step frequency */
14882+
this.hz = 60;
14883+
/** World simulation speed, default is 1 */
14884+
this.speed = 1;
14885+
this.ratio = 16;
14886+
this.background = '#222222';
14887+
this.activeKeys = {};
14888+
/** callback, to be implemented by user */
14889+
this.step = function (dt, t) {
14890+
return;
14891+
};
14892+
/** callback, to be implemented by user */
14893+
this.keydown = function (keyCode, label) {
14894+
return;
14895+
};
14896+
/** callback, to be implemented by user */
14897+
this.keyup = function (keyCode, label) {
14898+
return;
14899+
};
14900+
this.statusText = '';
14901+
this.statusMap = {};
14902+
}
14903+
Testbed.mount = function (options) {
14904+
throw new Error('Not implemented');
14905+
};
14906+
Testbed.prototype.status = function (a, b) {
14907+
if (typeof b !== 'undefined') {
14908+
var key_1 = a;
14909+
var value_1 = b;
14910+
if (typeof value_1 !== 'function' && typeof value_1 !== 'object') {
14911+
this.statusMap[key_1] = value_1;
14912+
}
14913+
}
14914+
else if (a && typeof a === 'object') {
14915+
// tslint:disable-next-line:no-for-in
14916+
for (var key_2 in a) {
14917+
var value_2 = a[key_2];
14918+
if (typeof value_2 !== 'function' && typeof value_2 !== 'object') {
14919+
this.statusMap[key_2] = value_2;
14920+
}
14921+
}
14922+
}
14923+
else if (typeof a === 'string') {
14924+
this.statusText = a;
14925+
}
14926+
var newline = '\n';
14927+
var text = this.statusText || '';
14928+
for (var key in this.statusMap) {
14929+
var value = this.statusMap[key];
14930+
if (typeof value === 'function')
14931+
continue;
14932+
text += (text && newline) + key + ': ' + value;
14933+
}
14934+
this._status(text);
14935+
};
14936+
Testbed.prototype.info = function (text) {
14937+
this._info(text);
14938+
};
14939+
Testbed.prototype.color = function (r, g, b) {
14940+
r = r * 256 | 0;
14941+
g = g * 256 | 0;
14942+
b = b * 256 | 0;
14943+
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
14944+
};
14945+
return Testbed;
14946+
}());
14947+
/** @internal */
14948+
function testbed(a, b) {
14949+
var callback;
14950+
var options;
14951+
if (typeof a === 'function') {
14952+
callback = a;
14953+
options = b;
14954+
}
14955+
else if (typeof b === 'function') {
14956+
callback = b;
14957+
options = a;
14958+
}
14959+
else {
14960+
options = a !== null && a !== void 0 ? a : b;
14961+
}
14962+
var testbed = Testbed.mount(options);
14963+
if (callback) {
14964+
// this is for backwards compatibility
14965+
var world = callback(testbed) || testbed.world;
14966+
testbed.start(world);
14967+
}
14968+
else {
14969+
return testbed;
14970+
}
14971+
}
14972+
1487014973
/*
1487114974
* Planck.js
1487214975
* The MIT License
@@ -15848,9 +15951,10 @@ var internal = {
1584815951

1584915952
var planck = /*#__PURE__*/Object.freeze({
1585015953
__proto__: null,
15851-
internal: internal,
1585215954
Math: math,
1585315955
Serializer: Serializer,
15956+
Testbed: Testbed,
15957+
testbed: testbed,
1585415958
Vec2: Vec2,
1585515959
Vec3: Vec3,
1585615960
Mat22: Mat22,
@@ -15925,8 +16029,9 @@ var planck = /*#__PURE__*/Object.freeze({
1592516029
TimeOfImpact: TimeOfImpact,
1592616030
TreeNode: TreeNode,
1592716031
DynamicTree: DynamicTree,
15928-
stats: stats
16032+
stats: stats,
16033+
internal: internal
1592916034
});
1593016035

15931-
export { AABB, Body, Box, BoxShape, Chain, ChainShape, Circle, CircleShape, ClipVertex, CollideCircles, CollideEdgeCircle, CollideEdgePolygon, CollidePolygonCircle, CollidePolygons, Contact, ContactEdge, ContactFeatureType, ContactID, Distance, DistanceInput, DistanceJoint, DistanceOutput, DistanceProxy, DynamicTree, Edge, EdgeShape, Fixture, FixtureProxy, FrictionJoint, GearJoint, Joint, JointEdge, Manifold, ManifoldPoint, ManifoldType, MassData, Mat22, Mat33, math as Math, MotorJoint, MouseJoint, PointState, Polygon, PolygonShape, PrismaticJoint, PulleyJoint, RevoluteJoint, RopeJoint, Rot, Serializer, Settings, SettingsInternal, Shape, ShapeCast, ShapeCastInput, ShapeCastOutput, SimplexCache, Sweep, TOIInput, TOIOutput, TOIOutputState, TimeOfImpact, Transform, TreeNode, Vec2, Vec3, VelocityConstraintPoint, WeldJoint, WheelJoint, World, WorldManifold, clipSegmentToLine, planck as default, getPointStates, internal, mixFriction, mixRestitution, stats, testOverlap };
16036+
export { AABB, Body, Box, BoxShape, Chain, ChainShape, Circle, CircleShape, ClipVertex, CollideCircles, CollideEdgeCircle, CollideEdgePolygon, CollidePolygonCircle, CollidePolygons, Contact, ContactEdge, ContactFeatureType, ContactID, Distance, DistanceInput, DistanceJoint, DistanceOutput, DistanceProxy, DynamicTree, Edge, EdgeShape, Fixture, FixtureProxy, FrictionJoint, GearJoint, Joint, JointEdge, Manifold, ManifoldPoint, ManifoldType, MassData, Mat22, Mat33, math as Math, MotorJoint, MouseJoint, PointState, Polygon, PolygonShape, PrismaticJoint, PulleyJoint, RevoluteJoint, RopeJoint, Rot, Serializer, Settings, SettingsInternal, Shape, ShapeCast, ShapeCastInput, ShapeCastOutput, SimplexCache, Sweep, TOIInput, TOIOutput, TOIOutputState, Testbed, TimeOfImpact, Transform, TreeNode, Vec2, Vec3, VelocityConstraintPoint, WeldJoint, WheelJoint, World, WorldManifold, clipSegmentToLine, planck as default, getPointStates, internal, mixFriction, mixRestitution, stats, testOverlap, testbed };
1593216037
//# sourceMappingURL=planck.mjs.map

dist/planck.mjs.map

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

example/8-Ball.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Vec2, World, Circle, Settings, Polygon } = planck;
1+
const { Vec2, World, Circle, Settings, Polygon, Testbed } = planck;
22

33
let SPI4 = Math.sin(Math.PI / 4), SPI3 = Math.sin(Math.PI / 3);
44

@@ -31,7 +31,7 @@ Settings.velocityThreshold = 0;
3131

3232
let world = new World();
3333

34-
const testbed = planck.testbed();
34+
const testbed = Testbed.mount();
3535
testbed.x = 0;
3636
testbed.y = 0;
3737
testbed.width = width * 1.2;

example/AddPair.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
* SOFTWARE.
2222
*/
2323

24-
const { Vec2, World, Circle, Box, Math } = planck;
24+
const { Vec2, World, Circle, Box, Math, Testbed } = planck;
2525

2626
let world = new World(new Vec2(0, 0));
2727

28-
const testbed = planck.testbed();
28+
const testbed = Testbed.mount();
2929
testbed.y = 0;
3030
testbed.hz = 60;
3131
testbed.speed = 1;

example/ApplyForce.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
* SOFTWARE.
2222
*/
2323

24-
const { Vec2, Transform, Polygon, Box, FrictionJoint, World, Edge } = planck;
24+
const { Vec2, Transform, Polygon, Box, FrictionJoint, World, Edge, Testbed } = planck;
2525

2626
let world = new World();
2727

28-
const testbed = planck.testbed();
28+
const testbed = Testbed.mount();
2929
testbed.y = -20;
3030
testbed.start(world);
3131

example/Asteroid.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { World, Vec2, Circle, Polygon } = planck;
1+
const { World, Vec2, Circle, Polygon, Testbed } = planck;
22

33
let SHIP = 2;
44
let BULLET = 4;
@@ -24,7 +24,7 @@ let allowFireTime = 0;
2424

2525
let world = new World();
2626

27-
const testbed = planck.testbed();
27+
const testbed = Testbed.mount();
2828
testbed.width = SPACE_WIDTH;
2929
testbed.height = SPACE_HEIGHT;
3030
testbed.step = tick;

example/BasicSliderCrank.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
// A basic slider crank created for GDC tutorial: Understanding Constraints
2525

26-
const { Vec2, World, Box, RevoluteJoint, PrismaticJoint } = planck;
26+
const { Vec2, World, Box, RevoluteJoint, PrismaticJoint, Testbed } = planck;
2727

2828
let world = new World(new Vec2(0, -10));
2929

30-
const testbed = planck.testbed();
30+
const testbed = Testbed.mount();
3131
testbed.y = -15;
3232
testbed.start(world);
3333

example/BodyTypes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
* SOFTWARE.
2222
*/
2323

24-
const { Vec2, World, Edge, Box, RevoluteJoint, PrismaticJoint } = planck;
24+
const { Vec2, World, Edge, Box, RevoluteJoint, PrismaticJoint, Testbed } = planck;
2525

2626
let world = new World(new Vec2(0, -10));
2727

28-
const testbed = planck.testbed();
28+
const testbed = Testbed.mount();
2929
testbed.info('Z: Dynamic, X: Static, C: Kinematic');
3030
testbed.start(world);
3131

example/Boxes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { Vec2, World, Edge, Box } = planck;
1+
const { Vec2, World, Edge, Box, Testbed } = planck;
22

33
let world = new World(new Vec2(0, -10));
44

5-
const testbed = planck.testbed();
5+
const testbed = Testbed.mount();
66
testbed.start(world);
77

88
let bar = world.createBody();

0 commit comments

Comments
 (0)