Fix para los items que no caen
This commit is contained in:
1 parent
e1e29f02f1
commit
aeb5b324f1
28 files changed
+194
-54
No files matched your search
@@ -0,0 +1,62 @@
|
||||
"""Validate Godot pickup resources before exporting Android.
|
||||
|
||||
Godot's serialized .tres files only accept Color(r, g, b, a) with numeric
|
||||
arguments. The GDScript syntax Color("#hex") is *not* valid here and caused
|
||||
all item data to fail to load (white squares named "Item").
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DATA = ROOT / "pickups" / "data"
|
||||
NUM = r"[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?"
|
||||
COLOR = re.compile(rf'color\s*=\s*Color\(\s*({NUM})\s*,\s*({NUM})\s*,\s*({NUM})\s*,\s*({NUM})\s*\)')
|
||||
|
||||
|
||||
class PickupResourceTests(unittest.TestCase):
|
||||
def test_all_pickups_have_serializable_colors(self):
|
||||
resources = sorted(DATA.glob("*.tres"))
|
||||
self.assertEqual(len(resources), 18, "17 rewards plus one laboratory control")
|
||||
for path in resources:
|
||||
with self.subTest(path=path.name):
|
||||
content = path.read_text(encoding="utf-8")
|
||||
color = COLOR.search(content)
|
||||
self.assertIsNotNone(
|
||||
color,
|
||||
"A .tres color must use four numeric components, not Color('#hex')",
|
||||
)
|
||||
self.assertTrue(all(0.0 <= float(v) <= 1.0 for v in color.groups()))
|
||||
|
||||
def test_item_resources_have_valid_identifiers_names_and_images(self):
|
||||
names = set()
|
||||
for path in sorted(DATA.glob("*.tres")):
|
||||
with self.subTest(path=path.name):
|
||||
content = path.read_text(encoding="utf-8")
|
||||
identifier = re.search(r'^id = &"([^"]+)"$', content, re.M)
|
||||
title = re.search(r'^display_name = "([^"]+)"$', content, re.M)
|
||||
image = re.search(r'\[ext_resource type="Texture2D" path="res://([^"]+)"', content)
|
||||
self.assertIsNotNone(identifier)
|
||||
self.assertIsNotNone(title)
|
||||
self.assertIsNotNone(image)
|
||||
self.assertNotEqual(title.group(1), "Item")
|
||||
self.assertNotIn(identifier.group(1), names)
|
||||
names.add(identifier.group(1))
|
||||
self.assertTrue((ROOT / image.group(1)).is_file())
|
||||
|
||||
def test_runtime_pickups_detect_player_and_only_drops_have_a_delay(self):
|
||||
scene = (ROOT / "pickups/pickup.tscn").read_text(encoding="utf-8")
|
||||
pickup = (ROOT / "pickups/pickup.gd").read_text(encoding="utf-8")
|
||||
drop_manager = (ROOT / "pickups/drop_manager.gd").read_text(encoding="utf-8")
|
||||
laboratory = (ROOT / "levels/level_01.gd").read_text(encoding="utf-8")
|
||||
self.assertIn("collision_mask = 2", scene)
|
||||
self.assertIn("monitoring = true", scene)
|
||||
self.assertIn("@export var collection_delay_seconds: float = 0.0", pickup)
|
||||
self.assertIn("get_overlapping_bodies()", pickup)
|
||||
for code in (drop_manager, laboratory):
|
||||
self.assertIn("pickup.collection_delay_seconds = Pickup.DROP_COLLECTION_DELAY_SECONDS", code)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -20,7 +20,7 @@ func _run() -> void:
|
||||
await process_frame
|
||||
|
||||
var status: Label = level.get_node("TestHUD/Overlay/Status") as Label
|
||||
if not status.text.contains("LAB DROPS v2"):
|
||||
if not status.text.contains("LAB DROPS v3"):
|
||||
_fail("No se esta ejecutando level_01.gd")
|
||||
return
|
||||
|
||||
@@ -32,6 +32,29 @@ func _run() -> void:
|
||||
if not control.visible or control.get_node("Sprite2D").texture == null:
|
||||
_fail("El pickup de control no tiene icono visible")
|
||||
return
|
||||
if control.get_node("Label").text != control.pickup_data.display_name:
|
||||
_fail("El nombre del pickup sigue siendo Item")
|
||||
return
|
||||
if not control.monitoring or not control.get("_can_collect"):
|
||||
_fail("Un objeto fijo debe ser recogible desde el primer instante")
|
||||
return
|
||||
|
||||
# Test a real collision, not a direct call to collect_pickup(). This used
|
||||
# to fail when monitoring was disabled while the player ran past the item.
|
||||
var player: CharacterBody2D = level.get_node("Player") as CharacterBody2D
|
||||
player.global_position = control.global_position
|
||||
await physics_frame
|
||||
await physics_frame
|
||||
await process_frame
|
||||
if is_instance_valid(control):
|
||||
_fail("El jugador ha tocado el objeto de control, pero no lo ha recogido")
|
||||
return
|
||||
if int(player.get("_shield_hits")) < 1:
|
||||
_fail("El efecto de escudo del objeto de control no se aplico")
|
||||
return
|
||||
if level.collected_items.size() != 0:
|
||||
_fail("El objeto de control no debe contar entre los 17 drops")
|
||||
return
|
||||
|
||||
var enemies: Array[Node] = level.get_node("TestEnemies").get_children()
|
||||
if enemies.size() != 17:
|
||||
@@ -62,8 +85,8 @@ func _run() -> void:
|
||||
return
|
||||
|
||||
var pickups: Array[Node] = get_nodes_in_group("pickup")
|
||||
if pickups.size() != 18:
|
||||
_fail("Se esperaban 17 drops mas el control, hay %d" % pickups.size())
|
||||
if pickups.size() != 17:
|
||||
_fail("Se esperaban 17 drops; el control ya se ha recogido. Hay %d" % pickups.size())
|
||||
return
|
||||
|
||||
var actual_ids: Dictionary = {}
|
||||
@@ -75,8 +98,8 @@ func _run() -> void:
|
||||
if pickup.get_node("Sprite2D").texture == null:
|
||||
_fail("Pickup sin icono: %s" % pickup.pickup_data.id)
|
||||
return
|
||||
if pickup.monitoring:
|
||||
_fail("Pickup activo antes de los 0.75 s: %s" % pickup.pickup_data.id)
|
||||
if not pickup.monitoring or bool(pickup.get("_can_collect")):
|
||||
_fail("El drop debe detectar solapes, pero esperar 0.75 s para recogerse: %s" % pickup.pickup_data.id)
|
||||
return
|
||||
if pickup.pickup_data.id != &"lab_control":
|
||||
actual_ids[pickup.pickup_data.id] = true
|
||||
@@ -86,11 +109,11 @@ func _run() -> void:
|
||||
return
|
||||
|
||||
await create_timer(0.2).timeout
|
||||
if get_nodes_in_group("pickup").size() != 18:
|
||||
if get_nodes_in_group("pickup").size() != 17:
|
||||
_fail("Se duplicaron o perdieron drops al procesar frames adicionales")
|
||||
return
|
||||
|
||||
print("OK LAB DROPS v2: 17 KOs, 17 recompensas distintas, 1 control, 1 senal desconectada")
|
||||
print("OK LAB DROPS: control recogido por colision, 17 KOs, 17 recompensas, 1 senal desconectada")
|
||||
quit(0)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user