Skip to content

Commit

Permalink
refactor testbed api
Browse files Browse the repository at this point in the history
  • Loading branch information
shakiba committed Aug 20, 2023
1 parent ce047fa commit a42764e
Show file tree
Hide file tree
Showing 93 changed files with 16,562 additions and 16,244 deletions.
4,186 changes: 2,087 additions & 2,099 deletions dist/planck-with-testbed.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck-with-testbed.d.ts.map

Large diffs are not rendered by default.

10,932 changes: 5,496 additions & 5,436 deletions dist/planck-with-testbed.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck-with-testbed.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/planck-with-testbed.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck-with-testbed.min.js.map

Large diffs are not rendered by default.

10,930 changes: 5,495 additions & 5,435 deletions dist/planck-with-testbed.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck-with-testbed.mjs.map

Large diffs are not rendered by default.

4,136 changes: 2,129 additions & 2,007 deletions dist/planck.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck.d.ts.map

Large diffs are not rendered by default.

113 changes: 110 additions & 3 deletions dist/planck.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Planck.js v1.0.0-beta.9
* Planck.js v1.0.0-beta.10
* @license The MIT license
* @copyright Copyright (c) 2021 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -14873,6 +14873,109 @@
Serializer.toJson = serializer.toJson;
Serializer.fromJson = serializer.fromJson;

var Testbed = /** @class */ (function () {
function Testbed() {
/** World viewbox width. */
this.width = 80;
/** World viewbox height. */
this.height = 60;
/** World viewbox center vertical offset. */
this.x = 0;
/** World viewbox center horizontal offset. */
this.y = -10;
this.scaleY = -1;
/** World simulation step frequency */
this.hz = 60;
/** World simulation speed, default is 1 */
this.speed = 1;
this.ratio = 16;
this.background = '#222222';
this.activeKeys = {};
/** callback, to be implemented by user */
this.step = function (dt, t) {
return;
};
/** callback, to be implemented by user */
this.keydown = function (keyCode, label) {
return;
};
/** callback, to be implemented by user */
this.keyup = function (keyCode, label) {
return;
};
this.statusText = '';
this.statusMap = {};
}
Testbed.mount = function (options) {
throw new Error('Not implemented');
};
Testbed.prototype.status = function (a, b) {
if (typeof b !== 'undefined') {
var key_1 = a;
var value_1 = b;
if (typeof value_1 !== 'function' && typeof value_1 !== 'object') {
this.statusMap[key_1] = value_1;
}
}
else if (a && typeof a === 'object') {
// tslint:disable-next-line:no-for-in
for (var key_2 in a) {
var value_2 = a[key_2];
if (typeof value_2 !== 'function' && typeof value_2 !== 'object') {
this.statusMap[key_2] = value_2;
}
}
}
else if (typeof a === 'string') {
this.statusText = a;
}
var newline = '\n';
var text = this.statusText || '';
for (var key in this.statusMap) {
var value = this.statusMap[key];
if (typeof value === 'function')
continue;
text += (text && newline) + key + ': ' + value;
}
this._status(text);
};
Testbed.prototype.info = function (text) {
this._info(text);
};
Testbed.prototype.color = function (r, g, b) {
r = r * 256 | 0;
g = g * 256 | 0;
b = b * 256 | 0;
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
};
return Testbed;
}());
/** @internal */
function testbed(a, b) {
var callback;
var options;
if (typeof a === 'function') {
callback = a;
options = b;
}
else if (typeof b === 'function') {
callback = b;
options = a;
}
else {
options = a !== null && a !== void 0 ? a : b;
}
var testbed = Testbed.mount(options);
if (callback) {
// this is for backwards compatibility
var world = callback(testbed) || testbed.world;
testbed.start(world);
}
else {
return testbed;
}
}

/*
* Planck.js
* The MIT License
Expand Down Expand Up @@ -15854,9 +15957,10 @@

var planck = /*#__PURE__*/Object.freeze({
__proto__: null,
internal: internal,
Math: math,
Serializer: Serializer,
Testbed: Testbed,
testbed: testbed,
Vec2: Vec2,
Vec3: Vec3,
Mat22: Mat22,
Expand Down Expand Up @@ -15931,7 +16035,8 @@
TimeOfImpact: TimeOfImpact,
TreeNode: TreeNode,
DynamicTree: DynamicTree,
stats: stats
stats: stats,
internal: internal
});

exports.AABB = AABB;
Expand Down Expand Up @@ -15991,6 +16096,7 @@
exports.Sweep = Sweep;
exports.TOIInput = TOIInput;
exports.TOIOutput = TOIOutput;
exports.Testbed = Testbed;
exports.TimeOfImpact = TimeOfImpact;
exports.Transform = Transform;
exports.TreeNode = TreeNode;
Expand All @@ -16009,6 +16115,7 @@
exports.mixRestitution = mixRestitution;
exports.stats = stats;
exports.testOverlap = testOverlap;
exports.testbed = testbed;

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

Expand Down
2 changes: 1 addition & 1 deletion dist/planck.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/planck.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/planck.min.js.map

Large diffs are not rendered by default.

113 changes: 109 additions & 4 deletions dist/planck.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Planck.js v1.0.0-beta.9
* Planck.js v1.0.0-beta.10
* @license The MIT license
* @copyright Copyright (c) 2021 Erin Catto, Ali Shakiba
*
Expand Down Expand Up @@ -14867,6 +14867,109 @@ var serializer = new Serializer();
Serializer.toJson = serializer.toJson;
Serializer.fromJson = serializer.fromJson;

var Testbed = /** @class */ (function () {
function Testbed() {
/** World viewbox width. */
this.width = 80;
/** World viewbox height. */
this.height = 60;
/** World viewbox center vertical offset. */
this.x = 0;
/** World viewbox center horizontal offset. */
this.y = -10;
this.scaleY = -1;
/** World simulation step frequency */
this.hz = 60;
/** World simulation speed, default is 1 */
this.speed = 1;
this.ratio = 16;
this.background = '#222222';
this.activeKeys = {};
/** callback, to be implemented by user */
this.step = function (dt, t) {
return;
};
/** callback, to be implemented by user */
this.keydown = function (keyCode, label) {
return;
};
/** callback, to be implemented by user */
this.keyup = function (keyCode, label) {
return;
};
this.statusText = '';
this.statusMap = {};
}
Testbed.mount = function (options) {
throw new Error('Not implemented');
};
Testbed.prototype.status = function (a, b) {
if (typeof b !== 'undefined') {
var key_1 = a;
var value_1 = b;
if (typeof value_1 !== 'function' && typeof value_1 !== 'object') {
this.statusMap[key_1] = value_1;
}
}
else if (a && typeof a === 'object') {
// tslint:disable-next-line:no-for-in
for (var key_2 in a) {
var value_2 = a[key_2];
if (typeof value_2 !== 'function' && typeof value_2 !== 'object') {
this.statusMap[key_2] = value_2;
}
}
}
else if (typeof a === 'string') {
this.statusText = a;
}
var newline = '\n';
var text = this.statusText || '';
for (var key in this.statusMap) {
var value = this.statusMap[key];
if (typeof value === 'function')
continue;
text += (text && newline) + key + ': ' + value;
}
this._status(text);
};
Testbed.prototype.info = function (text) {
this._info(text);
};
Testbed.prototype.color = function (r, g, b) {
r = r * 256 | 0;
g = g * 256 | 0;
b = b * 256 | 0;
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
};
return Testbed;
}());
/** @internal */
function testbed(a, b) {
var callback;
var options;
if (typeof a === 'function') {
callback = a;
options = b;
}
else if (typeof b === 'function') {
callback = b;
options = a;
}
else {
options = a !== null && a !== void 0 ? a : b;
}
var testbed = Testbed.mount(options);
if (callback) {
// this is for backwards compatibility
var world = callback(testbed) || testbed.world;
testbed.start(world);
}
else {
return testbed;
}
}

/*
* Planck.js
* The MIT License
Expand Down Expand Up @@ -15848,9 +15951,10 @@ var internal = {

var planck = /*#__PURE__*/Object.freeze({
__proto__: null,
internal: internal,
Math: math,
Serializer: Serializer,
Testbed: Testbed,
testbed: testbed,
Vec2: Vec2,
Vec3: Vec3,
Mat22: Mat22,
Expand Down Expand Up @@ -15925,8 +16029,9 @@ var planck = /*#__PURE__*/Object.freeze({
TimeOfImpact: TimeOfImpact,
TreeNode: TreeNode,
DynamicTree: DynamicTree,
stats: stats
stats: stats,
internal: internal
});

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 };
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 };
//# sourceMappingURL=planck.mjs.map
2 changes: 1 addition & 1 deletion dist/planck.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/8-Ball.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Vec2, World, Circle, Settings, Polygon } = planck;
const { Vec2, World, Circle, Settings, Polygon, Testbed } = planck;

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

Expand Down Expand Up @@ -31,7 +31,7 @@ Settings.velocityThreshold = 0;

let world = new World();

const testbed = planck.testbed();
const testbed = Testbed.mount();
testbed.x = 0;
testbed.y = 0;
testbed.width = width * 1.2;
Expand Down
4 changes: 2 additions & 2 deletions example/AddPair.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* SOFTWARE.
*/

const { Vec2, World, Circle, Box, Math } = planck;
const { Vec2, World, Circle, Box, Math, Testbed } = planck;

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

const testbed = planck.testbed();
const testbed = Testbed.mount();
testbed.y = 0;
testbed.hz = 60;
testbed.speed = 1;
Expand Down
4 changes: 2 additions & 2 deletions example/ApplyForce.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* SOFTWARE.
*/

const { Vec2, Transform, Polygon, Box, FrictionJoint, World, Edge } = planck;
const { Vec2, Transform, Polygon, Box, FrictionJoint, World, Edge, Testbed } = planck;

let world = new World();

const testbed = planck.testbed();
const testbed = Testbed.mount();
testbed.y = -20;
testbed.start(world);

Expand Down
4 changes: 2 additions & 2 deletions example/Asteroid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { World, Vec2, Circle, Polygon } = planck;
const { World, Vec2, Circle, Polygon, Testbed } = planck;

let SHIP = 2;
let BULLET = 4;
Expand All @@ -24,7 +24,7 @@ let allowFireTime = 0;

let world = new World();

const testbed = planck.testbed();
const testbed = Testbed.mount();
testbed.width = SPACE_WIDTH;
testbed.height = SPACE_HEIGHT;
testbed.step = tick;
Expand Down
4 changes: 2 additions & 2 deletions example/BasicSliderCrank.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

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

const { Vec2, World, Box, RevoluteJoint, PrismaticJoint } = planck;
const { Vec2, World, Box, RevoluteJoint, PrismaticJoint, Testbed } = planck;

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

const testbed = planck.testbed();
const testbed = Testbed.mount();
testbed.y = -15;
testbed.start(world);

Expand Down
4 changes: 2 additions & 2 deletions example/BodyTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* SOFTWARE.
*/

const { Vec2, World, Edge, Box, RevoluteJoint, PrismaticJoint } = planck;
const { Vec2, World, Edge, Box, RevoluteJoint, PrismaticJoint, Testbed } = planck;

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

const testbed = planck.testbed();
const testbed = Testbed.mount();
testbed.info('Z: Dynamic, X: Static, C: Kinematic');
testbed.start(world);

Expand Down
4 changes: 2 additions & 2 deletions example/Boxes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { Vec2, World, Edge, Box } = planck;
const { Vec2, World, Edge, Box, Testbed } = planck;

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

const testbed = planck.testbed();
const testbed = Testbed.mount();
testbed.start(world);

let bar = world.createBody();
Expand Down
Loading

0 comments on commit a42764e

Please sign in to comment.