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.
This commit is contained in:
parent
05c67aa19e
commit
5cf4cd512c
6 changed files with 3756 additions and 0 deletions
30
UI/Controls/script_editor.gd
Normal file
30
UI/Controls/script_editor.gd
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue