@@ -26,6 +26,7 @@ func _init(editor_file_system: EditorFileSystem) -> void:
2626
2727func _export (res_source_file_path : String , atlas_maker : AtlasMaker , options : Dictionary ) -> _Common.ExportResult :
2828 var result : _Common .ExportResult = _Common .ExportResult .new ()
29+ var err : Error
2930
3031 var os_command_result : _ProjectSetting .Result = __os_command_project_setting .get_value ()
3132 if os_command_result .error :
@@ -41,30 +42,44 @@ func _export(res_source_file_path: String, atlas_maker: AtlasMaker, options: Dic
4142 if temp_dir_path_result .error :
4243 result .fail (ERR_UNCONFIGURED , "Unable to get Temporary Files Directory Path to export spritesheet" , temp_dir_path_result )
4344 return result
45+ var global_temp_dir_path : String = ProjectSettings .globalize_path (
46+ temp_dir_path_result .value .strip_edges ())
4447
45- var png_path : String = temp_dir_path_result .value .path_join ("temp.png" )
46- var global_png_path : String = ProjectSettings .globalize_path (png_path )
47- var json_path : String = temp_dir_path_result .value .path_join ("temp.json" )
48- var global_json_path : String = ProjectSettings .globalize_path (json_path )
48+ if not DirAccess .dir_exists_absolute (global_temp_dir_path ):
49+ err = DirAccess .make_dir_recursive_absolute (global_temp_dir_path )
50+ if err :
51+ result .fail (ERR_UNCONFIGURED , "Unable to create directory for temporary files \" %s \" with error %s \" %s \" " %
52+ [global_temp_dir_path , err , error_string (err )])
53+ return result
4954
50- var output : Array = []
51- var exit_code : int = OS .execute (
52- os_command_result .value ,
53- os_command_arguments_result .value + PackedStringArray ([
55+ var global_png_path : String = global_temp_dir_path .path_join ("temp.png" )
56+ var global_json_path : String = global_temp_dir_path .path_join ("temp.json" )
57+
58+ var command : String = os_command_result .value .strip_edges ()
59+ var arguments : PackedStringArray = \
60+ os_command_arguments_result .value + \
61+ PackedStringArray ([
5462 "--batch" ,
5563 "--format" , "json-array" ,
5664 "--list-tags" ,
5765 "--sheet" , global_png_path ,
5866 "--data" , global_json_path ,
59- ProjectSettings .globalize_path (res_source_file_path )]),
60- output , true , false )
67+ ProjectSettings .globalize_path (res_source_file_path )])
68+
69+ var output : Array = []
70+ var exit_code : int = OS .execute (command , arguments , output , true , false )
6171 if exit_code :
62- result .fail (ERR_QUERY_FAILED , "An error occurred while executing the Aseprite command. Process exited with code %s " % [exit_code ])
72+ for arg_index in arguments .size ():
73+ arguments [arg_index ] = "\n Argument: " + arguments [arg_index ]
74+ result .fail (ERR_QUERY_FAILED , " " .join ([
75+ "An error occurred while executing the Aseprite command." ,
76+ "Process exited with code %s :\n Command: %s%s "
77+ ]) % [exit_code , command , "" .join (arguments )])
6378 return result
6479 var raw_atlas_image : Image = Image .load_from_file (global_png_path )
6580 DirAccess .remove_absolute (global_png_path )
6681 var json = JSON .new ()
67- var err : Error = json .parse (FileAccess .get_file_as_string (global_json_path ))
82+ err = json .parse (FileAccess .get_file_as_string (global_json_path ))
6883 if err :
6984 result .fail (ERR_INVALID_DATA , "Unable to parse sprite sheet json data with error %s \" %s \" " % [err , error_string (err )])
7085 return result
@@ -205,6 +220,7 @@ class CustomImageFormatLoaderExtension:
205220
206221 func _load_image (image : Image , file_access : FileAccess , flags : int , scale : float ) -> Error :
207222 var global_source_file_path : String = file_access .get_path_absolute ()
223+ var err : Error
208224
209225 var os_command_result : _ProjectSetting .Result = __os_command_project_setting .get_value ()
210226 if os_command_result .error :
@@ -220,30 +236,44 @@ class CustomImageFormatLoaderExtension:
220236 if temp_dir_path_result .error :
221237 push_error (temp_dir_path_result .error_description )
222238 return temp_dir_path_result .error
223-
224- var png_path : String = temp_dir_path_result .value .path_join ("temp.png" )
225- var global_png_path : String = ProjectSettings .globalize_path (png_path )
226- var json_path : String = temp_dir_path_result .value .path_join ("temp.json" )
227- var global_json_path : String = ProjectSettings .globalize_path (json_path )
228-
229- var output : Array = []
230- var exit_code : int = OS .execute (
231- os_command_result .value ,
232- os_command_arguments_result .value + PackedStringArray ([
239+ var global_temp_dir_path : String = ProjectSettings .globalize_path (temp_dir_path_result .value .strip_edges ())
240+
241+ var global_png_path : String = global_temp_dir_path .path_join ("temp.png" )
242+ var global_json_path : String = global_temp_dir_path .path_join ("temp.json" )
243+ if not DirAccess .dir_exists_absolute (global_temp_dir_path ):
244+ err = DirAccess .make_dir_recursive_absolute (global_temp_dir_path )
245+ if err :
246+ push_error ("Unable to create directory for temporary files \" %s \" with error %s \" %s \" " %
247+ [global_temp_dir_path , err , error_string (err )])
248+ return ERR_QUERY_FAILED
249+
250+ var command : String = os_command_result .value .strip_edges ()
251+ var arguments : PackedStringArray = \
252+ os_command_arguments_result .value + \
253+ PackedStringArray ([
233254 "--batch" ,
234255 "--format" , "json-array" ,
235256 "--list-tags" ,
236257 "--sheet" , global_png_path ,
237258 "--data" , global_json_path ,
238- global_source_file_path ]),
239- output , true , false )
259+ global_source_file_path ,
260+ ])
261+
262+ var output : Array = []
263+ var exit_code : int = OS .execute (command , arguments , output , true , false )
240264 if exit_code :
241- push_error ("An error occurred while executing the Aseprite command. Process exited with code %s " % [exit_code ])
265+ for arg_index in arguments .size ():
266+ arguments [arg_index ] = "\n Argument: " + arguments [arg_index ]
267+ push_error (" " .join ([
268+ "An error occurred while executing the Aseprite command." ,
269+ "Process exited with code %s :\n Command: %s%s "
270+ ]) % [exit_code , command , "" .join (arguments )])
242271 return ERR_QUERY_FAILED
272+
243273 var raw_atlas_image : Image = Image .load_from_file (global_png_path )
244274 DirAccess .remove_absolute (global_png_path )
245275 var json = JSON .new ()
246- var err : Error = json .parse (FileAccess .get_file_as_string (global_json_path ))
276+ err = json .parse (FileAccess .get_file_as_string (global_json_path ))
247277 if err :
248278 push_error ("Unable to parse sprite sheet json data with error %s \" %s \" " % [err , error_string (err )])
249279 return ERR_INVALID_DATA
0 commit comments