Skip to content

Commit

Permalink
Fix collision detection
Browse files Browse the repository at this point in the history
  • Loading branch information
vikdoro authored and Paul Varache committed Jul 31, 2017
1 parent 5f414ad commit 57bc7be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
17 changes: 8 additions & 9 deletions app/scripts/kano/make-apps/blockly/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,20 @@
this.setColour(COLOR);
},
getFirstPartOptions: function () {
let options = Blockly.Blocks.collision_event.getParts()
.map(this.formatPartOption);
let parts = Blockly.Blocks.collision_event.getParts() || [],
options = parts.map(this.formatPartOption);

if (!options.length) {
options.push(['', 'null']);
options.push(['No available part', '']);
}

return options;
},
getSecondPartOptions: function () {
let options = Blockly.Blocks.collision_event.getParts()
.filter(part => {
let parts = Blockly.Blocks.collision_event.getParts() || [],
options = parts.filter(part => {
return `parts.get('${part.id}')` !== this.getFieldValue('PART1');
})
.map(this.formatPartOption);
}).map(this.formatPartOption);

// The @ here is to make sure no part id will collide with this name
options.push(['Top Edge', "'@top-edge'"]);
Expand Down Expand Up @@ -131,15 +130,15 @@
let part1Id = block.getFieldValue('PART1'),
part2Id = block.getFieldValue('PART2'),
statement = Blockly.JavaScript.statementToCode(block, 'DO'),
code = `parts.whenCollisionBetween(${part1Id}, ${part2Id}, function () {\n${statement}});\n`;
code = `parts.whenCollisionBetween(${part1Id ? part1Id : null}, ${part2Id}, function () {\n${statement}});\n`;
return code;
};

Blockly.Pseudo.collision_event = (block) => {
let part1Id = block.getFieldValue('PART1'),
part2Id = block.getFieldValue('PART2'),
statement = Blockly.Pseudo.statementToCode(block, 'DO'),
code = `parts.whenCollisionBetween(${part1Id}, ${part2Id}, function () {\n${statement}});\n`;
code = `parts.whenCollisionBetween(${part1Id ? part1Id : null}, ${part2Id}, function () {\n${statement}});\n`;
return code;
};

Expand Down
15 changes: 7 additions & 8 deletions app/scripts/kano/make-apps/blockly/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,20 @@
this.setColour(COLOR);
},
getFirstPartOptions: function () {
let options = Blockly.Blocks.collision_event.getParts()
.map(this.formatPartOption);
let parts = Blockly.Blocks.collision_event.getParts() || [],
options = parts.map(this.formatPartOption);

if (!options.length) {
options.push(['No available part', null]);
options.push(['No available part', '']);
}

return options;
},
getSecondPartOptions: function () {
let options = Blockly.Blocks.collision_event.getParts()
.filter(part => {
let parts = Blockly.Blocks.collision_event.getParts() || [],
options = parts.filter(part => {
return part.id !== this.getFieldValue('PART1');
})
.map(this.formatPartOption);
}).map(this.formatPartOption);

// The @ here is to make sure no part id will collide with this name
options.push(['Top Edge', "'@top-edge'"]);
Expand All @@ -198,7 +197,7 @@
Blockly.JavaScript.if_collides = (block) => {
let part1Id = block.getFieldValue('PART1'),
part2Id = block.getFieldValue('PART2'),
code = `parts.collisionBetween(${part1Id}, ${part2Id})`;
code = `parts.collisionBetween(${part1Id ? part1Id : null}, ${part2Id})`;
return [code];
};

Expand Down

0 comments on commit 57bc7be

Please sign in to comment.