36 lines
876 B
GDScript
Executable File
36 lines
876 B
GDScript
Executable File
extends Control
|
|
const DefaultDisplay = preload("InspectorDisplay.tscn")
|
|
const DefaultControl = preload("InspectorControl.tscn")
|
|
const DefaultSpacer = preload("InspectorSpacer.tscn")
|
|
|
|
@export var target: Node2D
|
|
|
|
func _ready():
|
|
if target:
|
|
setTarget(target)
|
|
|
|
func setTarget(newTarget):
|
|
target = newTarget
|
|
|
|
for child in get_children():
|
|
child.queue_free()
|
|
|
|
var definition = target.getInspecctorDefinition()
|
|
for spec in definition:
|
|
if 'type' in spec:
|
|
match (spec.type):
|
|
'spacer':
|
|
add_child(DefaultSpacer.instantiate())
|
|
continue
|
|
|
|
var node = (DefaultControl if spec.editable else DefaultDisplay).instantiate()
|
|
node.property = spec.property
|
|
node.target = target
|
|
node.label = spec.label
|
|
if 'min' in spec:
|
|
node.min = spec.min
|
|
if 'max' in spec:
|
|
node.max = spec.max
|
|
add_child(node)
|
|
|