Fix para los items que no caen #24

Merged
ankdev merged 1 commits from feature/ia_automated_test into main 2026-10-21 09:22:25 +00:00
9 changed files with 144 additions and 1468 deletions
Showing only changes of commit 5012879591 - Show all commits

No files matched your search

+6
View File
@@ -1978,6 +1978,12 @@ Recorrido de Android (17 estaciones, orden y checklist):
Comprobacion estatica reproducible (sin arrancar Godot):
`python -m unittest discover -s tests -v`.
Prueba de drops dentro del motor (necesita Godot instalado):
`godot --headless --path . --script res://tests/test_pickup_runtime.gd`.
Esta comprobacion crea los 17 drops garantizados y verifica sus recursos,
iconos y presencia en escena. Los pickups se generan fuera de la fase de
colisiones y no se pueden recoger durante sus primeros 0,75 segundos.
La escena de inicio del proyecto ya es `levels/level_01.tscn`.
Para exportar una APK de pruebas, revisa las instrucciones de
`scripts/export_android_debug.sh` y el preset de Android (requiere SDK y
+24
View File
@@ -99,3 +99,27 @@ Para generar un APK en un entorno que tenga Godot y el SDK Android configurados:
El script admite una ruta de salida opcional; por defecto escribe
`build/android/mortal-maze-debug.apk`. No se ha compilado la APK aqui.
## Diagnostico de los drops
El HUD muestra **KOs**, **DROPS EN SUELO** y **objetos recogidos** por separado.
Al matar al primer enemigo deberias ver 1 KO y, durante al menos 0,75 s,
un objeto visible en el suelo. Tras recogerlo, el numero de recogidos sube
si su efecto puede aplicarse. Los objetos de curacion no se consumen a vida
completa y los de carga especial no se consumen con la barra llena.
Los pickups se agregan al arbol **en diferido** porque un enemigo puede morir
mientras Godot procesa colisiones. Nacen con la deteccion desactivada y la
activan 0,75 s mas tarde para evitar recogidas instantaneas invisibles.
Si en el HUD suben los KOs pero los objetos en suelo siguen en cero y no
suben los recogidos, comprueba si aparecen errores de `guaranteed_drop` al
abrir el nivel y ejecuta la prueba de integracion con Godot:
```bash
godot --headless --path . --script res://tests/test_pickup_runtime.gd
```
Esta prueba mata los 17 enemigos, espera a que se creen sus drops y verifica
que los 17 recursos diferentes existen, son visibles y tienen icono. No
reemplaza la comprobacion visual en Android.
+18 -2
View File
@@ -16,6 +16,7 @@ const FINISH_RESTART_SECONDS: float = 8.0
@onready var finish_message: Label = $TestHUD/Overlay/FinishMessage
var collected_items: Dictionary = {} # PickupData.id -> true; count each only once
var defeated_enemies: int = 0
var showing_victory: bool = false
var victory_timer: float = 0.0
@@ -30,6 +31,12 @@ func _ready() -> void:
$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():
# Catch missing scene overrides as soon as the level starts rather than
# silently falling back to the normal random drop table.
if enemy.get("guaranteed_drop") == null:
push_error("%s has no guaranteed_drop assigned." % enemy.name)
enemy.died.connect(_on_station_enemy_died)
_update_status()
@@ -58,11 +65,20 @@ func _update_status() -> void:
next_item = data.display_name
break
status_label.text = "LAB THRASH %02d / %02d recogidos\nSIGUIENTE: %s" % [
collected_items.size(), TEST_ITEM_COUNT, next_item
# Two independent counters reveal whether an object failed to spawn or
# simply got collected. Useful for diagnosing drops on an Android APK.
var loose_drops: int = get_tree().get_nodes_in_group("pickup").size()
status_label.text = "LAB: %02d/%02d objetos | %02d KOs\nDROPS EN SUELO: %02d\nSIGUIENTE: %s" % [
collected_items.size(), TEST_ITEM_COUNT, defeated_enemies,
loose_drops, next_item
]
func _on_station_enemy_died() -> void:
defeated_enemies += 1
_update_status()
func _on_pickup_collected(data: PickupData) -> void:
# 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.
+1 -1
View File
@@ -412,7 +412,7 @@ anchor_right = 1.0
offset_left = -500.0
offset_top = 16.0
offset_right = -20.0
offset_bottom = 72.0
offset_bottom = 104.0
grow_horizontal = 0
theme_override_colors/font_color = Color(1, 0.93, 0.68, 1)
theme_override_colors/font_shadow_color = Color(0.02, 0.02, 0.02, 0.95)
File diff suppressed because it is too large. Load diff
+12 -2
View File
@@ -45,8 +45,18 @@ static func roll_drop(drop_table: PickupDropTable) -> Array[PickupData]:
static func spawn_drops(drops_data: Array[PickupData], parent: Node, position: Vector2) -> void:
# Death can happen inside a physics collision callback. Adding a new Area2D
# immediately at that point is unsafe: defer its entry into the scene tree.
# Set its local position first so it never briefly enters at the origin.
var local_position: Vector2 = position
if parent is Node2D:
local_position = (parent as Node2D).to_local(position)
for data in drops_data:
if data == null:
push_warning("A drop was requested without PickupData.")
continue
var pickup := PICKUP_SCENE.instantiate() as Pickup
pickup.pickup_data = data
parent.add_child(pickup)
pickup.global_position = position
pickup.position = local_position
parent.call_deferred("add_child", pickup)
+13
View File
@@ -3,6 +3,10 @@ class_name Pickup
signal picked_up(pickup: Pickup, data: PickupData)
# Give players a moment to see the item before it can be collected. Otherwise
# a close-range kill may immediately pick it up inside the player's collision.
const PICKUP_GRACE_SECONDS: float = 0.75
@export var pickup_data: PickupData
@export var fall_speed: float = 150.0
@export var bob_amplitude: float = 4.0
@@ -27,6 +31,15 @@ func _ready() -> void:
placeholder.color = pickup_data.color
start_y = position.y
body_entered.connect(_on_body_entered)
_enable_collection_after_delay()
func _enable_collection_after_delay() -> void:
# The scene starts with monitoring disabled. Enabling it after the initial
# grace period also avoids overlap signals during creation in a physics tick.
await get_tree().create_timer(PICKUP_GRACE_SECONDS).timeout
if is_inside_tree():
monitoring = true
func _physics_process(delta: float) -> void:
+2
View File
@@ -7,8 +7,10 @@
size = Vector2(16, 16)
[node name="Pickup" type="Area2D"]
z_index = 2
collision_layer = 0
collision_mask = 2
monitoring = false
script = ExtResource("1_pickup")
[node name="Sprite2D" type="Sprite2D" parent="."]
+68
View File
@@ -0,0 +1,68 @@
extends SceneTree
## Godot integration smoke test. Run from the project root with:
## godot --headless --path . --script res://tests/test_pickup_runtime.gd
## It checks actual instantiation after enemy death, not merely text in a .tscn.
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var packed_level := load("res://levels/level_01.tscn") as PackedScene
if packed_level == null:
_fail("Could not load Level 01")
return
var level := packed_level.instantiate()
root.add_child(level)
current_scene = level
await process_frame
var enemies := level.get_node("TestEnemies").get_children()
if enemies.size() != 17:
_fail("Expected 17 test enemies, found %d" % enemies.size())
return
var expected_ids: Dictionary = {}
for enemy in enemies:
var item: PickupData = enemy.get("guaranteed_drop") as PickupData
if item == null:
_fail("Missing guaranteed_drop on %s" % enemy.name)
return
expected_ids[item.id] = true
# Force a kill independently of enemy movement, AI and the camera.
enemy.call("take_damage", int(enemy.get("max_health")), Vector2.ZERO)
# Deferred add_child runs during the idle step, after the physics callback.
await create_timer(0.2).timeout
var pickups := get_nodes_in_group("pickup")
if pickups.size() != 17:
_fail("Expected 17 spawned pickups, found %d" % pickups.size())
return
var spawned_ids: Dictionary = {}
for node in pickups:
var pickup := node as Pickup
if pickup == null or pickup.pickup_data == null:
_fail("Spawned a pickup without PickupData")
return
if not pickup.visible or pickup.get_node("Sprite2D").texture == null:
_fail("Pickup has no visible sprite: %s" % pickup.pickup_data.id)
return
if pickup.monitoring:
_fail("Pickup collection activated before grace period: %s" % pickup.pickup_data.id)
return
spawned_ids[pickup.pickup_data.id] = true
if spawned_ids.size() != expected_ids.size() or spawned_ids != expected_ids:
_fail("Drops do not match the 17 assigned resources")
return
print("OK: all 17 guaranteed drops spawned, visible and correctly assigned.")
quit(0)
func _fail(message: String) -> void:
push_error("Pickup runtime test: " + message)
quit(1)