Converted code to ES5

This commit is contained in:
Andreas Loew 2018-06-04 22:44:36 +02:00
parent 6c58bd9029
commit fea754f1f9

View file

@ -17,19 +17,22 @@ var PhysicsEditorLoader = {
loadBody: function (x, y, w, h, config) loadBody: function (x, y, w, h, config)
{ {
const fixtureConfigs = GetFastValue(config, 'fixtures', []); var fixtureConfigs = GetFastValue(config, 'fixtures', []);
const fixtures = []; var fixtures = [];
for (let fixtureConfig of fixtureConfigs) for (var fc = 0; fc < fixtureConfigs.length; fc++)
{ {
const f = this.loadFixture(fixtureConfig); var fixtureParts = this.loadFixture(fixtureConfigs[fc]);
fixtures.push(...f); for(var i = 0; i < fixtureParts.length; i++)
{
fixtures.push(fixtureParts[i]);
}
} }
var matterConfig = Common.extend({}, false, config); var matterConfig = Common.extend({}, false, config);
delete matterConfig.fixtures; delete matterConfig.fixtures;
delete matterConfig.type; delete matterConfig.type;
const body = Body.create(matterConfig); var body = Body.create(matterConfig);
Body.setParts(body, fixtures); Body.setParts(body, fixtures);
body.render.sprite.xOffset = body.position.x / w; body.render.sprite.xOffset = body.position.x / w;
body.render.sprite.yOffset = body.position.y / h; body.render.sprite.yOffset = body.position.y / h;
@ -45,12 +48,12 @@ var PhysicsEditorLoader = {
delete matterConfig.circle; delete matterConfig.circle;
delete matterConfig.vertices; delete matterConfig.vertices;
let fixtures; var fixtures;
if (fixtureConfig.circle) if (fixtureConfig.circle)
{ {
const x = GetFastValue(fixtureConfig.circle, 'x'); var x = GetFastValue(fixtureConfig.circle, 'x');
const y = GetFastValue(fixtureConfig.circle, 'y'); var y = GetFastValue(fixtureConfig.circle, 'y');
const r = GetFastValue(fixtureConfig.circle, 'radius'); var r = GetFastValue(fixtureConfig.circle, 'radius');
fixtures = [ Bodies.circle(x, y, r, matterConfig) ]; fixtures = [ Bodies.circle(x, y, r, matterConfig) ];
} }
else if (fixtureConfig.vertices) else if (fixtureConfig.vertices)