From 9e473b3740483a40db251d435f93be9a0184e4f9 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 4 Nov 2024 10:26:15 +0000 Subject: [PATCH 01/41] Run tests with Godot 4.4 prerelease This is potentially interesting because we have translation-related code that behaves differently between 4.4 (which has some new API) and older versions (which do not). --- .github/workflows/checks.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 1d4e315c..cc3d1088 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -34,6 +34,7 @@ jobs: matrix: godot-version: - 4.3.0 + - 4.4.0-dev7 runs-on: ubuntu-latest steps: - name: Checkout From c5e3c086dff3c59df46d07ae06c05d8ca4f36255 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Mon, 20 Jan 2025 10:27:47 -0600 Subject: [PATCH 02/41] Point to Discussions board for feedback and support We've had multiple users mention that they'd like a better way to share ideas, comments and questions. Discord is one option but I think given current activity levels we'd be better served by a less synchronous option. I've enabled GitHub Discussions as a test. Point users there. --- addons/block_code/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/block_code/README.md b/addons/block_code/README.md index 89036b93..f20b7665 100644 --- a/addons/block_code/README.md +++ b/addons/block_code/README.md @@ -68,9 +68,9 @@ If you want to access the node's property, you can drag the property from the In You can also drag a file from the Resource Filesystem dock and drop it into the block script as a getter block. It will become a constant value block holding the file's resource full path. -## Feedback +## Feedback & Discussion -Please share feedback in the [Godot Forum Block Coding thread](https://forum.godotengine.org/t/block-coding-high-level-block-based-visual-programming/68941). +Please join our [Discussion Board](https://github.com/endlessm/godot-block-coding/discussions) to provide feedback, share ideas, and ask questions about building your games with Block Coding. ## Localization From 87c31b05c9f720cc2512285340117b86afc94e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Fri, 24 Jan 2025 08:29:27 -0300 Subject: [PATCH 03/41] Warn when Block Code overrides parent script Add a warning when the parent node of a BlockCoding node already has a script. To inform the user. https://github.com/endlessm/godot-block-coding/issues/356 --- addons/block_code/block_code_node/block_code.gd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/block_code/block_code_node/block_code.gd b/addons/block_code/block_code_node/block_code.gd index 6ea295ba..2fd3a89f 100644 --- a/addons/block_code/block_code_node/block_code.gd +++ b/addons/block_code/block_code_node/block_code.gd @@ -84,6 +84,8 @@ func _get_configuration_warnings(): warnings.append("A BlockCode must not be a root node.") if get_parent() is BlockCode: warnings.append("The parent must not be a BlockCode.") + if get_parent().script: + warnings.append("This BlockCode will override the existing script in the parent node.") if get_parent().find_children("*", "BlockCode", false).size() > 1: warnings.append("The parent should only contain one BlockCode.") if block_script and _get_custom_or_native_class(get_parent()) != block_script.script_inherits: From 60d02a11625af0a24ca7e2b94433001b168b6e16 Mon Sep 17 00:00:00 2001 From: Daze Date: Mon, 27 Jan 2025 00:01:07 -0500 Subject: [PATCH 04/41] Include minimum version in README --- addons/block_code/README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/block_code/README.md b/addons/block_code/README.md index f20b7665..5853fe9e 100644 --- a/addons/block_code/README.md +++ b/addons/block_code/README.md @@ -21,7 +21,9 @@ See our [pedagogy and audience documentation](docs/PEDAGOGY.md) for more info. ## Getting Started -1. Install the plugin through the Godot AssetLib searching for the name +1. Make sure you have Godot 4.3 or a newer version installed. + +2. Install the plugin through the Godot AssetLib searching for the name Block Coding. You can also download it from the online [Asset Library](https://godotengine.org/asset-library/asset/3095) and import it through AssetLib. Alternatively, you can clone the git repository and @@ -30,13 +32,13 @@ See our [pedagogy and audience documentation](docs/PEDAGOGY.md) for more info. project, reload the project once after opening it for the first time to resolve any errors. This is a Godot issue.* -2. Make sure to enable the plugin in **Project** → **Project Settings** → **Plugins**. +3. Make sure to enable the plugin in **Project** → **Project Settings** → **Plugins**. -3. You're ready to get started! Open a scene, select a node, and observe that there's a **Block Code** section within the lower central pane of the Godot editor, where you usually find debugging, animation and shader functionality. Click **Block Code** and then use the **Add Block Code** button to create a block canvas. +4. You're ready to get started! Open a scene, select a node, and observe that there's a **Block Code** section within the lower central pane of the Godot editor, where you usually find debugging, animation and shader functionality. Click **Block Code** and then use the **Add Block Code** button to create a block canvas. -4. Drag blocks from the picker and snap them together to create a script. You can switch to other Block Code scripts by selecting the respective node from the scene tree. +5. Drag blocks from the picker and snap them together to create a script. You can switch to other Block Code scripts by selecting the respective node from the scene tree. -5. **Run** the scene to see your Block Code scripts in action. Block Code scripts are saved within the scene. +6. **Run** the scene to see your Block Code scripts in action. Block Code scripts are saved within the scene. If you clone the plugin's git repository and open it in Godot, you will be presented with a block-built Pong game as an example. From 6e318f24dfd963983965b21450631af5eac51a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 29 Jan 2025 07:34:13 -0300 Subject: [PATCH 05/41] Make blocks in Picker not editable Add a new "editable" boolean property to Block, TemplateEditor and ParameterInput. When the block is in the picker, it will not be editable. Only when they are dragged to the canvas they become editable. The property has to be in each of these components because Block can't access its ParameterInputs directly, only through its TemplateEditor. The dropdown options in a not-editable block can still be changed to avoid disabling the button. But the change doesn't trigger any effect. The default is editable = true, so blocks in the canvas are editable. Fix https://github.com/endlessm/godot-block-coding/issues/357 --- .../block_code/drag_manager/drag_manager.gd | 3 ++- addons/block_code/ui/blocks/block/block.gd | 9 ++++++++ .../parameter_input/parameter_input.gd | 22 +++++++++++++++++++ .../parameter_input/parameter_input.tscn | 1 + .../template_editor/template_editor.gd | 12 ++++++++++ .../template_editor/template_editor.tscn | 1 + .../categories/block_category_display.gd | 1 + 7 files changed, 48 insertions(+), 1 deletion(-) diff --git a/addons/block_code/drag_manager/drag_manager.gd b/addons/block_code/drag_manager/drag_manager.gd index 201e0394..1c322c06 100644 --- a/addons/block_code/drag_manager/drag_manager.gd +++ b/addons/block_code/drag_manager/drag_manager.gd @@ -82,8 +82,9 @@ func drag_ended(): connect_block_canvas_signals(block) block.grab_focus() - # Allow the block to be deleted now that it's on the canvas. + # Allow the block to be deleted and edited now that it's on the canvas. block.can_delete = true + block.editable = true _block_canvas.release_scope() diff --git a/addons/block_code/ui/blocks/block/block.gd b/addons/block_code/ui/blocks/block/block.gd index 6a6f851e..64be644f 100644 --- a/addons/block_code/ui/blocks/block/block.gd +++ b/addons/block_code/ui/blocks/block/block.gd @@ -10,6 +10,10 @@ signal modified ## Color of block (optionally used to draw block color) @export var color: Color = Color(1., 1., 1.) +## Whether the parameter inputs inside the block can be edited. +@export var editable: bool = true: + set = _set_editable + # FIXME Note: This used to be a NodePath. There is a bug in Godot 4.2 that causes the # reference to not be set properly when the node is duplicated. Since we don't # use the Node duplicate function anymore, this is okay. @@ -56,6 +60,11 @@ func _ready(): _on_definition_changed() +func _set_editable(value) -> void: + editable = value + template_editor.editable = value + + func _block_on_focus_entered(): z_index = 1 if bottom_snap: diff --git a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd index 46de1795..c9551bdf 100644 --- a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd +++ b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd @@ -56,6 +56,22 @@ var _drag_start: Vector2 = Vector2.INF _v3_z_line_edit: "", } +## Whether the text inputs can be edited, and whether the options selection have any effect. +@export var editable: bool = true: + set = _set_editable + + +func _set_editable(value) -> void: + if not is_node_ready(): + await ready + editable = value + _line_edit.editable = value + _x_line_edit.editable = value + _y_line_edit.editable = value + _v3_x_line_edit.editable = value + _v3_y_line_edit.editable = value + _v3_z_line_edit.editable = value + ## Sets the value using [param raw_input], which could be one of a variety of types ## depending on [member variant_type]. The value could also be a [Block], in which @@ -180,6 +196,8 @@ func get_snapped_block() -> Block: func _validate_and_submit_edit_text(line_edit: Node, type: Variant.Type): + if not editable: + return if _last_submitted_text[line_edit] == line_edit.text: return match type: @@ -319,6 +337,8 @@ func _update_option_input(current_value: Variant = null): func _on_color_input_color_changed(color): + if not editable: + return _update_background_color(color) modified.emit() @@ -328,6 +348,8 @@ func _update_background_color(new_color): func _on_option_input_item_selected(index): + if not editable: + return modified.emit() diff --git a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn index 7add975d..85626bbb 100644 --- a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn +++ b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn @@ -34,6 +34,7 @@ grow_horizontal = 2 grow_vertical = 2 mouse_filter = 2 script = ExtResource("1_rgmxn") +editable = null [node name="Background" type="Control" parent="."] unique_name_in_owner = true diff --git a/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd b/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd index 6a17ca2f..147a20c2 100644 --- a/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd +++ b/addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd @@ -36,6 +36,10 @@ const CollapsableSettingsScene = preload("res://addons/block_code/ui/blocks/util parameter_defaults = value _update_from_format_string() +## Whether the parameter inputs can be edited. +@export var editable: bool = true: + set = _set_editable + var parent_block: Block var _parameter_inputs_by_name: Dictionary @@ -48,6 +52,13 @@ func _ready() -> void: _update_from_format_string() +func _set_editable(value) -> void: + editable = value + for parameter_name in _parameter_inputs_by_name: + var parameter_input: ParameterInput = _parameter_inputs_by_name[parameter_name] + parameter_input.editable = value + + ## Set the values of all input parameters based from a dictionary of raw values. ## Parameters not included in [param raw_values] will be reset to their ## defaults according to [member parameter_defaults]. @@ -125,6 +136,7 @@ func _append_input_parameter(container: Container, parameter: Dictionary, id: in parameter_input.placeholder = parameter["name"] parameter_input.variant_type = parameter["type"] parameter_input.drag_started.connect(_on_parameter_input_drag_started) + parameter_input.editable = editable if default_value is OptionData: var option_data := default_value as OptionData diff --git a/addons/block_code/ui/blocks/utilities/template_editor/template_editor.tscn b/addons/block_code/ui/blocks/utilities/template_editor/template_editor.tscn index 319306d1..2f96ad4b 100644 --- a/addons/block_code/ui/blocks/utilities/template_editor/template_editor.tscn +++ b/addons/block_code/ui/blocks/utilities/template_editor/template_editor.tscn @@ -10,6 +10,7 @@ grow_horizontal = 2 grow_vertical = 2 mouse_filter = 2 script = ExtResource("1_7extq") +editable = null [node name="Container" type="HBoxContainer" parent="."] unique_name_in_owner = true diff --git a/addons/block_code/ui/picker/categories/block_category_display.gd b/addons/block_code/ui/picker/categories/block_category_display.gd index c534ea9d..685dc6c4 100644 --- a/addons/block_code/ui/picker/categories/block_category_display.gd +++ b/addons/block_code/ui/picker/categories/block_category_display.gd @@ -66,6 +66,7 @@ func _get_or_create_block(block_definition: BlockDefinition) -> Block: if block == null: block = _context.block_script.instantiate_block(block_definition) block.can_delete = false + block.editable = false block.drag_started.connect(func(block: Block, offset: Vector2): block_picked.emit(block, offset)) _blocks_container.add_child(block) _blocks[block_definition.name] = block From 055fce72dece3af26361c70eab4738cb014dbaec Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 29 Jan 2025 11:51:35 +0000 Subject: [PATCH 06/41] Don't warn when BlockCode script extends parent script Commit 87c31b05c9f720cc2512285340117b86afc94e8e ("Warn when Block Code overrides parent script") introduced a warning when a BlockCode node's parent has a script attached. But if the parent is (for example) a Character2D with our SimpleCharacter script attached, this warning is incorrect: the block code script will correctly extend, not override, the parent. Before issuing this warning, check if the parent's script has a class_name that matches what the generated BlockCode script will extend, and suppress the warning if so. Fixes https://github.com/endlessm/godot-block-coding/issues/356 --- addons/block_code/block_code_node/block_code.gd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/block_code/block_code_node/block_code.gd b/addons/block_code/block_code_node/block_code.gd index 2fd3a89f..07e7cdeb 100644 --- a/addons/block_code/block_code_node/block_code.gd +++ b/addons/block_code/block_code_node/block_code.gd @@ -85,7 +85,9 @@ func _get_configuration_warnings(): if get_parent() is BlockCode: warnings.append("The parent must not be a BlockCode.") if get_parent().script: - warnings.append("This BlockCode will override the existing script in the parent node.") + var parent_script_name: StringName = get_parent().script.get_global_name() + if not (parent_script_name and block_script and parent_script_name == block_script.script_inherits): + warnings.append("This BlockCode will override the existing script in the parent node.") if get_parent().find_children("*", "BlockCode", false).size() > 1: warnings.append("The parent should only contain one BlockCode.") if block_script and _get_custom_or_native_class(get_parent()) != block_script.script_inherits: From 8750f7b6d85b1abd6576da54e98810aba5ead223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 29 Jan 2025 12:23:28 -0300 Subject: [PATCH 07/41] Update technical documentation Document BlockDefinition resource and block types using GDScript documentation comments. Outside code, rename the current technical document to `docs/TECH_OVERVIEW.md` to indicate that it's technical. And update it: - Move "How to create a new block" to the top - Leave UI technical docs in its own section - Remove other outdated explanation It would be nice to also document the AST decouple from the UI, but I'm no expert to do it. --- .../code_generation/block_definition.gd | 40 ++++++- addons/block_code/types/types.gd | 10 +- docs/OVERVIEW.md | 108 ------------------ docs/TECH_OVERVIEW.md | 26 +++++ 4 files changed, 68 insertions(+), 116 deletions(-) delete mode 100644 docs/OVERVIEW.md create mode 100644 docs/TECH_OVERVIEW.md diff --git a/addons/block_code/code_generation/block_definition.gd b/addons/block_code/code_generation/block_definition.gd index a4447044..d13ce8bf 100644 --- a/addons/block_code/code_generation/block_definition.gd +++ b/addons/block_code/code_generation/block_definition.gd @@ -11,25 +11,59 @@ const FORMAT_STRING_PATTERN = "\\[(?[^\\]]+)\\]|\\{const (?