1616
1717
1818class SpritesheetExporter :
19- export_name = "spritesheet"
20- export_dir = Path .home ()
19+ export_path = Path .home ().joinpath ("spritesheet.png" )
2120
2221 horizontal = True
2322 rows = DEFAULT_SPACE
@@ -121,22 +120,22 @@ def _set_frame_times(self, doc: Document):
121120 if def_start :
122121 self .start = 0
123122
124- def make_export_path (self , suffix = "" ):
125- return self .export_dir .joinpath (self .export_name + suffix )
126-
127123 def _make_frames_dir (self ):
128- frames_dir = self .make_export_path ( "_sprites" )
124+ frames_dir = self .export_path . with_name ( self . export_path . stem + "_sprites" )
129125
130126 if frames_dir .exists ():
131127 if self .force_new :
132128 export_num = 0
129+ frames_dir = self .export_path .with_suffix (
130+ self .export_path .stem + "_sprites0"
131+ )
133132
134- def export_candidate ():
135- return self .make_export_path ("_sprites" + str (export_num ))
136-
137- while export_candidate ().exists ():
133+ while frames_dir .exists ():
138134 export_num += 1
139- frames_dir = export_candidate ()
135+ frames_dir = self .export_path .with_suffix (
136+ "" .join ([self .export_path .stem , "_sprites" , str (export_num )])
137+ )
138+
140139 frames_dir .mkdir ()
141140 else :
142141 frames_dir .mkdir ()
@@ -195,7 +194,7 @@ def _process_frames(self, src: Document, dest: Document):
195194 name = layer .name ()
196195
197196 if frames_dir is not None :
198- file_name = f" sprite_{ name .zfill (3 )} .png"
197+ file_name = "" . join ([ " sprite_" , name .zfill (3 ), self . export_path . suffix ])
199198 new_doc = KI .createDocument (
200199 width ,
201200 height ,
@@ -242,7 +241,7 @@ def _process_frames(self, src: Document, dest: Document):
242241 )
243242
244243 if texture_atlas is not None :
245- with open ( str ( self .make_export_path (".json" )), "w" ) as f :
244+ with self .export_path . with_suffix (".json" ). open ( "w" ) as f :
246245 json .dump (texture_atlas , f )
247246
248247 def export (self , debug = False ):
@@ -263,18 +262,21 @@ def export(self, debug=False):
263262 width = doc .width ()
264263 height = doc .height ()
265264
265+ if self .export_path .suffix == "" :
266+ self .export_path = self .export_path .with_suffix (".png" )
267+
266268 # creating a new document where we'll put our sprites
267269 sheet = KI .createDocument (
268270 width ,
269271 height ,
270- self .export_name + ".png" ,
272+ self .export_path . name ,
271273 doc .colorModel (),
272274 doc .colorDepth (),
273275 doc .colorProfile (),
274276 doc .resolution (),
275277 )
276278
277- sheet .setFileName (str (self .make_export_path ( ".png" ) ))
279+ sheet .setFileName (str (self .export_path ))
278280 num_frames = self ._copy_frames (doc , sheet )
279281
280282 # getting a default value for rows and columns
0 commit comments