♻️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

+32 -49
View File
@@ -1,14 +1,13 @@
extends Node2D
@tool
extends LevelRoot
## Android test course: 17 stations / 17 different guaranteed items.
## Encounters are configured in the scene, not spawned by code.
## This laboratory intentionally owns fixed drops: each death is observed from
## the actual is_dead state, even when a died signal is missed.
## Laboratorio Android: 17 estaciones y 17 objetos garantizados distintos.
## Los encuentros se colocan en la escena. Este nivel observa is_dead
## y gestiona sus propias recompensas aunque no reciba alguna senal died.
signal level_completed
const TEST_ITEM_COUNT: int = 17
const LEVEL_WIDTH: int = 8500
const FINISH_RESTART_SECONDS: float = 8.0
const LAB_BUILD: String = "LAB DROPS v4"
const CONTROL_ITEM_ID: StringName = &"lab_control"
@@ -19,33 +18,32 @@ const PICKUP_SCENE: PackedScene = preload("res://pickups/pickup.tscn")
@onready var status_label: Label = $TestHUD/Overlay/Status
@onready var finish_message: Label = $TestHUD/Overlay/FinishMessage
var collected_items: Dictionary = {} # PickupData.id -> true; count each only once
var collected_items: Dictionary = {} # PickupData.id -> true; cuenta cada objeto una sola vez.
var defeated_enemies: int = 0
var death_signals: int = 0
var spawned_drops: int = 0
var _processed_deaths: Dictionary = {} # enemy instance id -> true
var _processed_deaths: Dictionary = {} # Identificador de instancia enemiga -> muerte ya procesada.
var showing_victory: bool = false
var victory_timer: float = 0.0
## Configura las estaciones sin alterar las recompensas del resto de niveles.
func _ready() -> void:
# These two markers distinguish an actually loaded script from an old APK.
super._ready()
if Engine.is_editor_hint():
return
# Estos marcadores distinguen la version cargada de una instalacion antigua del APK.
status_label.text = "%s: script iniciado" % LAB_BUILD
print("%s: Level01 script iniciado" % LAB_BUILD)
finish_message.visible = false
# Player Camera2D sets its own provisional limit (4000) in _ready.
# Override it here, after child _ready, for the long Android route.
var camera: Camera2D = player.get_node("Camera2D") as Camera2D
camera.limit_right = LEVEL_WIDTH
$FinishZone.body_entered.connect(_on_finish_entered)
$DeathZone.body_entered.connect(_on_death_entered)
player.connect(&"pickup_collected", _on_pickup_collected)
for enemy in test_enemies.get_children():
# Keep item-testing stations isolated despite the stronger game profiles.
# Mantiene aisladas las estaciones aunque las variantes normales persigan a mayor distancia.
enemy.set("chase_radius", 135.0)
# The laboratory, not Walker, owns the fixed drop. Only this level sets
# the flag: normal enemies still generate their usual random drops.
# Solo el laboratorio asume la recompensa fija; los enemigos normales conservan sus propios drops.
enemy.set("drops_handled_by_level", true)
if enemy.get("guaranteed_drop") == null:
push_error("%s has no guaranteed_drop assigned." % enemy.name)
@@ -56,9 +54,12 @@ func _ready() -> void:
_update_status()
## Observa muertes y actualiza el diagnostico; tras completar, cuenta hasta reiniciar.
func _process(delta: float) -> void:
# Do not depend on the died signal to count KOs or create the object.
# A transition to is_dead can only be processed once per enemy.
super._process(delta)
if Engine.is_editor_hint():
return
# El recuento y las recompensas no dependen de died. Cada muerte se procesa una sola vez.
_process_station_deaths()
if showing_victory:
victory_timer += delta
@@ -69,9 +70,9 @@ func _process(delta: float) -> void:
_update_status()
## Muestra progreso, estado de drops y siguiente recompensa.
func _update_status() -> void:
# Each station has one enemy and an assigned pickup. Look ahead to the first
# living enemy so the player knows what to expect without opening a menu.
# Busca la primera estacion viva por delante para anticipar su recompensa en el HUD.
var next_item: String = "FIN DEL RECORRIDO"
for enemy in test_enemies.get_children():
if bool(enemy.get("is_dead")):
@@ -84,8 +85,7 @@ func _update_status() -> void:
next_item = data.display_name
break
# S is the number of died signals received. KOs come from is_dead,
# not signals. A difference between them pinpoints a signal problem.
# Compara senales con muertes reales: una diferencia permite diagnosticar senales perdidas.
var loose_drops: int = get_tree().get_nodes_in_group("pickup").size()
status_label.text = "%s | %02d/%02d objetos\nKOs: %02d | Senales: %02d | Creados: %02d | Suelo: %02d\nSIGUIENTE: %s" % [
LAB_BUILD, collected_items.size(), TEST_ITEM_COUNT,
@@ -93,6 +93,7 @@ func _update_status() -> void:
]
## Convierte cada nueva muerte en un unico objeto garantizado.
func _process_station_deaths() -> void:
for enemy in test_enemies.get_children():
if not bool(enemy.get("is_dead")):
@@ -108,8 +109,8 @@ func _process_station_deaths() -> void:
push_error("%s: %s ha muerto sin objeto asignado" % [LAB_BUILD, enemy.name])
continue
# Adding an Area2D during a physics step is unsafe. Set position and
# data before adding it, then defer its entry into the scene tree.
# Prepara posicion y datos antes de diferir la entrada al arbol.
# No se debe anadir un Area2D durante la resolucion de contactos fisicos.
var pickup: Pickup = PICKUP_SCENE.instantiate() as Pickup
pickup.pickup_data = data
pickup.collection_delay_seconds = Pickup.DROP_COLLECTION_DELAY_SECONDS
@@ -119,22 +120,23 @@ func _process_station_deaths() -> void:
print("%s: KO %s -> %s" % [LAB_BUILD, enemy.name, data.display_name])
## Cuenta senales para compararlas con las muertes observadas.
func _on_station_enemy_died() -> void:
# Diagnostic counter only; the actual reward is managed above.
# Contador diagnostico; la recompensa se procesa por separado al observar is_dead.
death_signals += 1
## Cuenta identificadores distintos de recompensas realmente aplicadas.
func _on_pickup_collected(data: PickupData) -> void:
# The extra pickup at the start checks rendering and collection independently
# of enemy deaths. It is not one of the 17 rewards.
# El objeto inicial verifica imagen y recogida sin matar enemigos; no cuenta entre las 17 recompensas.
if data.id == CONTROL_ITEM_ID:
return
# A heal at full HP or a charge item with a full meter isn't consumed and
# doesn't count. The object remains on the floor for later collection.
# Una curacion con vida llena o carga ya completa no consume el objeto ni aumenta el recuento.
collected_items[data.id] = true
_update_status()
## Completa el laboratorio al entrar el jugador en la meta.
func _on_finish_entered(body: Node2D) -> void:
if body != player or showing_victory:
return
@@ -146,26 +148,7 @@ func _on_finish_entered(body: Node2D) -> void:
finish_message.visible = true
## Aplica el comportamiento original del area de caida del laboratorio.
func _on_death_entered(body: Node2D) -> void:
if body == player and body.has_method("take_damage"):
body.take_damage(9999, body.global_position)
func _draw() -> void:
# Temporary coloured geometry; collision shapes are the single source of
# truth for position and dimensions, so the visuals cannot desynchronise.
for child in $World.get_children():
if not child is CollisionShape2D:
continue
var collision: CollisionShape2D = child as CollisionShape2D
var rectangle: RectangleShape2D = collision.shape as RectangleShape2D
if rectangle == null:
continue
var color: Color = Color(0.32, 0.57, 0.79)
if collision.name == "Floor":
color = Color(0.20, 0.40, 0.25)
elif collision.name.begins_with("High"):
color = Color(0.68, 0.39, 0.76)
var rect: Rect2 = Rect2(collision.position - rectangle.size / 2.0, rectangle.size)
draw_rect(rect, color, true)
draw_rect(rect, Color(0.93, 0.94, 1.0, 0.6), false, 2.0)