Skip to content

Commit bc93c4f

Browse files
committed
SimpleSpawner: Rename frequency to period
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.
1 parent 57b06bc commit bc93c4f

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

.github/workflows/checks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
name: Tests
2828
strategy:
2929
matrix:
30-
godot-version: [4.2.2, 4.3.0]
30+
godot-version: [4.3.0]
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Checkout

addons/block_code/simple_spawner/simple_spawner.gd

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ enum LimitBehavior { REPLACE, NO_SPAWN }
2323

2424
## The period of time in seconds to spawn another component. If zero, they won't spawn
2525
## automatically. Use the "Spawn" block.
26-
@export_range(0.0, 10.0, 0.1, "or_greater", "suffix:s") var spawn_frequency: float = 0.0:
27-
set = _set_spawn_fraquency
26+
@export_range(0.0, 10.0, 0.1, "or_greater", "suffix:s") var spawn_period: float = 0.0:
27+
set = _set_spawn_period
2828

2929
## How many spawned scenes are allowed. If zero, there is no limit.
3030
@export_range(0, 50, 0.1, "or_greater", "suffix:scenes") var spawn_limit: int = 50
@@ -34,6 +34,15 @@ enum LimitBehavior { REPLACE, NO_SPAWN }
3434
## - No Spawn: No spawn happens until any spawned scene is removed by other means.
3535
@export var limit_behavior: LimitBehavior
3636

37+
## Old name for [member spawn_period].
38+
##
39+
## @deprecated: Use [member spawn_period] instead
40+
@export_storage var spawn_frequency: float:
41+
get:
42+
return spawn_period
43+
set(value):
44+
spawn_period = value
45+
3746
var _timer: Timer
3847
var _spawned_scenes: Array[Node]
3948

@@ -53,20 +62,20 @@ func _remove_oldest_spawned():
5362
spawned.get_parent().remove_child(spawned)
5463

5564

56-
func _set_spawn_fraquency(new_frequency: float):
57-
spawn_frequency = new_frequency
65+
func _set_spawn_period(new_period: float):
66+
spawn_period = new_period
5867
if not _timer or not is_instance_valid(_timer):
5968
return
60-
_timer.wait_time = spawn_frequency
69+
_timer.wait_time = spawn_period
6170

6271

6372
func spawn_start():
64-
if spawn_frequency == 0.0:
73+
if spawn_period == 0.0:
6574
return
6675
if not _timer or not is_instance_valid(_timer):
6776
_timer = Timer.new()
6877
add_child(_timer)
69-
_timer.wait_time = spawn_frequency
78+
_timer.wait_time = spawn_period
7079
_timer.timeout.connect(spawn_once)
7180
_timer.start()
7281
spawn_once.call_deferred()
@@ -106,9 +115,9 @@ func spawn_once():
106115
get_tree().current_scene.add_child(spawned)
107116
spawned.position = global_position
108117

109-
118+
## @deprecated: Set the [member spawn_period] property instead
110119
func do_set_spawn_frequency(new_frequency: float):
111-
_set_spawn_fraquency(new_frequency)
120+
spawn_period = new_frequency
112121

113122

114123
static func setup_custom_blocks():
@@ -159,6 +168,7 @@ static func setup_custom_blocks():
159168
block_definition.type = Types.BlockType.STATEMENT
160169
block_definition.display_template = "set spawn frequency to {new_frequency: FLOAT}"
161170
block_definition.code_template = "do_set_spawn_frequency({new_frequency})"
171+
block_definition.hidden = true
162172
block_list.append(block_definition)
163173

164174
block_definition = BlockDefinition.new()
@@ -169,6 +179,26 @@ static func setup_custom_blocks():
169179
block_definition.variant_type = TYPE_FLOAT
170180
block_definition.display_template = "spawn frequency"
171181
block_definition.code_template = "spawn_frequency"
182+
block_definition.hidden = true
183+
block_list.append(block_definition)
184+
185+
block_definition = BlockDefinition.new()
186+
block_definition.name = &"simplespawner_set_spawn_period"
187+
block_definition.target_node_class = _class_name
188+
block_definition.category = "Lifecycle | Spawn"
189+
block_definition.type = Types.BlockType.STATEMENT
190+
block_definition.display_template = "set spawn period to {new_period: FLOAT}"
191+
block_definition.code_template = "spawn_period = {new_period}"
192+
block_list.append(block_definition)
193+
194+
block_definition = BlockDefinition.new()
195+
block_definition.name = &"simplespawner_get_spawn_period"
196+
block_definition.target_node_class = _class_name
197+
block_definition.category = "Lifecycle | Spawn"
198+
block_definition.type = Types.BlockType.VALUE
199+
block_definition.variant_type = TYPE_FLOAT
200+
block_definition.display_template = "spawn period"
201+
block_definition.code_template = "spawn_period"
172202
block_list.append(block_definition)
173203

174204
BlocksCatalog.add_custom_blocks(_class_name, block_list, [], {})

asset-template.json.hb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "Block Coding",
33
"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.",
44
"category_id": "5",
5-
"godot_version": "4.2",
5+
"godot_version": "4.3",
66
"version_string": "{{ context.release.name }}",
77
"cost": "MIT",
88
"support_level": "community",

0 commit comments

Comments
 (0)