Skip to content

Commit 164fd11

Browse files
authored
support for more types of frame numeration
1 parent 63d38c4 commit 164fd11

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

FunkIntoFunky/FunkIntoFunky.html

+37-15
Original file line numberDiff line numberDiff line change
@@ -187,34 +187,55 @@ <h1 class="text-center mb-4" data-text="title">Animation Frame Combiner</h1>
187187
try {
188188
const zip = await JSZip.loadAsync(file);
189189
const imageFiles = {};
190+
const tempGroups = {};
190191

191-
// First pass: Group files by animation name
192+
// First pass: Collect all PNG files and their potential base names
192193
for (const [filename, zipEntry] of Object.entries(zip.files)) {
193194
if (!filename.endsWith('.png')) continue;
194195

195-
const animName = filename.replace(/\d+\.png$/, '');
196-
if (!imageFiles[animName]) {
197-
imageFiles[animName] = [];
196+
// Extract name without extension
197+
const nameWithoutExt = filename.slice(0, -4);
198+
199+
// Try to find a number at the end
200+
const numberMatch = nameWithoutExt.match(/^(.*?)(\d+)?$/);
201+
if (!numberMatch) continue;
202+
203+
const [_, baseName, frameNumber] = numberMatch;
204+
const normalizedBaseName = baseName.endsWith('_') || baseName.endsWith('-')
205+
? baseName.slice(0, -1)
206+
: baseName;
207+
208+
// Store in temporary groups to help identify base names
209+
if (!tempGroups[normalizedBaseName]) {
210+
tempGroups[normalizedBaseName] = [];
198211
}
199-
imageFiles[animName].push({
212+
213+
tempGroups[normalizedBaseName].push({
200214
name: filename,
215+
frameNumber: frameNumber ? parseInt(frameNumber) : 0,
201216
entry: zipEntry
202217
});
203218
}
204219

220+
// Second pass: Process groups and create final imageFiles object
221+
for (const [baseName, files] of Object.entries(tempGroups)) {
222+
// If there's only one file and it has no number, skip grouping
223+
if (files.length === 1 && files[0].frameNumber === 0) {
224+
continue;
225+
}
226+
227+
imageFiles[baseName] = files;
228+
}
229+
205230
const newZip = new JSZip();
206231
let processedCount = 0;
207232
const totalAnimations = Object.keys(imageFiles).length;
208233

209234
for (const [animName, files] of Object.entries(imageFiles)) {
210235
statusText.textContent = getText('processingAnimation') + animName;
211236

212-
// Sort files numerically
213-
files.sort((a, b) => {
214-
const numA = parseInt(a.name.match(/\d+/g).pop());
215-
const numB = parseInt(b.name.match(/\d+/g).pop());
216-
return numA - numB;
217-
});
237+
// Sort files by frame number
238+
files.sort((a, b) => a.frameNumber - b.frameNumber);
218239

219240
// Load all images first
220241
const images = await Promise.all(files.map(async file => {
@@ -252,10 +273,6 @@ <h1 class="text-center mb-4" data-text="title">Animation Frame Combiner</h1>
252273
img.width,
253274
img.height
254275
);
255-
256-
// Optional: Draw frame boundary for debugging
257-
// ctx.strokeStyle = '#ff0000';
258-
// ctx.strokeRect(x, 0, maxWidth, maxHeight);
259276
});
260277

261278
const blob = await new Promise(resolve => canvas.toBlob(resolve));
@@ -294,4 +311,9 @@ <h1 class="text-center mb-4" data-text="title">Animation Frame Combiner</h1>
294311
updateLanguage('en');
295312
</script>
296313
</body>
314+
</html>
315+
316+
updateLanguage('en');
317+
</script>
318+
</body>
297319
</html>

0 commit comments

Comments
 (0)