54 lines
1.6 KiB
GDScript
54 lines
1.6 KiB
GDScript
@tool
|
|
extends Node
|
|
## Componente colocable: escucha la muerte de un jefe y finaliza el LevelRoot.
|
|
## El jefe solo necesita emitir died; no se modifica su script al disenar niveles.
|
|
|
|
@export var boss_path: NodePath:
|
|
set(value):
|
|
boss_path = value
|
|
update_configuration_warnings()
|
|
@export_range(0.0, 10.0, 0.1) var completion_delay: float = 1.5
|
|
@export var victory_message: String = ""
|
|
|
|
var _triggered: bool = false
|
|
|
|
|
|
func _ready() -> void:
|
|
if Engine.is_editor_hint():
|
|
update_configuration_warnings()
|
|
return
|
|
var boss: Node = get_node_or_null(boss_path) if not boss_path.is_empty() else null
|
|
if boss == null or not boss.has_signal(&"died"):
|
|
push_error("BossVictory: Boss Path debe apuntar a un nodo que emita died.")
|
|
return
|
|
boss.connect(&"died", _on_boss_died)
|
|
|
|
|
|
func _on_boss_died() -> void:
|
|
if _triggered:
|
|
return
|
|
_triggered = true
|
|
var level: LevelRoot = LevelRoot.find_for(self)
|
|
if level != null and not victory_message.is_empty():
|
|
level.progress_notice.emit(victory_message)
|
|
get_tree().create_timer(completion_delay).timeout.connect(_finish)
|
|
|
|
|
|
func _finish() -> void:
|
|
if not is_inside_tree():
|
|
return
|
|
var level: LevelRoot = LevelRoot.find_for(self)
|
|
if level != null:
|
|
level.complete_level()
|
|
|
|
|
|
func _get_configuration_warnings() -> PackedStringArray:
|
|
var warnings := PackedStringArray()
|
|
if boss_path.is_empty():
|
|
warnings.append("Asigna Boss Path al jefe que debe morir para completar el nivel.")
|
|
elif is_inside_tree():
|
|
var boss: Node = get_node_or_null(boss_path) if not boss_path.is_empty() else null
|
|
if boss == null or not boss.has_signal(&"died"):
|
|
warnings.append("Boss Path debe apuntar a un nodo con senal died.")
|
|
return warnings
|