diff --git a/FileHandler.gd b/FileHandler.gd new file mode 100644 index 00000000..eb0207f5 --- /dev/null +++ b/FileHandler.gd @@ -0,0 +1,18 @@ +const converter_executable_path = "./xml_converter/build/xml_converter" + +static func call_xml_converter(args: PoolStringArray): + var output: Array = [] + print(args) + var result: int = OS.execute(converter_executable_path, args, true, output, true) + print(output) + if result != OK: + print("Failed to execute the converter. Error code:", result) + else: + print("Command executed successfully.") + +static func create_directory_if_missing(path: String): + var dir = Directory.new() + if not dir.dir_exists(path): + var success = dir.make_dir(path) + if success != OK: + print("Error: Could not create data folder:", path) diff --git a/ImportPackDialog.gd b/ImportPackDialog.gd new file mode 100644 index 00000000..3db05f00 --- /dev/null +++ b/ImportPackDialog.gd @@ -0,0 +1,25 @@ +extends FileDialog + +const FileHandler = preload("res://FileHandler.gd") +var downloaded_markers_dir: String +var unsaved_markers_dir: String +var user_data_dir: String + +func _ready(): + #TODO: Move these to global file Settings so they can be customized + self.user_data_dir = str(OS.get_user_data_dir()) + self.downloaded_markers_dir = self.user_data_dir.plus_file("packs") + self.unsaved_markers_dir = self.user_data_dir.plus_file("protobins") + FileHandler.create_directory_if_missing(self.downloaded_markers_dir) + FileHandler.create_directory_if_missing(self.unsaved_markers_dir) + +func _on_FileDialog_dir_selected(dir_path: String): + print("Selected folder:", dir_path) + var new_path: String = self.downloaded_markers_dir.plus_file(dir_path.get_file()) + FileHandler.create_directory_if_missing(new_path) + var args: PoolStringArray = [ + "--input-taco-path", dir_path, + "--output-waypoint-path", new_path, + "--output-split-waypoint-path", self.unsaved_markers_dir + ] + FileHandler.call_xml_converter(args) diff --git a/PackDialog.gd b/PackDialog.gd deleted file mode 100644 index 10b86f2e..00000000 --- a/PackDialog.gd +++ /dev/null @@ -1,44 +0,0 @@ -extends Control - -const executable_path: String = "./xml_converter/build/xml_converter" -var protobin_data_folder: String -var split_protobin_data_folder: String -var user_data_dir: String - -func _ready(): - var dir = Directory.new() - self.user_data_dir = str(OS.get_user_data_dir()) - self.protobin_data_folder = self.user_data_dir.plus_file("packs") - self.split_protobin_data_folder = self.user_data_dir.plus_file("protobins") - if not dir.dir_exists(self.protobin_data_folder): - var success = dir.make_dir(self.protobin_data_folder) - if success != OK: - print("Error: Could not create data folder:", self.protobin_data_folder) - if not dir.dir_exists(self.split_protobin_data_folder): - var success = dir.make_dir(self.split_protobin_data_folder) - if success != OK: - print("Error: Could not create data folder:", self.split_protobin_data_folder) - -func _on_FileDialog_dir_selected(dir_path): - var output: Array = [] - print("Selected folder:", dir_path) - var dir = Directory.new() - var new_path: String = self.protobin_data_folder.plus_file(dir_path.get_file()) - if not dir.dir_exists(new_path): - var success = dir.make_dir(new_path) - if success != OK: - print("Error: Could not create data folder:", self.protobin_data_folder) - #else: - # #Pop up here to confirm overwrite? - var args: PoolStringArray = [ - "--input-taco-path", dir_path, - "--output-waypoint-path", new_path, - "--output-split-waypoint-path", self.split_protobin_data_folder - ] - print(args) - var result: int = OS.execute(self.executable_path, args, true, output, true) - print(output) - if result != OK: - print("Failed to execute the command. Error code:", result) - else: - print("Command executed successfully.") diff --git a/Spatial.gd b/Spatial.gd index ebcef36c..c806ee30 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -51,9 +51,10 @@ const category3d_scene = preload("res://Category3D.tscn") const category2d_scene = preload("res://Category2D.tscn") const path2d_scene = preload("res://Route2D.tscn") const gizmo_scene = preload("res://Gizmo/PointEdit.tscn") + +# Scripts containing code used by this scene const CategoryData = preload("res://CategoryData.gd") const Waypoint = preload("res://waypoint.gd") -const PackDialog = preload("res://PackDialog.gd") ##########Node Connections########### onready var markers_ui := $Control/Dialogs/CategoriesDialog/MarkersUI as Tree @@ -817,22 +818,6 @@ func _on_NewPathPoint_pressed(): self.currently_active_path.add_point(z_accurate_player_position) self.currently_active_path_2d.add_point(Vector2(self.player_position.x, -self.player_position.z)) - -################################################################################ -# -################################################################################ -func _on_SavePath_pressed(): - $Control/Dialogs/SaveDialog.show() - -################################################################################ -# TODO: This function will be used when exporting packs -################################################################################ -func _on_SaveDialog_file_selected(path): - self.markerdata[str(self.map_id)] = data_from_renderview() - var save_game = File.new() - save_game.open(path, File.WRITE) - save_game.store_string(JSON.print(self.markerdata)) - func _on_NodeEditorDialog_hide(): self.currently_selected_node = null clear_adjustment_nodes() diff --git a/Spatial.tscn b/Spatial.tscn index a220578a..05650e14 100644 --- a/Spatial.tscn +++ b/Spatial.tscn @@ -12,7 +12,7 @@ [ext_resource path="res://icon_new_point.png" type="Texture" id=11] [ext_resource path="res://SettingsDialog.gd" type="Script" id=12] [ext_resource path="res://Category3D.gd" type="Script" id=13] -[ext_resource path="res://PackDialog.gd" type="Script" id=14] +[ext_resource path="res://ImportPackDialog.gd" type="Script" id=14] [ext_resource path="res://Category2D.gd" type="Script" id=15] [sub_resource type="Shader" id=1]