@@ -26,6 +26,7 @@ func _init(editor_file_system: EditorFileSystem) -> void:
26
26
27
27
func _export (res_source_file_path : String , atlas_maker : AtlasMaker , options : Dictionary ) -> _Common.ExportResult :
28
28
var result : _Common .ExportResult = _Common .ExportResult .new ()
29
+ var err : Error
29
30
30
31
var os_command_result : _ProjectSetting .Result = __os_command_project_setting .get_value ()
31
32
if os_command_result .error :
@@ -41,30 +42,44 @@ func _export(res_source_file_path: String, atlas_maker: AtlasMaker, options: Dic
41
42
if temp_dir_path_result .error :
42
43
result .fail (ERR_UNCONFIGURED , "Unable to get Temporary Files Directory Path to export spritesheet" , temp_dir_path_result )
43
44
return result
45
+ var global_temp_dir_path : String = ProjectSettings .globalize_path (
46
+ temp_dir_path_result .value .strip_edges ())
44
47
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
49
54
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 ([
54
62
"--batch" ,
55
63
"--format" , "json-array" ,
56
64
"--list-tags" ,
57
65
"--sheet" , global_png_path ,
58
66
"--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 )
61
71
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 )])
63
78
return result
64
79
var raw_atlas_image : Image = Image .load_from_file (global_png_path )
65
80
DirAccess .remove_absolute (global_png_path )
66
81
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 ))
68
83
if err :
69
84
result .fail (ERR_INVALID_DATA , "Unable to parse sprite sheet json data with error %s \" %s \" " % [err , error_string (err )])
70
85
return result
@@ -205,6 +220,7 @@ class CustomImageFormatLoaderExtension:
205
220
206
221
func _load_image (image : Image , file_access : FileAccess , flags : int , scale : float ) -> Error :
207
222
var global_source_file_path : String = file_access .get_path_absolute ()
223
+ var err : Error
208
224
209
225
var os_command_result : _ProjectSetting .Result = __os_command_project_setting .get_value ()
210
226
if os_command_result .error :
@@ -220,30 +236,44 @@ class CustomImageFormatLoaderExtension:
220
236
if temp_dir_path_result .error :
221
237
push_error (temp_dir_path_result .error_description )
222
238
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 ([
233
254
"--batch" ,
234
255
"--format" , "json-array" ,
235
256
"--list-tags" ,
236
257
"--sheet" , global_png_path ,
237
258
"--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 )
240
264
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 )])
242
271
return ERR_QUERY_FAILED
272
+
243
273
var raw_atlas_image : Image = Image .load_from_file (global_png_path )
244
274
DirAccess .remove_absolute (global_png_path )
245
275
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 ))
247
277
if err :
248
278
push_error ("Unable to parse sprite sheet json data with error %s \" %s \" " % [err , error_string (err )])
249
279
return ERR_INVALID_DATA
0 commit comments