From 06f325cb0c7c03c3acf826109d931d10cd9600e9 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 14 Oct 2024 11:03:22 +0200 Subject: [PATCH 1/4] SimpleSpawner: Add unit suffixes to exported properties I learned about this annotation in a workshop hosted by Nathan from GDQuest. --- addons/block_code/simple_spawner/simple_spawner.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/block_code/simple_spawner/simple_spawner.gd b/addons/block_code/simple_spawner/simple_spawner.gd index fac71698..16b20fb7 100644 --- a/addons/block_code/simple_spawner/simple_spawner.gd +++ b/addons/block_code/simple_spawner/simple_spawner.gd @@ -23,11 +23,11 @@ enum LimitBehavior { REPLACE, NO_SPAWN } ## The period of time in seconds to spawn another component. If zero, they won't spawn ## automatically. Use the "Spawn" block. -@export_range(0.0, 10.0, 0.1, "or_greater") var spawn_frequency: float = 0.0: +@export_range(0.0, 10.0, 0.1, "or_greater", "suffix:s") var spawn_frequency: float = 0.0: set = _set_spawn_fraquency ## How many spawned scenes are allowed. If zero, there is no limit. -@export_range(0, 50, 0.1, "or_greater") var spawn_limit: int = 50 +@export_range(0, 50, 0.1, "or_greater", "suffix:scenes") var spawn_limit: int = 50 ## What happens when the limit is reached and a new spawn is attempted: ## - Replace: Remove the oldest spawned scene and spawn a new one. From 27149417931caa96ea26f805c7b4b97fff8abd9d Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 22 Oct 2024 14:34:20 +0100 Subject: [PATCH 2/4] Add the concept of a hidden block definition This makes it possible to define a block that cannot be added to new block programs, but which will still work if present in a block program. The intended use is to fix SimpleSpawner's "spawn frequency" property and blocks, which is in fact the spawn period (frequency is the reciprocal of period). --- addons/block_code/code_generation/block_definition.gd | 5 +++++ addons/block_code/ui/picker/picker.gd | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/block_code/code_generation/block_definition.gd b/addons/block_code/code_generation/block_definition.gd index 26ac9e70..8857421c 100644 --- a/addons/block_code/code_generation/block_definition.gd +++ b/addons/block_code/code_generation/block_definition.gd @@ -30,6 +30,11 @@ const FORMAT_STRING_PATTERN = "\\[(?[^\\]]+)\\]|\\{(? Date: Tue, 22 Oct 2024 15:15:56 +0100 Subject: [PATCH 3/4] Add hidden = false to all BlockDefinition resources --- addons/block_code/blocks/communication/add_node_to_group.tres | 1 + addons/block_code/blocks/communication/add_to_group.tres | 1 + addons/block_code/blocks/communication/call_method_group.tres | 1 + addons/block_code/blocks/communication/get_node.tres | 1 + addons/block_code/blocks/communication/is_in_group.tres | 1 + addons/block_code/blocks/communication/is_node_in_group.tres | 1 + addons/block_code/blocks/communication/remove_from_group.tres | 1 + .../block_code/blocks/communication/remove_node_from_group.tres | 1 + addons/block_code/blocks/graphics/animationplayer_play.tres | 1 + addons/block_code/blocks/input/is_input_actioned.tres | 1 + addons/block_code/blocks/logic/compare.tres | 1 + addons/block_code/blocks/sounds/pause_continue_sound.tres | 1 + 12 files changed, 12 insertions(+) diff --git a/addons/block_code/blocks/communication/add_node_to_group.tres b/addons/block_code/blocks/communication/add_node_to_group.tres index 2e386d22..40dd39d9 100644 --- a/addons/block_code/blocks/communication/add_node_to_group.tres +++ b/addons/block_code/blocks/communication/add_node_to_group.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("1_p83c7") +hidden = false diff --git a/addons/block_code/blocks/communication/add_to_group.tres b/addons/block_code/blocks/communication/add_to_group.tres index 04e14a6f..b7eff98d 100644 --- a/addons/block_code/blocks/communication/add_to_group.tres +++ b/addons/block_code/blocks/communication/add_to_group.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("2_42ixf") +hidden = false diff --git a/addons/block_code/blocks/communication/call_method_group.tres b/addons/block_code/blocks/communication/call_method_group.tres index 06515f55..e69ae4fd 100644 --- a/addons/block_code/blocks/communication/call_method_group.tres +++ b/addons/block_code/blocks/communication/call_method_group.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("1_of577") +hidden = false diff --git a/addons/block_code/blocks/communication/get_node.tres b/addons/block_code/blocks/communication/get_node.tres index 22f7f5ff..8f86a4f9 100644 --- a/addons/block_code/blocks/communication/get_node.tres +++ b/addons/block_code/blocks/communication/get_node.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("1_we5wl") +hidden = false diff --git a/addons/block_code/blocks/communication/is_in_group.tres b/addons/block_code/blocks/communication/is_in_group.tres index afd089d8..a5200ce6 100644 --- a/addons/block_code/blocks/communication/is_in_group.tres +++ b/addons/block_code/blocks/communication/is_in_group.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("2_o165d") +hidden = false diff --git a/addons/block_code/blocks/communication/is_node_in_group.tres b/addons/block_code/blocks/communication/is_node_in_group.tres index d56b3f7e..1d535f5f 100644 --- a/addons/block_code/blocks/communication/is_node_in_group.tres +++ b/addons/block_code/blocks/communication/is_node_in_group.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("1_r4prw") +hidden = false diff --git a/addons/block_code/blocks/communication/remove_from_group.tres b/addons/block_code/blocks/communication/remove_from_group.tres index b25fe8ad..78fd3dd4 100644 --- a/addons/block_code/blocks/communication/remove_from_group.tres +++ b/addons/block_code/blocks/communication/remove_from_group.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("1_i50fw") +hidden = false diff --git a/addons/block_code/blocks/communication/remove_node_from_group.tres b/addons/block_code/blocks/communication/remove_node_from_group.tres index defa9251..338c1ce1 100644 --- a/addons/block_code/blocks/communication/remove_node_from_group.tres +++ b/addons/block_code/blocks/communication/remove_node_from_group.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("1_h3lhb") +hidden = false diff --git a/addons/block_code/blocks/graphics/animationplayer_play.tres b/addons/block_code/blocks/graphics/animationplayer_play.tres index 3a593f83..f56dafaf 100644 --- a/addons/block_code/blocks/graphics/animationplayer_play.tres +++ b/addons/block_code/blocks/graphics/animationplayer_play.tres @@ -43,3 +43,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("2_7ymgi") +hidden = false diff --git a/addons/block_code/blocks/input/is_input_actioned.tres b/addons/block_code/blocks/input/is_input_actioned.tres index 5f7545f3..2b4062fa 100644 --- a/addons/block_code/blocks/input/is_input_actioned.tres +++ b/addons/block_code/blocks/input/is_input_actioned.tres @@ -25,3 +25,4 @@ defaults = { signal_name = "" scope = "" extension_script = ExtResource("2_h11b7") +hidden = false diff --git a/addons/block_code/blocks/logic/compare.tres b/addons/block_code/blocks/logic/compare.tres index d4b4dc4f..b3f40b0f 100644 --- a/addons/block_code/blocks/logic/compare.tres +++ b/addons/block_code/blocks/logic/compare.tres @@ -25,3 +25,4 @@ defaults = { } signal_name = "" scope = "" +hidden = false diff --git a/addons/block_code/blocks/sounds/pause_continue_sound.tres b/addons/block_code/blocks/sounds/pause_continue_sound.tres index 17487bbc..68d0c538 100644 --- a/addons/block_code/blocks/sounds/pause_continue_sound.tres +++ b/addons/block_code/blocks/sounds/pause_continue_sound.tres @@ -28,3 +28,4 @@ defaults = { } signal_name = "" scope = "" +hidden = false From 17d897e2983a79c32267f3d613443d867eacf711 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 22 Oct 2024 15:18:55 +0100 Subject: [PATCH 4/4] SimpleSpawner: Rename frequency to period MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This property is the time, in seconds, to wait between spawning scenes. This is a period/interval/wavelength, not a frequency, which would be measured in Hz, or 1/seconds. Add a new property and corresponding blocks with the correct definition. Adjust the existing property to delegate to the new property. Use @export_storage to allow its value to be set from existing serialized scenes without it being visible in the inspector. This annotation is new in Godot 4.3 so bump our minimum supported version. When a scene that overrides the old property is loaded in the editor, the value will be propagated to the new property, which is then saved into the scene. Adjusting the new property also adjusts the old property's value. The old property will hang around, harmlessly mirroring the new property, in the .tscn file until it is removed in a text editor. The instances of “frequency” that I have not changed are in the example scene's on-screen documentation. In this case it was actually used correctly: the keyboard action to increase the frequency reduces the property which is now called period, and the decrease action respectively increases the period. --- .github/workflows/checks.yaml | 2 +- .../simple_spawner/simple_spawner.gd | 47 +++++++++++++++---- asset-template.json.hb | 2 +- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index f8057221..ea5086d6 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -27,7 +27,7 @@ jobs: name: Tests strategy: matrix: - godot-version: [4.2.2, 4.3.0] + godot-version: [4.3.0] runs-on: ubuntu-latest steps: - name: Checkout diff --git a/addons/block_code/simple_spawner/simple_spawner.gd b/addons/block_code/simple_spawner/simple_spawner.gd index 16b20fb7..601ac85c 100644 --- a/addons/block_code/simple_spawner/simple_spawner.gd +++ b/addons/block_code/simple_spawner/simple_spawner.gd @@ -23,8 +23,8 @@ enum LimitBehavior { REPLACE, NO_SPAWN } ## The period of time in seconds to spawn another component. If zero, they won't spawn ## automatically. Use the "Spawn" block. -@export_range(0.0, 10.0, 0.1, "or_greater", "suffix:s") var spawn_frequency: float = 0.0: - set = _set_spawn_fraquency +@export_range(0.0, 10.0, 0.1, "or_greater", "suffix:s") var spawn_period: float = 0.0: + set = _set_spawn_period ## How many spawned scenes are allowed. If zero, there is no limit. @export_range(0, 50, 0.1, "or_greater", "suffix:scenes") var spawn_limit: int = 50 @@ -34,6 +34,15 @@ enum LimitBehavior { REPLACE, NO_SPAWN } ## - No Spawn: No spawn happens until any spawned scene is removed by other means. @export var limit_behavior: LimitBehavior +## Old name for [member spawn_period]. +## +## @deprecated: Use [member spawn_period] instead +@export_storage var spawn_frequency: float: + get: + return spawn_period + set(value): + spawn_period = value + var _timer: Timer var _spawned_scenes: Array[Node] @@ -53,20 +62,20 @@ func _remove_oldest_spawned(): spawned.get_parent().remove_child(spawned) -func _set_spawn_fraquency(new_frequency: float): - spawn_frequency = new_frequency +func _set_spawn_period(new_period: float): + spawn_period = new_period if not _timer or not is_instance_valid(_timer): return - _timer.wait_time = spawn_frequency + _timer.wait_time = spawn_period func spawn_start(): - if spawn_frequency == 0.0: + if spawn_period == 0.0: return if not _timer or not is_instance_valid(_timer): _timer = Timer.new() add_child(_timer) - _timer.wait_time = spawn_frequency + _timer.wait_time = spawn_period _timer.timeout.connect(spawn_once) _timer.start() spawn_once.call_deferred() @@ -107,8 +116,9 @@ func spawn_once(): spawned.position = global_position +## @deprecated: Set the [member spawn_period] property instead func do_set_spawn_frequency(new_frequency: float): - _set_spawn_fraquency(new_frequency) + spawn_period = new_frequency static func setup_custom_blocks(): @@ -159,6 +169,7 @@ static func setup_custom_blocks(): block_definition.type = Types.BlockType.STATEMENT block_definition.display_template = "set spawn frequency to {new_frequency: FLOAT}" block_definition.code_template = "do_set_spawn_frequency({new_frequency})" + block_definition.hidden = true block_list.append(block_definition) block_definition = BlockDefinition.new() @@ -169,6 +180,26 @@ static func setup_custom_blocks(): block_definition.variant_type = TYPE_FLOAT block_definition.display_template = "spawn frequency" block_definition.code_template = "spawn_frequency" + block_definition.hidden = true + block_list.append(block_definition) + + block_definition = BlockDefinition.new() + block_definition.name = &"simplespawner_set_spawn_period" + block_definition.target_node_class = _class_name + block_definition.category = "Lifecycle | Spawn" + block_definition.type = Types.BlockType.STATEMENT + block_definition.display_template = "set spawn period to {new_period: FLOAT}" + block_definition.code_template = "spawn_period = {new_period}" + block_list.append(block_definition) + + block_definition = BlockDefinition.new() + block_definition.name = &"simplespawner_get_spawn_period" + block_definition.target_node_class = _class_name + block_definition.category = "Lifecycle | Spawn" + block_definition.type = Types.BlockType.VALUE + block_definition.variant_type = TYPE_FLOAT + block_definition.display_template = "spawn period" + block_definition.code_template = "spawn_period" block_list.append(block_definition) BlocksCatalog.add_custom_blocks(_class_name, block_list, [], {}) diff --git a/asset-template.json.hb b/asset-template.json.hb index d9539075..a0093ae6 100644 --- a/asset-template.json.hb +++ b/asset-template.json.hb @@ -2,7 +2,7 @@ "title": "Block Coding", "description": "Create games using a high-level, block-based visual programming language.\r\n\r\nIntended as an educational tool for learners in the earlier stages of their journey towards becoming game developers. This plugin lets you create your first games with high-level blocks, avoiding the immediate need to learn to code in GDScript. Building games in this way provides a gentle introduction to programming concepts and allows you to focus your efforts on becoming familiar with the rest of the Godot Editor UI.", "category_id": "5", - "godot_version": "4.2", + "godot_version": "4.3", "version_string": "{{ context.release.name }}", "cost": "MIT", "support_level": "community",