|
@@ -9,6 +9,9 @@ var _config_path: String
|
|
|
var _config := ConfigFile.new()
|
|
|
var _task: Thread
|
|
|
|
|
|
+@export_file('*.rb')
|
|
|
+var _tool_file: String
|
|
|
+
|
|
|
const _config_section := 'CONFIG'
|
|
|
|
|
|
func _enter_tree() -> void:
|
|
@@ -19,6 +22,7 @@ func _enter_tree() -> void:
|
|
|
$config_path.text = _config.get_value(_config_section, 'config_path', '')
|
|
|
$output_path.text = _config.get_value(_config_section, 'output_path', '')
|
|
|
$generate_code_path.text = _config.get_value(_config_section, 'generate_code_path', '')
|
|
|
+ $generate_text_path.text = _config.get_value(_config_section, 'generate_text_path', '')
|
|
|
$generate_field_info.button_pressed = _config.get_value(_config_section, 'generate_field_info', true)
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
@@ -30,6 +34,7 @@ func _config_save() -> void:
|
|
|
_config.set_value(_config_section, 'config_path', $config_path.text)
|
|
|
_config.set_value(_config_section, 'output_path', $output_path.text)
|
|
|
_config.set_value(_config_section, 'generate_code_path', $generate_code_path.text)
|
|
|
+ _config.set_value(_config_section, 'generate_text_path', $generate_text_path.text)
|
|
|
_config.set_value(_config_section, 'generate_field_info', $generate_field_info.button_pressed)
|
|
|
_config.save(_config_path)
|
|
|
|
|
@@ -45,90 +50,32 @@ func _setup_task(task:Callable) -> void:
|
|
|
_task = Thread.new()
|
|
|
_task.start(task)
|
|
|
|
|
|
-class ConfigField:
|
|
|
- var column_id: int
|
|
|
- var name: String
|
|
|
- var comment: String
|
|
|
- var default_record: String
|
|
|
-
|
|
|
- static func parse(file_access:FileAccess):
|
|
|
- var fields := []
|
|
|
- var names := file_access.get_csv_line()
|
|
|
- var comments := file_access.get_csv_line()
|
|
|
- var infos := file_access.get_csv_line()
|
|
|
- for i in range(0, len(names)):
|
|
|
- if (names[i].is_empty()):
|
|
|
- continue
|
|
|
- var field := ConfigField.new()
|
|
|
- field.column_id = i
|
|
|
- field.name = names[i]
|
|
|
- field.comment = comments[i]
|
|
|
- fields.push_back(field)
|
|
|
- return fields
|
|
|
-
|
|
|
- static func pick(fields, id):
|
|
|
- for field in fields:
|
|
|
- if field.name == id:
|
|
|
- return field
|
|
|
- return null
|
|
|
-
|
|
|
func _recreate_dir(full_path:String) -> void:
|
|
|
if DirAccess.dir_exists_absolute(full_path):
|
|
|
OS.move_to_trash(full_path)
|
|
|
DirAccess.make_dir_recursive_absolute(full_path)
|
|
|
|
|
|
func _on_import_perform_button_down() -> void:
|
|
|
+ _setup_task(perform)
|
|
|
+
|
|
|
+func perform():
|
|
|
var full_output_path := ProjectSettings.globalize_path($output_path.text)
|
|
|
var full_gen_code_path := ProjectSettings.globalize_path($generate_code_path.text)
|
|
|
-
|
|
|
+ var full_gen_text_path := ProjectSettings.globalize_path($generate_text_path.text)
|
|
|
+ var params: PackedStringArray = [
|
|
|
+ ProjectSettings.globalize_path(_tool_file),
|
|
|
+ ProjectSettings.globalize_path($config_path.text),
|
|
|
+ ProjectSettings.globalize_path($output_path.text),
|
|
|
+ full_gen_code_path,
|
|
|
+ full_gen_text_path,
|
|
|
+ $generate_field_info.button_pressed
|
|
|
+ ]
|
|
|
+ for i in range(0, len(params)):
|
|
|
+ params[i] = ('\"' + params[i] + '\"').strip_edges()
|
|
|
_recreate_dir(full_output_path)
|
|
|
_recreate_dir(full_gen_code_path)
|
|
|
-
|
|
|
- _setup_task(func():
|
|
|
- var dir_access := DirAccess.open($config_path.text)
|
|
|
- var gen_script := FileAccess.open($generate_code_path.text.path_join('config') + '.gen.gd', FileAccess.WRITE)
|
|
|
- for config_type in dir_access.get_directories():
|
|
|
- var config_type_dir: String = $config_path.text.path_join(config_type)
|
|
|
- var config_dir_access := DirAccess.open(config_type_dir)
|
|
|
- var ini := FileAccess.open($output_path.text.path_join(config_type) + '.ini', FileAccess.WRITE)
|
|
|
- for config_file in config_dir_access.get_files():
|
|
|
- if config_file.get_extension() != 'csv':
|
|
|
- continue
|
|
|
- var file_access := FileAccess.open(config_type_dir.path_join(config_file), FileAccess.READ)
|
|
|
- var fields = ConfigField.parse(file_access)
|
|
|
- var id_field = ConfigField.pick(fields, 'Id')
|
|
|
- var id_name_field = ConfigField.pick(fields, 'IdName')
|
|
|
- var config_title := config_file.get_basename()
|
|
|
- var config_class_name := config_title.capitalize().replace(' ', '')
|
|
|
- fields.erase(id_field)
|
|
|
- fields.erase(id_name_field)
|
|
|
-
|
|
|
- ini.store_line('; --------------- {0} ---------------'.format([config_title]))
|
|
|
-
|
|
|
- if $generate_field_info.button_pressed:
|
|
|
- ini.store_line('; {0} data fields:'.format([config_title]))
|
|
|
- for field in fields:
|
|
|
- ini.store_line('; {0}={1} ; {2}'.format([field.name, field.default_record, field.comment]))
|
|
|
- ini.store_line('')
|
|
|
-
|
|
|
- gen_script.store_line('class {0}:'.format([config_class_name]))
|
|
|
- for field in fields:
|
|
|
- gen_script.store_line('\\t# {0}'.format([field.name]))
|
|
|
-
|
|
|
- while !file_access.eof_reached():
|
|
|
- var line := file_access.get_csv_line()
|
|
|
- ini.store_line('[{0}]'.format([line[id_field.column_id]]))
|
|
|
- for field in fields:
|
|
|
- var i:int = field.column_id
|
|
|
- var is_use_default := line[i].is_empty()
|
|
|
- if is_use_default:
|
|
|
- continue
|
|
|
- ini.store_line('{0}={1}'.format([field.name, line[field.column_id]]))
|
|
|
- ini.store_line('')
|
|
|
-
|
|
|
- gen_script.store_line('\\tpass')
|
|
|
- gen_script.store_line('')
|
|
|
- )
|
|
|
+ _recreate_dir(full_gen_text_path)
|
|
|
+ OS.execute('ruby', params)
|
|
|
"
|
|
|
|
|
|
[node name="配置" type="VBoxContainer"]
|
|
@@ -138,6 +85,7 @@ anchor_bottom = 1.0
|
|
|
grow_horizontal = 2
|
|
|
grow_vertical = 2
|
|
|
script = SubResource("GDScript_d7xax")
|
|
|
+_tool_file = "res://addons/godot-TBL-extension-base/editor/tools/config-importer.rb"
|
|
|
|
|
|
[node name="config_path" type="LineEdit" parent="."]
|
|
|
layout_mode = 2
|
|
@@ -151,6 +99,10 @@ placeholder_text = "ini 生成路径"
|
|
|
layout_mode = 2
|
|
|
placeholder_text = "代码生成路径"
|
|
|
|
|
|
+[node name="generate_text_path" type="LineEdit" parent="."]
|
|
|
+layout_mode = 2
|
|
|
+placeholder_text = "文本表生成路径"
|
|
|
+
|
|
|
[node name="generate_field_info" type="CheckBox" parent="."]
|
|
|
layout_mode = 2
|
|
|
button_pressed = true
|