@@ -44,16 +44,17 @@ func _export(res_source_file_path: String, options: Dictionary) -> ExportResult:
4444 return result
4545 var global_temp_dir_path : String = ProjectSettings .globalize_path (
4646 temp_dir_path_result .value .strip_edges ())
47+ var unique_temp_dir_creation_result : _DirAccessExtensions .CreationResult = \
48+ _DirAccessExtensions .create_directory_with_unique_name (global_temp_dir_path )
49+ if unique_temp_dir_creation_result .error :
50+ result .fail (ERR_QUERY_FAILED , "Failed to create unique temporary directory to export spritesheet" , unique_temp_dir_creation_result )
51+ return result
52+ var unique_temp_dir_path : String = unique_temp_dir_creation_result .path
4753
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 , "Failed to create directory for temporary files \" %s \" with error %s \" %s \" " %
52- [global_temp_dir_path , err , error_string (err )])
53- return result
54+ var global_source_file_path : String = ProjectSettings .globalize_path (res_source_file_path )
5455
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" )
56+ var global_png_path : String = unique_temp_dir_path .path_join ("temp.png" )
57+ var global_json_path : String = unique_temp_dir_path .path_join ("temp.json" )
5758
5859 var command : String = os_command_result .value .strip_edges ()
5960 var arguments : PackedStringArray = \
@@ -64,7 +65,7 @@ func _export(res_source_file_path: String, options: Dictionary) -> ExportResult:
6465 "--list-tags" ,
6566 "--sheet" , global_png_path ,
6667 "--data" , global_json_path ,
67- ProjectSettings . globalize_path ( res_source_file_path ) ])
68+ global_source_file_path ])
6869
6970 var output : Array = []
7071 var exit_code : int = OS .execute (command , arguments , output , true , false )
@@ -77,13 +78,11 @@ func _export(res_source_file_path: String, options: Dictionary) -> ExportResult:
7778 ]) % [exit_code , command , "" .join (arguments )])
7879 return result
7980 var raw_atlas_image : Image = Image .load_from_file (global_png_path )
80- DirAccess .remove_absolute (global_png_path )
8181 var json = JSON .new ()
8282 err = json .parse (FileAccess .get_file_as_string (global_json_path ))
8383 if err :
8484 result .fail (ERR_INVALID_DATA , "Failed to parse sprite sheet json data with error %s \" %s \" " % [err , error_string (err )])
8585 return result
86- DirAccess .remove_absolute (global_json_path )
8786 var raw_sprite_sheet_data : Dictionary = json .data
8887
8988 var sprite_sheet_layout : _Common .SpriteSheetLayout = options [_Options .SPRITE_SHEET_LAYOUT ]
@@ -186,6 +185,11 @@ func _export(res_source_file_path: String, options: Dictionary) -> ExportResult:
186185 if not autoplay_animation_name .is_empty () and animation_library .autoplay_index < 0 :
187186 push_warning ("Autoplay animation name not found: \" %s \" . Continuing..." % [autoplay_animation_name ])
188187
188+ if _DirAccessExtensions .remove_dir_recursive (unique_temp_dir_path ).error :
189+ push_warning (
190+ "Failed to remove unique temporary directory: \" %s \" " %
191+ [unique_temp_dir_path ])
192+
189193 result .success (sprite_sheet_building_result .atlas_image , sprite_sheet , animation_library )
190194 return result
191195
@@ -225,20 +229,21 @@ class CustomImageFormatLoaderExtension:
225229 push_error (os_command_arguments_result .error_description )
226230 return os_command_arguments_result .error
227231
228- var temp_dir_path_result : _ProjectSetting .GettingValueResult = __common_temporary_files_directory_path_project_setting .get_value ()
232+ var temp_dir_path_result : _ProjectSetting .GettingValueResult = _Common . common_temporary_files_directory_path_project_setting .get_value ()
229233 if temp_dir_path_result .error :
230- push_error (temp_dir_path_result . error_description )
234+ push_error ("Failed to get Temporary Files Directory Path to export spritesheet" )
231235 return temp_dir_path_result .error
232- var global_temp_dir_path : String = ProjectSettings .globalize_path (temp_dir_path_result .value .strip_edges ())
233-
234- var global_png_path : String = global_temp_dir_path .path_join ("temp.png" )
235- var global_json_path : String = global_temp_dir_path .path_join ("temp.json" )
236- if not DirAccess .dir_exists_absolute (global_temp_dir_path ):
237- err = DirAccess .make_dir_recursive_absolute (global_temp_dir_path )
238- if err :
239- push_error ("Failed to create directory for temporary files \" %s \" with error %s \" %s \" " %
240- [global_temp_dir_path , err , error_string (err )])
241- return ERR_QUERY_FAILED
236+ var global_temp_dir_path : String = ProjectSettings .globalize_path (
237+ temp_dir_path_result .value .strip_edges ())
238+ var unique_temp_dir_creation_result : _DirAccessExtensions .CreationResult = \
239+ _DirAccessExtensions .create_directory_with_unique_name (global_temp_dir_path )
240+ if unique_temp_dir_creation_result .error :
241+ push_error ("Failed to create unique temporary directory to export spritesheet" )
242+ return unique_temp_dir_creation_result .error
243+ var unique_temp_dir_path : String = unique_temp_dir_creation_result .path
244+
245+ var global_png_path : String = unique_temp_dir_path .path_join ("temp.png" )
246+ var global_json_path : String = unique_temp_dir_path .path_join ("temp.json" )
242247
243248 var command : String = os_command_result .value .strip_edges ()
244249 var arguments : PackedStringArray = \
@@ -264,17 +269,20 @@ class CustomImageFormatLoaderExtension:
264269 return ERR_QUERY_FAILED
265270
266271 var raw_atlas_image : Image = Image .load_from_file (global_png_path )
267- DirAccess .remove_absolute (global_png_path )
268272 var json = JSON .new ()
269273 err = json .parse (FileAccess .get_file_as_string (global_json_path ))
270274 if err :
271275 push_error ("Failed to parse sprite sheet json data with error %s \" %s \" " % [err , error_string (err )])
272276 return ERR_INVALID_DATA
273- DirAccess .remove_absolute (global_json_path )
274277 var raw_sprite_sheet_data : Dictionary = json .data
275278
276279 var source_image_size : Vector2i = _Common .get_vector2i (
277280 raw_sprite_sheet_data .frames [0 ].sourceSize , "w" , "h" )
278281
282+ if _DirAccessExtensions .remove_dir_recursive (unique_temp_dir_path ).error :
283+ push_warning (
284+ "Failed to remove unique temporary directory: \" %s \" " %
285+ [unique_temp_dir_path ])
286+
279287 image .copy_from (raw_atlas_image .get_region (Rect2i (Vector2i .ZERO , source_image_size )))
280288 return OK
0 commit comments