StreamOverlay/UI/Controls/script_editor.gd
Mario Steele 5cf4cd512c Created Test Script Editor
Starting work on allowing for GDScript to code various functionality in
Overlay outside of normal backend code.  Such as event handling, sending
messages, alerts, etc, etc.
2026-02-28 02:39:51 -06:00

30 lines
893 B
GDScript

extends PanelContainer
@onready var run_script: Button = %RunScript
@onready var code_editor: TextEdit = %CodeEditor
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
%CodeEditor.text = "extends OverlayPlugin\n\nfunc run() -> void:\n\tpass"
run_script.pressed.connect(_handle_run_script)
func _handle_run_script() -> void:
var script = GDScript.new()
script.source_code = %CodeEditor.text
var error := script.reload()
if error != OK:
print("Failed to parse script!")
return
var context: Object = script.new()
if not context is OverlayPlugin:
print("Script doesn't inherit from OverlayPlugin!")
if context.has_method(&"queue_free"):
context.queue_free()
elif context is RefCounted:
context = null
else:
context.free()
return
context.ready.connect(func() -> void: context.run(); context.queue_free())
add_child(context)