@tool extends EditorPlugin const _tool_json_root_path := "res://.tbl" func _enter_tree() -> void: var helper := preload('tblext.gd') var base_dir: String = helper.resource_path.get_base_dir() var tools_dir := base_dir.path_join('editor/tools') var dir := DirAccess.open(tools_dir) for file in dir.get_files(): if file.get_extension() == 'rb': var json_path := _tool_json_root_path.path_join(file.get_basename()) + '.json' if FileAccess.file_exists(json_path): make_panel(ProjectSettings.globalize_path(json_path), ProjectSettings.globalize_path(dir.get_current_dir().path_join(file))) func make_panel(tool_json_path:String, tool_script_path:String) -> VBoxContainer: var panel := VBoxContainer.new() var tool_json = JSON.parse_string(FileAccess.get_file_as_string(tool_json_path)) var options = tool_json.options for option in options: if option.value is String: var comment := Label.new() var line_edit := LineEdit.new() comment.text = option.comment line_edit.text = option.value panel.add_child(comment) panel.add_child(line_edit) panel.tree_exiting.connect(func(): option.value = line_edit.text ) elif option.value is int: var comment := Label.new() var range := SpinBox.new() comment.text = option.comment range.value = option.value range.step = 1 range.min_value = -65535 range.max_value = 65535 panel.add_child(comment) panel.add_child(range) panel.tree_exiting.connect(func(): option.value = int(range.value) ) elif option.value is float: var comment := Label.new() var range := SpinBox.new() comment.text = option.comment range.value = option.value panel.add_child(comment) panel.add_child(range) panel.tree_exiting.connect(func(): option.value = range.value ) elif option.value is bool: var check_box := CheckBox.new() check_box.text = option.comment check_box.button_pressed = option.value panel.add_child(check_box) panel.tree_exiting.connect(func(): option.value = check_box.button_pressed ) else: print("unsupported option value({0}): {1}".format([option.name, typeof(option.value)])) var command := Button.new() command.text = tool_json.command_name command.button_up.connect(func(): OS.execute('ruby', [tool_script_path]) ) panel.add_child(command) panel.name = tool_json.title add_control_to_dock(DOCK_SLOT_LEFT_BR, panel) panel.tree_exited.connect(func(): var json := FileAccess.open(tool_json_path, FileAccess.WRITE) json.store_string(JSON.stringify(tool_json, "\t")) ) tree_exiting.connect(func(): remove_control_from_docks(panel) panel.queue_free() ) return panel