tblext.gd 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. @tool
  2. extends EditorPlugin
  3. func _enter_tree() -> void:
  4. var helper := preload('tblext.gd')
  5. var base_dir: String = helper.resource_path.get_base_dir()
  6. make_panel(load(base_dir.path_join('editor/tools/config-importer.tres')))
  7. func make_panel(dev_tool:DevTool) -> VBoxContainer:
  8. var panel := VBoxContainer.new()
  9. var options := JSON.parse_string(FileAccess.get_file_as_string(dev_tool.tool_config))
  10. for option in options:
  11. if option.value is String:
  12. var comment := Label.new()
  13. var line_edit := LineEdit.new()
  14. comment.text = option.comment
  15. line_edit.text = option.value
  16. panel.add_child(comment)
  17. panel.add_child(line_edit)
  18. panel.tree_exiting.connect(func():
  19. option.value = line_edit.text
  20. )
  21. elif option.value is bool:
  22. var check_box := CheckBox.new()
  23. check_box.text = option.comment
  24. check_box.button_pressed = option.value
  25. panel.add_child(check_box)
  26. panel.tree_exiting.connect(func():
  27. option.value = check_box.button_pressed
  28. )
  29. var command := Button.new()
  30. command.text = dev_tool.tool_command_name
  31. command.button_up.connect(func():
  32. OS.execute('ruby', [dev_tool.tool_script])
  33. )
  34. panel.add_child(command)
  35. panel.name = dev_tool.tool_name
  36. add_control_to_dock(dev_tool.tool_dock, panel)
  37. panel.tree_exited.connect(func():
  38. var json := FileAccess.open(dev_tool.tool_config, FileAccess.WRITE)
  39. json.store_string(JSON.stringify(options, "\t"))
  40. )
  41. tree_exiting.connect(func():
  42. remove_control_from_docks(panel)
  43. panel.queue_free()
  44. )
  45. return panel