godot-plateformer/addons/reedscene/scene/ReedSceneIDInspector.gd

32 lines
732 B
GDScript

@tool
extends EditorInspectorPlugin
func _can_handle(object) -> bool:
return object is ReedSceneID
func _parse_begin(object):
var button := Button.new()
button.text = "Request Scene ID"
button.pressed.connect(func():
_request_id(object)
)
add_custom_control(button)
func _request_id(id_comp: ReedSceneID):
var scene := id_comp.get_owner()
if scene == null:
push_error("[ReedSceneID] Cannot find owning scene")
return
var scene_path := scene.scene_file_path
if scene_path == "":
push_error("[ReedSceneID] Scene must be saved before requesting ID")
return
var id := ReedSceneIDEditorSystem.request_id_for_scene(scene_path)
if id < 0:
return
id_comp.scene_id = id
id_comp.notify_property_list_changed()