Skip to content

Commit 2f66ee7

Browse files
authored
Merge pull request #272 from endlessm/simplespawner-frequency-is-actually-period
SimpleSpawner: Rename frequency to period
2 parents 7ac2a2b + a353af4 commit 2f66ee7

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

addons/block_code/examples/spawner/spawner.tscn

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ arguments = {
3737

3838
[sub_resource type="Resource" id="Resource_uv0fo"]
3939
script = ExtResource("7_cykhe")
40-
name = &"simplespawner_get_spawn_frequency"
40+
name = &"simplespawner_get_spawn_period"
4141
arguments = {}
4242

4343
[sub_resource type="Resource" id="Resource_l45hk"]
@@ -50,10 +50,10 @@ arguments = {
5050

5151
[sub_resource type="Resource" id="Resource_6g0ng"]
5252
script = ExtResource("6_dv2kl")
53-
name = &"simplespawner_set_spawn_frequency"
53+
name = &"simplespawner_set_spawn_period"
5454
children = Array[ExtResource("6_dv2kl")]([])
5555
arguments = {
56-
"new_frequency": SubResource("Resource_l45hk")
56+
"new_period": SubResource("Resource_l45hk")
5757
}
5858

5959
[sub_resource type="Resource" id="Resource_ke4bk"]
@@ -74,7 +74,7 @@ arguments = {
7474

7575
[sub_resource type="Resource" id="Resource_ih8lj"]
7676
script = ExtResource("7_cykhe")
77-
name = &"simplespawner_get_spawn_frequency"
77+
name = &"simplespawner_get_spawn_period"
7878
arguments = {}
7979

8080
[sub_resource type="Resource" id="Resource_rfxul"]
@@ -87,10 +87,10 @@ arguments = {
8787

8888
[sub_resource type="Resource" id="Resource_2rqfa"]
8989
script = ExtResource("6_dv2kl")
90-
name = &"simplespawner_set_spawn_frequency"
90+
name = &"simplespawner_set_spawn_period"
9191
children = Array[ExtResource("6_dv2kl")]([])
9292
arguments = {
93-
"new_frequency": SubResource("Resource_rfxul")
93+
"new_period": SubResource("Resource_rfxul")
9494
}
9595

9696
[sub_resource type="Resource" id="Resource_movu5"]
@@ -194,9 +194,9 @@ func _ready():
194194
195195
func _process(delta):
196196
if (Input.is_action_just_pressed('ui_right')):
197-
do_set_spawn_frequency(((spawn_frequency) - 0.1))
197+
spawn_period = ((spawn_period) - 0.1)
198198
elif (Input.is_action_just_pressed('ui_left')):
199-
do_set_spawn_frequency(((spawn_frequency) + 0.1))
199+
spawn_period = ((spawn_period) + 0.1)
200200
elif (Input.is_action_just_pressed('ui_up')):
201201
if (is_spawning()):
202202
spawn_stop()
@@ -216,7 +216,7 @@ version = 0
216216
position = Vector2(103, 128)
217217
script = ExtResource("1_g2l2s")
218218
scenes = Array[PackedScene]([ExtResource("2_d0h86"), ExtResource("3_tt12o")])
219-
spawn_frequency = 0.6
219+
spawn_period = 0.6
220220
spawn_limit = 5
221221

222222
[node name="BlockCode" type="Node" parent="SimpleSpawner"]

addons/block_code/simple_spawner/simple_spawner.gd

+14-18
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ 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") 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.
30-
@export_range(0, 50, 0.1, "or_greater") var spawn_limit: int = 50
30+
@export_range(0, 50, 0.1, "or_greater", "suffix:scenes") var spawn_limit: int = 50
3131

3232
## What happens when the limit is reached and a new spawn is attempted:
3333
## - Replace: Remove the oldest spawned scene and spawn a new one.
@@ -53,20 +53,20 @@ func _remove_oldest_spawned():
5353
spawned.get_parent().remove_child(spawned)
5454

5555

56-
func _set_spawn_fraquency(new_frequency: float):
57-
spawn_frequency = new_frequency
56+
func _set_spawn_period(new_period: float):
57+
spawn_period = new_period
5858
if not _timer or not is_instance_valid(_timer):
5959
return
60-
_timer.wait_time = spawn_frequency
60+
_timer.wait_time = spawn_period
6161

6262

6363
func spawn_start():
64-
if spawn_frequency == 0.0:
64+
if spawn_period == 0.0:
6565
return
6666
if not _timer or not is_instance_valid(_timer):
6767
_timer = Timer.new()
6868
add_child(_timer)
69-
_timer.wait_time = spawn_frequency
69+
_timer.wait_time = spawn_period
7070
_timer.timeout.connect(spawn_once)
7171
_timer.start()
7272
spawn_once.call_deferred()
@@ -107,10 +107,6 @@ func spawn_once():
107107
spawned.position = global_position
108108

109109

110-
func do_set_spawn_frequency(new_frequency: float):
111-
_set_spawn_fraquency(new_frequency)
112-
113-
114110
static func setup_custom_blocks():
115111
var _class_name = "SimpleSpawner"
116112
var block_list: Array[BlockDefinition] = []
@@ -153,22 +149,22 @@ static func setup_custom_blocks():
153149
block_list.append(block_definition)
154150

155151
block_definition = BlockDefinition.new()
156-
block_definition.name = &"simplespawner_set_spawn_frequency"
152+
block_definition.name = &"simplespawner_set_spawn_period"
157153
block_definition.target_node_class = _class_name
158154
block_definition.category = "Lifecycle | Spawn"
159155
block_definition.type = Types.BlockType.STATEMENT
160-
block_definition.display_template = "set spawn frequency to {new_frequency: FLOAT}"
161-
block_definition.code_template = "do_set_spawn_frequency({new_frequency})"
156+
block_definition.display_template = "set spawn period to {new_period: FLOAT}"
157+
block_definition.code_template = "spawn_period = {new_period}"
162158
block_list.append(block_definition)
163159

164160
block_definition = BlockDefinition.new()
165-
block_definition.name = &"simplespawner_get_spawn_frequency"
161+
block_definition.name = &"simplespawner_get_spawn_period"
166162
block_definition.target_node_class = _class_name
167163
block_definition.category = "Lifecycle | Spawn"
168164
block_definition.type = Types.BlockType.VALUE
169165
block_definition.variant_type = TYPE_FLOAT
170-
block_definition.display_template = "spawn frequency"
171-
block_definition.code_template = "spawn_frequency"
166+
block_definition.display_template = "spawn period"
167+
block_definition.code_template = "spawn_period"
172168
block_list.append(block_definition)
173169

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

0 commit comments

Comments
 (0)