Skip to content

Commit

Permalink
Merge pull request #3 from kaluluosi/2-在godot42中似乎有问题
Browse files Browse the repository at this point in the history
2 在godot42中似乎有问题
  • Loading branch information
kaluluosi authored Dec 9, 2023
2 parents 9022e58 + b78e042 commit 6bf8de5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion addons/GDExcelExporter/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ description="GDExcelExporter插件,用来在Godot里面调用ee命令导出项
1. 先去项目设置>GDExcelExporter里设置你配置表项目目录路径
2. 项目>工具>ExcelExport 导出目录中的Excel表"
author="kaluluosi"
version="1.1"
version="1.2"
script="plugin.gd"
54 changes: 31 additions & 23 deletions addons/GDExcelExporter/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ extends EditorPlugin
var btn_export:Button = null


var settings_dir = {
var settings_dir_property = {
"name": "GDExcelExporter/SettingsDir",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_DIR,
"hint_string": "配置表所在目录"
}
var ee_path = {
var ee_path_property = {
"name": "GDExcelExporter/cmd_path",
"type":TYPE_STRING,
"hint": PROPERTY_HINT_DIR,
Expand All @@ -21,15 +21,15 @@ var _dialog_size:Vector2i = Vector2i(500,200)

func _enter_tree():

if not ProjectSettings.has_setting(settings_dir.name):
ProjectSettings.add_property_info(settings_dir)
ProjectSettings.set_initial_value(settings_dir.name, "res://settings")
ProjectSettings.set_setting(settings_dir.name, "res://settings")
if not ProjectSettings.has_setting(settings_dir_property.name):
ProjectSettings.add_property_info(settings_dir_property)
ProjectSettings.set_initial_value(settings_dir_property.name, "res://settings")
ProjectSettings.set_setting(settings_dir_property.name, "res://settings")

if not ProjectSettings.has_setting(ee_path.name):
ProjectSettings.add_property_info(ee_path)
ProjectSettings.set_initial_value(settings_dir.name, "ee")
ProjectSettings.set_setting(ee_path.name, "res://addons/GDExcelExporter/ee.exe")
if not ProjectSettings.has_setting(ee_path_property.name):
ProjectSettings.add_property_info(ee_path_property)
ProjectSettings.set_initial_value(settings_dir_property.name, "ee")
ProjectSettings.set_setting(ee_path_property.name, "res://addons/GDExcelExporter/ee.exe")

btn_export = Button.new()
btn_export.icon = load("res://addons/GDExcelExporter/Excel.svg")
Expand All @@ -47,42 +47,50 @@ func _exit_tree():

func gen_all():

var settings_dir_path = ProjectSettings.get_setting(settings_dir.name)
var ee = ProjectSettings.get_setting(ee_path.name)
var settings_dir_path = ProjectSettings.get_setting(settings_dir_property.name)
var ee_path = ProjectSettings.get_setting(ee_path_property.name)

if not DirAccess.dir_exists_absolute(settings_dir_path):

var settings_abs_path = ProjectSettings.globalize_path(settings_dir_path)
var ee_abs_path = ProjectSettings.globalize_path(ee_path)

if not DirAccess.dir_exists_absolute(settings_abs_path):
var warning_box =AcceptDialog.new()
warning_box.dialog_text = settings_dir_path + " 目录不存在!"
warning_box.dialog_text = settings_abs_path + " 目录不存在!"
warning_box.title = "[警告]GDExcelExporter"
get_editor_interface().get_editor_viewport().add_child(warning_box)
warning_box.popup_centered(_dialog_size)
else:
var abs_path = ProjectSettings.globalize_path(settings_dir_path)

var warning_box =AcceptDialog.new()
# 添加到EditorInterface控件节点里才能显示(入树)
EditorInterface.get_base_control().add_child(warning_box)

warning_box.title = "[导出]GDExcelExporter"
warning_box.dialog_text = "导出中..." # 显示不出来,留着吧
get_editor_interface().get_viewport().add_child(warning_box)
warning_box.dialog_text = "导出中..." # TODO: 显示不出来,留着吧
# 弹出到中间
warning_box.popup_centered(_dialog_size)

# 等待一帧防止卡住无法弹出
await get_tree().process_frame

var output = []
print("=".repeat(10))
print("导出",abs_path,"下面的所有表")
ee_path = ProjectSettings.globalize_path(ee)
OS.execute("CMD.exe",["/c",ee_path,"gen-all","--cwd",abs_path],output,true)
print("导出",settings_abs_path,"下面的所有表")

OS.execute("CMD.exe",["/c",ee_abs_path,"gen-all","--cwd",settings_abs_path],output,true)
for line in output:
print(line)

print("导表结束!")
print("=".repeat(10))
output.push_front("ee_path:"+ee_path)
output.push_front("ee_path_property:"+ee_abs_path)

warning_box.title = "[导出结束]GDExcelExporter"
warning_box.dialog_text = "\n".join(output)

await warning_box.confirmed
warning_box.queue_free() # 得手动销毁,不然会一直编辑器树里
warning_box.queue_free() # 得手动销毁节点,不然会一直编辑器树里

# 触发godot扫描文件改动以重新导入
# XXX: 并没有达到我想要的效果,这里触发的扫描不会重新加载导出的gd脚本
Expand Down
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cmd_path="res://addons/GDExcelExporter/ee.exe"
[application]

config/name="Gd Eexcel Exporer-plugin"
config/features=PackedStringArray("4.0", "Forward Plus")
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"

[autoload]
Expand Down

0 comments on commit 6bf8de5

Please sign in to comment.