Skip to content

Commit ff0a43a

Browse files
committed
Adjust rows and columns calculations
1 parent 55833fb commit ff0a43a

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

spritesheetExporter/spritesheet_exporter.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ class SpritesheetExporter:
3232
write_texture_atlas = False
3333
show_export_dialog = False
3434

35-
def _position_layer(self, layer: Node, imgNum: int, width: int, height: int):
36-
distance = self.columns if self.horizontal else self.rows
37-
layer.move(
38-
int((imgNum % distance) * width),
39-
int((imgNum // distance) * height),
40-
)
41-
4235
def _check_last_keyframe(self, layer: Node, time_range: Iterable[int]):
4336
"""
4437
Finds the time of the layer's last keyframe, and updates the upper time limit
@@ -193,6 +186,7 @@ def _copy_frames(self, src: Document, dest: Document) -> int:
193186
def _process_frames(self, src: Document, dest: Document):
194187
width = src.width()
195188
height = src.height()
189+
num_cells = self.columns if self.horizontal else self.rows
196190

197191
frames_dir = self._make_frames_dir() if self.export_individual_frames else None
198192
texture_atlas = {"frames": []} if self.write_texture_atlas else None
@@ -220,11 +214,18 @@ def _process_frames(self, src: Document, dest: Document):
220214
new_doc.setBatchmode(True)
221215
new_doc.saveAs(str(frames_dir.joinpath(file_name)))
222216

223-
self._position_layer(
224-
layer,
225-
((int(name) - self.start) / self.step),
226-
width,
227-
height,
217+
# TODO: This is too simple for edge cases, like when the direction
218+
# is horizontal and there are 7 frames, 2 columns, and 5 rows
219+
# (there are not enough frames to fill out all 5 rows if they're
220+
# simply placed horizontally and wrap onto the next row when needed)
221+
if self.layers_as_animation:
222+
index = int(name)
223+
else:
224+
index = (int(name) - self.start) // self.step
225+
226+
layer.move(
227+
(index % num_cells) * width,
228+
(index // num_cells) * height,
228229
)
229230

230231
if texture_atlas is not None:
@@ -283,13 +284,7 @@ def export(self, debug=False):
283284

284285
self.rows = ceil(num_frames / self.columns)
285286
elif self.columns == DEFAULT_SPACE:
286-
# Though if I have to guess the number of columns,
287-
# it may also change the (user-set) number of rows.
288-
# For example, if you want ten rows from twelve sprites
289-
# instead of two rows of two and eight of one,
290-
# you'll have six rows of two
291287
self.columns = ceil(num_frames / self.rows)
292-
self.rows = ceil(num_frames / self.columns)
293288

294289
sheet.setWidth(self.columns * width)
295290
sheet.setHeight(self.rows * height)

0 commit comments

Comments
 (0)