♻️REFACTOR: Mejoras en la viabilidad para desarrollo

This commit is contained in:
Diego De la Viuda Llorente committed 2026-10-29 13:23:46 +01:00
1 parent 5aba6c7b47
commit fd0118d964
98 files changed
+5985 -3024

No files matched your search

+53 -10
View File
@@ -1,16 +1,30 @@
@tool
extends Area2D
class_name Pickup
signal picked_up(pickup: Pickup, data: PickupData)
# Enemies leave their reward on screen briefly. A player who touches it during
# that interval must still receive it, even if they keep running.
# Los drops permanecen visibles brevemente antes de poder recogerse.
# Se recuerda al jugador que los toque durante esa espera, aunque continue corriendo.
const DROP_COLLECTION_DELAY_SECONDS: float = 0.75
@export var pickup_data: PickupData
## Recurso compartido de efecto; para cambiar solo esta instancia, hazlo unico.
@export var pickup_data: PickupData:
set(value):
if pickup_data != null and pickup_data.changed.is_connected(_update_preview):
pickup_data.changed.disconnect(_update_preview)
pickup_data = value
if pickup_data != null and not pickup_data.changed.is_connected(_update_preview):
pickup_data.changed.connect(_update_preview)
if is_inside_tree():
call_deferred("_update_preview")
## Espera antes de permitir la recogida; los objetos colocados usan cero.
@export var collection_delay_seconds: float = 0.0
## Aceleracion de caida del objeto; conserva el comportamiento previo.
@export var fall_speed: float = 150.0
## Amplitud vertical de la oscilacion al apoyarse en el suelo.
@export var bob_amplitude: float = 4.0
## Velocidad angular de esa oscilacion.
@export var bob_speed: float = 3.0
var velocity: Vector2 = Vector2.ZERO
@@ -18,14 +32,18 @@ var time: float = 0.0
var start_y: float = 0.0
var grounded: bool = false
var _can_collect: bool = false
var _pending_collector: Node2D # Player who crossed the pickup during its delay.
var _pending_collector: Node2D # Jugador que toco el objeto durante la espera.
@onready var label: Label = $Label
@onready var sprite: Sprite2D = $Sprite2D
@onready var placeholder: ColorRect = $Sprite2D/ColorRect
## Prepara la vista previa; solo en partida activa la recogida y sus senales.
func _ready() -> void:
_update_preview()
if Engine.is_editor_hint():
return
add_to_group("pickup")
body_entered.connect(_on_body_entered)
@@ -47,20 +65,23 @@ func _ready() -> void:
_can_collect = true
## Habilita el drop y resuelve un contacto que hubiera ocurrido durante la espera.
func _enable_collection_after_delay() -> void:
await get_tree().create_timer(collection_delay_seconds).timeout
if not is_inside_tree():
return
_can_collect = true
# A body_entered signal received during the delay is not lost. Crossing a
# spawning item counts as touching it, even if the player is now elsewhere.
# No se pierde un contacto recibido durante la espera: atravesar el objeto cuenta como haberlo tocado.
if is_instance_valid(_pending_collector):
_on_body_entered(_pending_collector)
_pending_collector = null
## Hace caer/flotar el objeto y reintenta aplicar efectos mientras el jugador lo toca.
func _physics_process(delta: float) -> void:
if Engine.is_editor_hint():
return
time += delta
if not grounded:
velocity.y += fall_speed * delta
@@ -72,9 +93,8 @@ func _physics_process(delta: float) -> void:
else:
position.y = start_y + sin(time * bob_speed) * bob_amplitude
# body_entered only fires at the start of a contact. Rechecking overlaps
# also handles moving pickups and effects that were unusable on first touch
# (e.g. a heal while HP was full, then the player takes damage).
# body_entered solo avisa al comenzar el contacto. Revisar solapamientos
# permite recoger un objeto cuando pasa a ser util sin exigir salir y volver a entrar.
if pickup_data != null and not is_queued_for_deletion():
for body in get_overlapping_bodies():
_on_body_entered(body)
@@ -82,6 +102,7 @@ func _physics_process(delta: float) -> void:
break
## Sonda de suelo sobre la capa World; los objetos son areas, no cuerpos fisicos.
func is_on_floor() -> bool:
var space = get_world_2d().direct_space_state
var params = PhysicsRayQueryParameters2D.create(global_position, global_position + Vector2(0, 12))
@@ -90,6 +111,7 @@ func is_on_floor() -> bool:
return result.size() > 0
## Consume el objeto solo cuando Player confirma que se ha aplicado su efecto.
func _on_body_entered(body: Node2D) -> void:
if pickup_data == null or is_queued_for_deletion():
return
@@ -104,7 +126,28 @@ func _on_body_entered(body: Node2D) -> void:
picked_up.emit(self, pickup_data)
queue_free()
elif pickup_data.effect_type == "heal":
# This is not a collision failure: the player already has full HP.
# No es un fallo de colision: el jugador ya tiene la vida completa.
label.text = "%s\n(HP LLENO)" % pickup_data.display_name
elif pickup_data.effect_type == "special_charge":
label.text = "%s\n(ESPECIAL LLENO)" % pickup_data.display_name
## Actualiza exclusivamente la presentacion; nunca consume objetos en el editor.
func _update_preview() -> void:
if not is_inside_tree() or not has_node("Label"):
return
var preview_label: Label = $Label
var preview_sprite: Sprite2D = $Sprite2D
var preview_placeholder: ColorRect = $Sprite2D/ColorRect
preview_label.text = pickup_data.display_name if pickup_data != null else "SIN DATOS"
preview_sprite.texture = pickup_data.icon if pickup_data != null else null
preview_placeholder.visible = preview_sprite.texture == null
preview_placeholder.color = pickup_data.color if pickup_data != null else Color.MAGENTA
update_configuration_warnings()
## Avisa en el arbol del editor cuando falta el recurso de datos.
func _get_configuration_warnings() -> PackedStringArray:
if pickup_data == null:
return PackedStringArray(["Asigna Pickup Data o arrastra una escena de pickups/variants."])
return PackedStringArray()