Skip to content

Commit

Permalink
SimpleSpawner: Always spawn to the current scene
Browse files Browse the repository at this point in the history
Remove the spawn_parent property and only leave the "SCENE" behavior.
Document this as part of the class documentation.
  • Loading branch information
manuq committed Oct 28, 2024
1 parent 8b93cfb commit 8b35143
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions addons/block_code/simple_spawner/simple_spawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ class_name SimpleSpawner
extends Node2D
## SimpleSpawner node.
##
## If multiple spawned scenes are provided, one is picked ramdomly when spawning.
##
## Spawned instances are children of the current scene.
##
## The scene being spawned is rotated according to this node's global rotation:
## - If the spawned scene is a RigidBody2D, the linear velocity and constant forces
## are rotated according to the SimpleSpawner node global rotation.
Expand All @@ -13,20 +17,11 @@ const BlocksCatalog = preload("res://addons/block_code/code_generation/blocks_ca
const OptionData = preload("res://addons/block_code/code_generation/option_data.gd")
const Types = preload("res://addons/block_code/types/types.gd")

enum SpawnParent {
THIS, ## Spawned scenes are children of this node
SCENE, ## Spawned scenes are children of the scene
}
enum LimitBehavior { REPLACE, NO_SPAWN }

## The scenes to spawn. If more than one are provided, they will be picked randomly.
@export var scenes: Array[PackedScene] = []

## The node that the spawned scenes should be a child of. If you want to move
## the SimpleSpawner without moving the scenes it has already spawned, choose
## SCENE.
@export var spawn_parent: SpawnParent

## 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_period: float = 0.0:
Expand Down Expand Up @@ -111,12 +106,9 @@ func spawn_once():
spawned.constant_force = spawned.constant_force.rotated(global_rotation)
elif spawned is Node2D:
spawned.rotate(global_rotation)
match spawn_parent:
SpawnParent.THIS:
add_child(spawned)
SpawnParent.SCENE:
get_tree().current_scene.add_child(spawned)
spawned.position = global_position
# Add the spawned instance to the current scene:
get_tree().current_scene.add_child(spawned)
spawned.position = global_position


static func setup_custom_blocks():
Expand Down

0 comments on commit 8b35143

Please sign in to comment.