forked from kanium/starcheese
71 lines
2.7 KiB
GDScript3
71 lines
2.7 KiB
GDScript3
|
|
extends CanvasLayer
|
||
|
|
|
||
|
|
@onready var debug_console = get_node("/root/Main/DebugConsole")
|
||
|
|
@export var update_interval: float = 0.5 # Time between global debug info updates
|
||
|
|
var update_timer: float = 0.0
|
||
|
|
var global_debug_visible: bool = false
|
||
|
|
var instance_debug_visible: bool = false
|
||
|
|
var debug_label: Label # Declare as a class-level variable
|
||
|
|
|
||
|
|
signal toggle_instance_debug_signal(visible: bool)
|
||
|
|
|
||
|
|
func _ready():
|
||
|
|
# Check for duplicate DebugManager instances
|
||
|
|
var existing_debug_managers = get_tree().get_nodes_in_group("DebugManager")
|
||
|
|
#if existing_debug_managers.size() > 0 and existing_debug_managers[0] != self:
|
||
|
|
#print("Warning: Duplicate DebugManager detected. Removing:", self)
|
||
|
|
#queue_free()
|
||
|
|
# return
|
||
|
|
add_to_group("DebugManager")
|
||
|
|
|
||
|
|
debug_label = Label.new()
|
||
|
|
debug_label.name = "GlobalDebugLabel"
|
||
|
|
debug_label.set_custom_minimum_size(Vector2(300, 0))
|
||
|
|
debug_label.position = Vector2(10, 10) # Position in the top-left corner
|
||
|
|
debug_label.autowrap_mode = TextServer.AUTOWRAP_WORD # Enable word wrapping
|
||
|
|
debug_label.horizontal_alignment = HorizontalAlignment.HORIZONTAL_ALIGNMENT_LEFT
|
||
|
|
debug_label.vertical_alignment = VerticalAlignment.VERTICAL_ALIGNMENT_TOP
|
||
|
|
debug_label.visible = global_debug_visible # Initially hidden
|
||
|
|
add_child(debug_label)
|
||
|
|
print("Global debug label initialized:", debug_label)
|
||
|
|
|
||
|
|
func _input(event: InputEvent) -> void:
|
||
|
|
# Toggle global debug
|
||
|
|
if event.is_action_pressed("toggle_global_debug"):
|
||
|
|
toggle_global_debug()
|
||
|
|
|
||
|
|
# Toggle instance debug
|
||
|
|
if event.is_action_pressed("toggle_instance_debug"):
|
||
|
|
toggle_instance_debug()
|
||
|
|
|
||
|
|
func _process(delta: float):
|
||
|
|
if global_debug_visible:
|
||
|
|
update_timer += delta
|
||
|
|
if update_timer >= update_interval:
|
||
|
|
update_timer = 0.0
|
||
|
|
update_global_debug_info()
|
||
|
|
|
||
|
|
func toggle_global_debug():
|
||
|
|
global_debug_visible = not global_debug_visible
|
||
|
|
debug_label.visible = global_debug_visible
|
||
|
|
if global_debug_visible:
|
||
|
|
update_global_debug_info()
|
||
|
|
print("Toggled global debug to:", global_debug_visible)
|
||
|
|
if debug_console:
|
||
|
|
debug_console.log_message("Toggled global debug to: %s" %[global_debug_visible], Color(1, 0, 0))
|
||
|
|
|
||
|
|
func toggle_instance_debug():
|
||
|
|
instance_debug_visible = not instance_debug_visible
|
||
|
|
emit_signal("toggle_instance_debug_signal", instance_debug_visible)
|
||
|
|
print("Toggling instance debug to:", instance_debug_visible)
|
||
|
|
|
||
|
|
func update_global_debug_info():
|
||
|
|
var info = []
|
||
|
|
info.append("=== GLOBAL DEBUG ===")
|
||
|
|
info.append("FPS: %s" % Engine.get_frames_per_second())
|
||
|
|
info.append("Node Count: %s" % get_tree().get_node_count())
|
||
|
|
info.append("Collectibles: %s" % get_tree().get_nodes_in_group("collectibles").size())
|
||
|
|
info.append("Spaceships: %s" % get_tree().get_nodes_in_group("spaceships").size())
|
||
|
|
info.append("Asteroids: %s" % get_tree().get_nodes_in_group("asteroids").size())
|
||
|
|
debug_label.text = String("\n").join(info)
|