71 lines
2.1 KiB
GDScript
71 lines
2.1 KiB
GDScript
extends CanvasLayer
|
|
|
|
@onready var rect = $ColorRect
|
|
@onready var log_display = $RichTextLabel
|
|
|
|
func _ready():
|
|
rect.modulate.a = 0
|
|
log_display.text = ""
|
|
log_display.visible = false
|
|
# Ensure the rect doesn't block clicks while invisible
|
|
rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
## Combined function to handle both success and error transitions
|
|
func change_scene(target_path: String, is_error: bool = false):
|
|
rect.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
|
|
# Set color based on status
|
|
if is_error:
|
|
rect.color = Color.CRIMSON
|
|
else:
|
|
rect.color = Color.from_string("#364388", Color.BLUE)
|
|
|
|
# Fade In
|
|
var tween_in = create_tween()
|
|
await tween_in.tween_property(rect, "modulate:a", 1.0, 0.3).finished
|
|
|
|
# Display Log
|
|
log_display.visible = true
|
|
var log_file = "res://hex.txt" if is_error else "res://log.txt"
|
|
await display_log_file(log_file)
|
|
|
|
await get_tree().create_timer(0.5).timeout
|
|
|
|
# Change Scene
|
|
var error = get_tree().change_scene_to_file(target_path)
|
|
if error != OK:
|
|
push_error("Failed to load scene: " + target_path)
|
|
|
|
# Cleanup and Fade Out
|
|
log_display.visible = false
|
|
log_display.text = ""
|
|
|
|
var tween_out = create_tween()
|
|
await tween_out.tween_property(rect, "modulate:a", 0.0, 0.5).finished
|
|
rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
func display_log_file(file_path: String):
|
|
if not FileAccess.file_exists(file_path):
|
|
log_display.add_text("ERROR: " + file_path + " not found in build.\n")
|
|
# Check Project -> Export -> Resources -> Filters to include non-resource files
|
|
return
|
|
|
|
var file = FileAccess.open(file_path, FileAccess.READ)
|
|
if not file:
|
|
log_display.add_text("ERROR: Could not open file.\n")
|
|
return
|
|
|
|
# Reading line by line for that "hacker" effect
|
|
while not file.eof_reached():
|
|
var line = file.get_line()
|
|
if line.strip_edges() == "": continue # Skip empty lines if desired
|
|
|
|
log_display.add_text(line + "\n")
|
|
# Auto-scroll to bottom
|
|
log_display.scroll_to_line(log_display.get_line_count())
|
|
|
|
var delay = 0#randf_range(0.0001, 0.00015)
|
|
#if randf() > 0.95:
|
|
#delay += 0.2 # Random "loading" hitch for realism
|
|
|
|
await get_tree().create_timer(delay).timeout
|