config-importer.tscn 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. [gd_scene load_steps=2 format=3 uid="uid://c7m7hu5uvgbit"]
  2. [sub_resource type="GDScript" id="GDScript_d7xax"]
  3. script/source = "@tool
  4. extends Control
  5. var path: String
  6. var _config_path: String
  7. var _config := ConfigFile.new()
  8. var _task: Thread
  9. @export_file('*.rb')
  10. var _tool_file: String
  11. const _config_section := 'CONFIG'
  12. func _enter_tree() -> void:
  13. if path.is_empty():
  14. return
  15. _config_path = path.path_join('config-importer.ini')
  16. _config.load(_config_path)
  17. $config_path.text = _config.get_value(_config_section, 'config_path', '')
  18. $output_path.text = _config.get_value(_config_section, 'output_path', '')
  19. $generate_code_path.text = _config.get_value(_config_section, 'generate_code_path', '')
  20. $generate_text_path.text = _config.get_value(_config_section, 'generate_text_path', '')
  21. $generate_field_info.button_pressed = _config.get_value(_config_section, 'generate_field_info', true)
  22. func _exit_tree() -> void:
  23. if path.is_empty():
  24. return
  25. _config_save()
  26. func _config_save() -> void:
  27. _config.set_value(_config_section, 'config_path', $config_path.text)
  28. _config.set_value(_config_section, 'output_path', $output_path.text)
  29. _config.set_value(_config_section, 'generate_code_path', $generate_code_path.text)
  30. _config.set_value(_config_section, 'generate_text_path', $generate_text_path.text)
  31. _config.set_value(_config_section, 'generate_field_info', $generate_field_info.button_pressed)
  32. _config.save(_config_path)
  33. func _process(delta) -> void:
  34. if _task == null || !_task.is_alive():
  35. if _task != null && !_task.is_alive():
  36. _task.wait_to_finish()
  37. _task = null
  38. scale = Vector2.ONE
  39. func _setup_task(task:Callable) -> void:
  40. scale = Vector2.ZERO
  41. _task = Thread.new()
  42. _task.start(task)
  43. func _recreate_dir(full_path:String) -> void:
  44. if DirAccess.dir_exists_absolute(full_path):
  45. OS.move_to_trash(full_path)
  46. DirAccess.make_dir_recursive_absolute(full_path)
  47. func _on_import_perform_button_down() -> void:
  48. _setup_task(perform)
  49. func perform():
  50. var full_output_path := ProjectSettings.globalize_path($output_path.text)
  51. var full_gen_code_path := ProjectSettings.globalize_path($generate_code_path.text)
  52. var full_gen_text_path := ProjectSettings.globalize_path($generate_text_path.text)
  53. var params: PackedStringArray = [
  54. ProjectSettings.globalize_path(_tool_file),
  55. ProjectSettings.globalize_path($config_path.text),
  56. ProjectSettings.globalize_path($output_path.text),
  57. full_gen_code_path,
  58. full_gen_text_path,
  59. $generate_field_info.button_pressed
  60. ]
  61. for i in range(0, len(params)):
  62. params[i] = ('\"' + params[i] + '\"').strip_edges()
  63. _recreate_dir(full_output_path)
  64. _recreate_dir(full_gen_code_path)
  65. _recreate_dir(full_gen_text_path)
  66. OS.execute('ruby', params)
  67. "
  68. [node name="配置" type="VBoxContainer"]
  69. anchors_preset = 15
  70. anchor_right = 1.0
  71. anchor_bottom = 1.0
  72. grow_horizontal = 2
  73. grow_vertical = 2
  74. script = SubResource("GDScript_d7xax")
  75. _tool_file = "res://addons/godot-TBL-extension-base/editor/tools/config-importer.rb"
  76. [node name="config_path" type="LineEdit" parent="."]
  77. layout_mode = 2
  78. placeholder_text = "配置路径"
  79. [node name="output_path" type="LineEdit" parent="."]
  80. layout_mode = 2
  81. placeholder_text = "ini 生成路径"
  82. [node name="generate_code_path" type="LineEdit" parent="."]
  83. layout_mode = 2
  84. placeholder_text = "代码生成路径"
  85. [node name="generate_text_path" type="LineEdit" parent="."]
  86. layout_mode = 2
  87. placeholder_text = "文本表生成路径"
  88. [node name="generate_field_info" type="CheckBox" parent="."]
  89. layout_mode = 2
  90. button_pressed = true
  91. text = "生成所有字段注释"
  92. [node name="import_perform" type="Button" parent="."]
  93. layout_mode = 2
  94. text = "读取表格生成配置"
  95. [connection signal="button_down" from="import_perform" to="." method="_on_import_perform_button_down"]