Skip to content

Commit

Permalink
fix: make block images work in all contexts (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfunko authored Apr 19, 2024
1 parent fafed65 commit 920febf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions blocks_vertical/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Blockly.Blocks['control_forever'] = {
* @this Blockly.Block
*/
init: function() {
const ws = this.workspace.options.parentWorkspace || this.workspace;
this.jsonInit({
"id": "control_forever",
"message0": Blockly.Msg.CONTROL_FOREVER,
Expand All @@ -44,7 +45,7 @@ Blockly.Blocks['control_forever'] = {
"args2": [
{
"type": "field_image",
"src": Blockly.getMainWorkspace().options.pathToMedia + "repeat.svg",
"src": ws.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
Expand All @@ -64,6 +65,7 @@ Blockly.Blocks['control_repeat'] = {
* @this Blockly.Block
*/
init: function() {
const ws = this.workspace.options.parentWorkspace || this.workspace;
this.jsonInit({
"id": "control_repeat",
"message0": Blockly.Msg.CONTROL_REPEAT,
Expand All @@ -85,7 +87,7 @@ Blockly.Blocks['control_repeat'] = {
"args2": [
{
"type": "field_image",
"src": Blockly.getMainWorkspace().options.pathToMedia + "repeat.svg",
"src": ws.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
Expand Down Expand Up @@ -267,6 +269,7 @@ Blockly.Blocks['control_repeat_until'] = {
* @this Blockly.Block
*/
init: function() {
const ws = this.workspace.options.parentWorkspace || this.workspace;
this.jsonInit({
"message0": Blockly.Msg.CONTROL_REPEATUNTIL,
"message1": "%1",
Expand All @@ -288,7 +291,7 @@ Blockly.Blocks['control_repeat_until'] = {
"args2": [
{
"type": "field_image",
"src": Blockly.getMainWorkspace().options.pathToMedia + "repeat.svg",
"src": ws.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
Expand All @@ -307,6 +310,7 @@ Blockly.Blocks['control_while'] = {
* (This is an obsolete "hacked" block, for compatibility with 2.0.)
*/
init: function() {
const ws = this.workspace.options.parentWorkspace || this.workspace;
this.jsonInit({
"message0": Blockly.Msg.CONTROL_WHILE,
"message1": "%1",
Expand All @@ -328,7 +332,7 @@ Blockly.Blocks['control_while'] = {
"args2": [
{
"type": "field_image",
"src": Blockly.getMainWorkspace().options.pathToMedia + "repeat.svg",
"src": ws.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
Expand Down
3 changes: 2 additions & 1 deletion blocks_vertical/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ Blockly.Blocks['event_whenflagclicked'] = {
* @this Blockly.Block
*/
init: function() {
const ws = this.workspace.options.parentWorkspace || this.workspace;
this.jsonInit({
"id": "event_whenflagclicked",
"message0": Blockly.Msg.EVENT_WHENFLAGCLICKED,
"args0": [
{
"type": "field_image",
"src": Blockly.getMainWorkspace().options.pathToMedia + "green-flag.svg",
"src": ws.options.pathToMedia + "green-flag.svg",
"width": 24,
"height": 24,
"alt": "flag"
Expand Down
6 changes: 4 additions & 2 deletions blocks_vertical/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ Blockly.Blocks['motion_turnright'] = {
* @this Blockly.Block
*/
init: function() {
const ws = this.workspace.options.parentWorkspace || this.workspace;
this.jsonInit({
"message0": Blockly.Msg.MOTION_TURNRIGHT,
"args0": [
{
"type": "field_image",
"src": Blockly.getMainWorkspace().options.pathToMedia + "rotate-right.svg",
"src": ws.options.pathToMedia + "rotate-right.svg",
"width": 24,
"height": 24
},
Expand All @@ -74,12 +75,13 @@ Blockly.Blocks['motion_turnleft'] = {
* @this Blockly.Block
*/
init: function() {
const ws = this.workspace.options.parentWorkspace || this.workspace;
this.jsonInit({
"message0": Blockly.Msg.MOTION_TURNLEFT,
"args0": [
{
"type": "field_image",
"src": Blockly.getMainWorkspace().options.pathToMedia + "rotate-left.svg",
"src": ws.options.pathToMedia + "rotate-left.svg",
"width": 24,
"height": 24
},
Expand Down
2 changes: 2 additions & 0 deletions blocks_vertical/vertical_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ VerticalExtensions.colourHelper = function(category) {
* @this {Blockly.Block}
*/
return function() {
this.setColour(colours.primary);
// this.setColourFromRawValues_(colours.primary, colours.secondary,
// colours.tertiary, colours.quaternary);
};
Expand All @@ -58,6 +59,7 @@ VerticalExtensions.colourHelper = function(category) {
* Extension to set the colours of a text field, which are all the same.
*/
VerticalExtensions.COLOUR_TEXTFIELD = function() {
this.setColour(colours.textField);
// this.setColourFromRawValues_(Colours.textField,
// Colours.textField, Colours.textField,
// Colours.textField);
Expand Down

0 comments on commit 920febf

Please sign in to comment.