2025-08-26 15:52:54 +08:00
|
|
|
extends Node2D
|
|
|
|
|
class_name EffectController
|
|
|
|
|
|
|
|
|
|
@export var oneShot: bool = true
|
2025-08-29 13:56:31 +08:00
|
|
|
@export var spawnSound: String = ""
|
2025-09-20 22:17:09 +08:00
|
|
|
@export var spawnAnimation: String = ""
|
2025-08-26 15:52:54 +08:00
|
|
|
|
|
|
|
|
@onready var particles: GPUParticles2D = $"%particles"
|
2025-09-20 22:17:09 +08:00
|
|
|
@onready var sounds: Node2D = $"%sounds"
|
|
|
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
2025-08-26 15:52:54 +08:00
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
|
particles.emitting = false
|
|
|
|
|
particles.one_shot = oneShot
|
2025-08-29 13:56:31 +08:00
|
|
|
var sound = sounds.get_node_or_null(spawnSound)
|
|
|
|
|
if sound and sound.stream:
|
|
|
|
|
sound.play()
|
2025-09-20 22:17:09 +08:00
|
|
|
if spawnAnimation:
|
|
|
|
|
animator.play(spawnAnimation)
|
2025-08-26 15:52:54 +08:00
|
|
|
func shot():
|
|
|
|
|
var cloned = particles.duplicate() as GPUParticles2D
|
|
|
|
|
cloned.emitting = true
|
|
|
|
|
add_child(cloned)
|
|
|
|
|
if oneShot:
|
|
|
|
|
await cloned.finished
|
|
|
|
|
cloned.queue_free()
|
2025-12-14 17:01:09 +08:00
|
|
|
if spawnSound:
|
|
|
|
|
var sound: AudioStreamPlayer2D = sounds.get_node(spawnSound)
|
|
|
|
|
if sound.playing:
|
|
|
|
|
await sound.finished
|
2025-12-14 13:36:48 +08:00
|
|
|
queue_free()
|
2025-08-29 12:42:44 +08:00
|
|
|
|
|
|
|
|
static func create(scene: PackedScene, spawnPosition: Vector2, parent: Node2D = null) -> EffectController:
|
|
|
|
|
var cloned = scene.instantiate() as EffectController
|
|
|
|
|
cloned.global_position = spawnPosition
|
|
|
|
|
if parent:
|
|
|
|
|
parent.add_child(cloned)
|
|
|
|
|
else:
|
|
|
|
|
WorldManager.rootNode.add_child(cloned)
|
|
|
|
|
return cloned
|