Skip to content

Commit

Permalink
Merge pull request #268 from klingbolt/godot_file_handler
Browse files Browse the repository at this point in the history
Godot File Handler
  • Loading branch information
AsherGlick authored May 18, 2024
2 parents eb2a544 + 6f0ee47 commit 8e68914
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 62 deletions.
18 changes: 18 additions & 0 deletions FileHandler.gd
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions ImportPackDialog.gd
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 0 additions & 44 deletions PackDialog.gd

This file was deleted.

19 changes: 2 additions & 17 deletions Spatial.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8e68914

Please sign in to comment.