2022-06-03 01:25:50 +02:00
|
|
|
tool
|
|
|
|
extends EditorPlugin
|
|
|
|
|
|
|
|
func _enter_tree():
|
2022-06-03 22:33:00 +02:00
|
|
|
add_tool_menu_item("Convert Scripts to Cpp", self, "on_convert_script_menu_clicked")
|
2022-06-04 13:01:41 +02:00
|
|
|
add_tool_menu_item("Convert Scenes to Cpp", self, "on_convert_scene_menu_clicked")
|
2022-06-03 01:25:50 +02:00
|
|
|
|
|
|
|
func _exit_tree():
|
2022-06-03 22:33:00 +02:00
|
|
|
remove_tool_menu_item("Convert Scripts to Cpp")
|
2022-06-04 13:01:41 +02:00
|
|
|
remove_tool_menu_item("Convert Scenes to Cpp")
|
2022-06-03 01:25:50 +02:00
|
|
|
|
2022-06-03 22:33:00 +02:00
|
|
|
func on_convert_script_menu_clicked(val) -> void:
|
2022-06-03 21:06:28 +02:00
|
|
|
var GDSParser = load("res://addons/gdc_converter/gdsparser.gd")
|
|
|
|
var parser = GDSParser.new()
|
|
|
|
|
2022-06-03 01:25:50 +02:00
|
|
|
var dir = Directory.new()
|
|
|
|
var dir_name = get_editor_interface().get_selected_path()
|
|
|
|
if dir.open(dir_name) == OK:
|
|
|
|
dir.list_dir_begin()
|
|
|
|
var file_name = dir.get_next()
|
|
|
|
while file_name != "":
|
|
|
|
|
|
|
|
if !dir.current_is_dir():
|
|
|
|
if file_name.get_extension() == "gd":
|
2022-06-03 21:06:28 +02:00
|
|
|
parser.process_file(dir_name + file_name)
|
2022-06-03 01:25:50 +02:00
|
|
|
|
|
|
|
file_name = dir.get_next()
|
2022-06-03 22:33:00 +02:00
|
|
|
|
|
|
|
func on_convert_scene_menu_clicked(val) -> void:
|
|
|
|
#var GDSParser = load("res://addons/gdc_converter/gdsparser.gd")
|
|
|
|
#var parser = GDSParser.new()
|
|
|
|
|
|
|
|
var dir = Directory.new()
|
|
|
|
var dir_name = get_editor_interface().get_selected_path()
|
|
|
|
if dir.open(dir_name) == OK:
|
|
|
|
dir.list_dir_begin()
|
|
|
|
var file_name = dir.get_next()
|
|
|
|
while file_name != "":
|
|
|
|
|
|
|
|
if !dir.current_is_dir():
|
2022-06-04 13:01:41 +02:00
|
|
|
if file_name.get_extension() == "tscn":
|
2022-06-03 22:33:00 +02:00
|
|
|
process_file(dir_name + file_name)
|
|
|
|
|
|
|
|
file_name = dir.get_next()
|
|
|
|
|
|
|
|
class GDSSceneParser:
|
2022-06-04 13:01:41 +02:00
|
|
|
var result : String
|
|
|
|
|
|
|
|
func parse(file_name : String) -> void:
|
|
|
|
var ps : PackedScene = ResourceLoader.load(file_name, "PackedScene")
|
|
|
|
|
|
|
|
if !ps:
|
|
|
|
print("ERROR! !ps :" + file_name)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2022-06-03 22:33:00 +02:00
|
|
|
|
|
|
|
# var c : PoolStringArray = split_preprocess_content(contents)
|
|
|
|
# root.parse(c)
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func _to_string():
|
2022-06-04 13:01:41 +02:00
|
|
|
return result
|
2022-06-03 22:33:00 +02:00
|
|
|
|
2022-06-04 13:01:41 +02:00
|
|
|
func get_cpp_impl_string() -> String:
|
2022-06-03 22:33:00 +02:00
|
|
|
var s : String = "\n"
|
2022-06-04 13:01:41 +02:00
|
|
|
s += "void construct() {\n"
|
|
|
|
s += "\n"
|
|
|
|
s += result
|
|
|
|
s += "\n}\n"
|
2022-06-03 22:33:00 +02:00
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
func process_file(file_name : String) -> void:
|
|
|
|
var parser : GDSSceneParser = GDSSceneParser.new()
|
2022-06-04 13:01:41 +02:00
|
|
|
parser.parse(file_name)
|
2022-06-03 22:33:00 +02:00
|
|
|
|
|
|
|
var save_base_file_path : String = file_name.get_base_dir()
|
2022-06-04 13:01:41 +02:00
|
|
|
var save_base_file_name : String = file_name.get_file().to_lower().trim_suffix(".tscn")
|
2022-06-03 22:33:00 +02:00
|
|
|
|
2022-06-04 13:01:41 +02:00
|
|
|
var impl_file : String = save_base_file_path + "/" + save_base_file_name + ".ctscn"
|
|
|
|
var impl_data : String = parser.get_cpp_impl_string()
|
2022-06-03 22:33:00 +02:00
|
|
|
|
2022-06-04 13:01:41 +02:00
|
|
|
print(impl_data)
|
2022-06-03 22:33:00 +02:00
|
|
|
|
|
|
|
#file.open(impl_file, File.WRITE)
|
|
|
|
#file.store_string(impl_data)
|
|
|
|
#file.close()
|