Skip to content

Commit

Permalink
Copy number block into Bird instead of entire math
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Sep 22, 2022
1 parent 1282c87 commit 7e45400
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions appengine/bird/src/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ goog.provide('Bird.Blocks');

goog.require('Blockly');
goog.require('Blockly.Constants.Logic');
goog.require('Blockly.Constants.Math');
goog.require('Blockly.Extensions');
goog.require('Blockly.FieldAngle');
goog.require('Blockly.FieldDropdown');
goog.require('Blockly.FieldNumber');
goog.require('Blockly.JavaScript');
goog.require('Blockly.JavaScript.logic');
goog.require('Blockly.JavaScript.math');
goog.require('BlocklyGames');


Expand Down Expand Up @@ -155,6 +154,22 @@ Bird.Blocks.init = function() {
"tooltip": "%{BKY_CONTROLS_IF_TOOLTIP_2}",
"helpUrl": "%{BKY_CONTROLS_IF_HELPURL}",
},

// Block for numeric value.
{
"type": "math_number",
"message0": "%1",
"args0": [{
"type": "field_number",
"name": "NUM",
"value": 0
}],
"output": "Number",
"helpUrl": "%{BKY_MATH_NUMBER_HELPURL}",
"colour": "%{BKY_MATH_HUE}",
"tooltip": "%{BKY_MATH_NUMBER_TOOLTIP}",
"extensions": ["parent_tooltip_when_inline"]
},
]);

Blockly.Extensions.register('bird_compare_tooltip',
Expand Down Expand Up @@ -236,3 +251,11 @@ Blockly.Blocks['controls_if'].init = function() {
this.setPreviousStatement(false);
this.setNextStatement(false);
};

Blockly.JavaScript['math_number'] = function(block) {
// Numeric value.
var code = Number(block.getFieldValue('NUM'));
var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC :
Blockly.JavaScript.ORDER_UNARY_NEGATION;
return [code, order];
};
2 changes: 1 addition & 1 deletion appengine/music/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function registerSounds() {
const instances = this['_soundInstances'][src];
this['_audioSources'][src] = result;

if (instances && instances.length > 0) {
if (instances) {
for (const instance of instances) {
instance['playbackResource'] = result;
}
Expand Down

0 comments on commit 7e45400

Please sign in to comment.