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

+84
View File
@@ -0,0 +1,84 @@
@tool
class_name LevelRoot
extends Node2D
## Infraestructura minima de un escenario, no un sistema de eventos.
## La plantilla contiene Player, terreno, decoracion, enemigos y controles.
## Los niveles con reglas propias pueden heredar y llamar a super en sus callbacks.
@export_category("Level")
## Limites locales de camara. El rectangulo se puede ver antes de ejecutar el juego.
@export var camera_bounds: Rect2 = Rect2(0.0, 0.0, 2400.0, 1280.0):
set(value):
camera_bounds = Rect2(value.position, Vector2(maxf(value.size.x, 1.0), maxf(value.size.y, 1.0)))
queue_redraw()
## Recuperacion al caer fuera del mapa. No depende de escudos o invulnerabilidad.
@export var reset_after_fall: bool = true:
set(value):
reset_after_fall = value
queue_redraw()
@export_range(0.0, 2000.0, 16.0) var fall_margin: float = 256.0:
set(value):
fall_margin = value
queue_redraw()
@export var show_editor_bounds: bool = true:
set(value):
show_editor_bounds = value
queue_redraw()
var _level_player: Node2D
var _reload_pending: bool = false
func _ready() -> void:
if Engine.is_editor_hint():
update_configuration_warnings()
return
_level_player = get_node_or_null("Player") as Node2D
if _level_player == null:
push_error("LevelRoot necesita una instancia de player/player.tscn llamada Player.")
return
apply_camera_bounds()
## Se ejecuta despues del _ready del jugador, sin limites ocultos en Camera2D.
func apply_camera_bounds() -> void:
var camera: Camera2D = _level_player.get_node_or_null("Camera2D") as Camera2D
if camera == null:
return
var top_left: Vector2 = to_global(camera_bounds.position)
var bottom_right: Vector2 = to_global(camera_bounds.end)
camera.limit_left = floori(top_left.x)
camera.limit_top = floori(top_left.y)
camera.limit_right = ceili(bottom_right.x)
camera.limit_bottom = ceili(bottom_right.y)
camera.reset_smoothing()
func _process(_delta: float) -> void:
if Engine.is_editor_hint() or not reset_after_fall or _reload_pending:
return
if not is_instance_valid(_level_player):
return
if _level_player.global_position.y > to_global(camera_bounds.end).y + fall_margin:
_reload_pending = true
# La recarga se difiere para no destruir nodos durante un paso de fisica.
get_tree().call_deferred("reload_current_scene")
func _draw() -> void:
if not Engine.is_editor_hint() or not show_editor_bounds:
return
draw_rect(camera_bounds, Color(0.25, 0.8, 1.0, 0.6), false, 2.0)
if reset_after_fall:
var y: float = camera_bounds.end.y + fall_margin
draw_line(Vector2(camera_bounds.position.x, y), Vector2(camera_bounds.end.x, y), Color(1.0, 0.3, 0.3, 0.7), 2.0)
func _get_configuration_warnings() -> PackedStringArray:
var warnings := PackedStringArray()
if not has_node("Player"):
warnings.append("Falta Player. Arrastra player/player.tscn y conserva ese nombre en la raiz del nivel.")
if not scale.is_equal_approx(Vector2.ONE) or not is_zero_approx(rotation):
warnings.append("No escales ni rotes la raiz del nivel; edita las piezas individualmente.")
return warnings