From f4625cdb6f4ea80f435abb7b259b0c35785d048d Mon Sep 17 00:00:00 2001 From: Erik Pasternak Date: Wed, 28 May 2025 09:09:52 -0700 Subject: [PATCH 1/3] Add a button block for testing --- test/blocks/p5_blocks.js | 69 ++++++++++++++++++++++++++++++++++++++++ test/blocks/toolbox.js | 4 +++ 2 files changed, 73 insertions(+) diff --git a/test/blocks/p5_blocks.js b/test/blocks/p5_blocks.js index 83654f74..eda65654 100644 --- a/test/blocks/p5_blocks.js +++ b/test/blocks/p5_blocks.js @@ -88,6 +88,74 @@ const p5Canvas = { }, }; +const buttonsJson = { + 'type': 'buttons', + 'message0': 'If %1 %2 Then %3 %4 more %5 %6 %7', + 'args0': [ + { + 'type': 'field_image', + 'name': 'BUTTON1', + 'src': 'https://www.gstatic.com/codesite/ph/images/star_on.gif', + 'width': 30, + 'height': 30, + 'alt': '*', + }, + { + 'type': 'input_value', + 'name': 'VALUE1', + 'check': '', + }, + { + 'type': 'field_image', + 'name': 'BUTTON2', + 'src': 'https://www.gstatic.com/codesite/ph/images/star_on.gif', + 'width': 30, + 'height': 30, + 'alt': '*', + }, + { + 'type': 'input_dummy', + 'name': 'DUMMY1', + 'check': '', + }, + { + 'type': 'input_value', + 'name': 'VALUE2', + 'check': '', + }, + { + 'type': 'input_statement', + 'name': 'STATEMENT1', + 'check': 'Number', + }, + { + 'type': 'field_image', + 'name': 'BUTTON3', + 'src': 'https://www.gstatic.com/codesite/ph/images/star_on.gif', + 'width': 30, + 'height': 30, + 'alt': '*', + }, + ], + 'previousStatement': null, + 'nextStatement': null, + 'colour': 230, + 'tooltip': '', + 'helpUrl': '', +}; + +const buttonsBlock = { + init: function () { + this.jsonInit(buttonsJson); + const clickHandler = function () { + console.log('clicking a button!'); + }; + this.getField('BUTTON1').setOnClickHandler(clickHandler); + this.getField('BUTTON2').setOnClickHandler(clickHandler); + this.getField('BUTTON3').setOnClickHandler(clickHandler); + }, +}; + const background = { 'type': 'p5_background_color', 'message0': 'Set background color to %1', @@ -285,5 +353,6 @@ export const blocks = { 'p5_setup': p5Setup, 'p5_draw': p5Draw, 'p5_canvas': p5Canvas, + 'buttons_block': buttonsBlock, ...jsonBlocks, }; diff --git a/test/blocks/toolbox.js b/test/blocks/toolbox.js index 88d54863..586618c9 100644 --- a/test/blocks/toolbox.js +++ b/test/blocks/toolbox.js @@ -54,6 +54,10 @@ export const p5CategoryContents = [ kind: 'block', type: 'write_text_without_shadow', }, + { + kind: 'block', + type: 'buttons_block' + }, ]; export const toolbox = { From 543613786d8466e2361b8dbd70baff0b3800b6d1 Mon Sep 17 00:00:00 2001 From: Erik Pasternak Date: Wed, 28 May 2025 20:51:40 -0700 Subject: [PATCH 2/3] Move buttons block to misc category --- test/blocks/toolbox.js | 4 ---- test/toolboxCategories.js | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/blocks/toolbox.js b/test/blocks/toolbox.js index 586618c9..88d54863 100644 --- a/test/blocks/toolbox.js +++ b/test/blocks/toolbox.js @@ -54,10 +54,6 @@ export const p5CategoryContents = [ kind: 'block', type: 'write_text_without_shadow', }, - { - kind: 'block', - type: 'buttons_block' - }, ]; export const toolbox = { diff --git a/test/toolboxCategories.js b/test/toolboxCategories.js index fe7eb8f7..9fc3d6e9 100644 --- a/test/toolboxCategories.js +++ b/test/toolboxCategories.js @@ -825,6 +825,10 @@ export default { kind: 'block', type: 'colour_random', }, + { + kind: 'block', + type: 'buttons_block' + }, ], }, ], From e6e4bb6014a16a60ef407f7972b29813fda2f7cc Mon Sep 17 00:00:00 2001 From: Erik Pasternak Date: Wed, 28 May 2025 21:14:14 -0700 Subject: [PATCH 3/3] fix formatting --- test/toolboxCategories.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/toolboxCategories.js b/test/toolboxCategories.js index 9fc3d6e9..c66918ce 100644 --- a/test/toolboxCategories.js +++ b/test/toolboxCategories.js @@ -827,7 +827,7 @@ export default { }, { kind: 'block', - type: 'buttons_block' + type: 'buttons_block', }, ], },