Skip to content

Commit

Permalink
fix: readd the event blocks (#21)
Browse files Browse the repository at this point in the history
* fix: readd the event blocks

* fix: only import core Blockly
  • Loading branch information
gonfunko authored Apr 17, 2024
1 parent 79398c2 commit 4de530f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
45 changes: 19 additions & 26 deletions blocks_vertical/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@
* limitations under the License.
*/

'use strict';

goog.provide('Blockly.Blocks.event');

goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
import * as Blockly from 'blockly/core';
import {Categories} from '../src/categories.js';
import * as Constants from '../src/constants.js';

Blockly.Blocks['event_whentouchingobject'] = {
/**
Expand All @@ -41,7 +36,7 @@ Blockly.Blocks['event_whentouchingobject'] = {
"name": "TOUCHINGOBJECTMENU"
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand Down Expand Up @@ -82,13 +77,13 @@ Blockly.Blocks['event_whenflagclicked'] = {
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "green-flag.svg",
"src": Blockly.getMainWorkspace().options.pathToMedia + "green-flag.svg",
"width": 24,
"height": 24,
"alt": "flag"
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand All @@ -102,7 +97,7 @@ Blockly.Blocks['event_whenthisspriteclicked'] = {
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENTHISSPRITECLICKED,
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand All @@ -117,7 +112,7 @@ Blockly.Blocks['event_whenstageclicked'] = {
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENSTAGECLICKED,
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand All @@ -136,11 +131,12 @@ Blockly.Blocks['event_whenbroadcastreceived'] = {
{
"type": "field_variable",
"name": "BROADCAST_OPTION",
"variableTypes": [Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
"variableTypes": [Constants.BROADCAST_MESSAGE_VARIABLE_TYPE],
"defaultType": Constants.BROADCAST_MESSAGE_VARIABLE_TYPE,
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand All @@ -163,7 +159,7 @@ Blockly.Blocks['event_whenbackdropswitchesto'] = {
]
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand Down Expand Up @@ -191,7 +187,7 @@ Blockly.Blocks['event_whengreaterthan'] = {
"name": "VALUE"
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand All @@ -209,15 +205,12 @@ Blockly.Blocks['event_broadcast_menu'] = {
{
"type": "field_variable",
"name": "BROADCAST_OPTION",
"variableTypes":[Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
"variableTypes": [Constants.BROADCAST_MESSAGE_VARIABLE_TYPE],
"defaultType": Constants.BROADCAST_MESSAGE_VARIABLE_TYPE,
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
}
],
"colour": Blockly.Colours.event.secondary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary,
"colourQuaternary": Blockly.Colours.event.quaternary,
"extensions": ["output_string"]
"extensions": ["colours_event", "output_string"]
});
}
};
Expand All @@ -237,7 +230,7 @@ Blockly.Blocks['event_broadcast'] = {
"name": "BROADCAST_INPUT"
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_statement"]
});
}
Expand All @@ -257,7 +250,7 @@ Blockly.Blocks['event_broadcastandwait'] = {
"name":"BROADCAST_INPUT"
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_statement"]
});
}
Expand Down Expand Up @@ -322,7 +315,7 @@ Blockly.Blocks['event_whenkeypressed'] = {
]
}
],
"category": Blockly.Categories.event,
"category": Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
Expand Down
9 changes: 9 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* String representing the variable type of broadcast message blocks.
* This string, for use in differentiating between types of variables,
* indicates that the current variable is a broadcast message.
* @const {string}
*/
const BROADCAST_MESSAGE_VARIABLE_TYPE = 'broadcast_msg';

export {BROADCAST_MESSAGE_VARIABLE_TYPE};
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import '../blocks_common/math.js';
import '../blocks_vertical/vertical_extensions.js';
import '../blocks_vertical/event.js';
import '../blocks_vertical/motion.js';
import '../blocks_vertical/operators.js';

Expand Down

0 comments on commit 4de530f

Please sign in to comment.