Skip to content

Commit 3753907

Browse files
committed
Added filename indexing formatting to 'All sprites (seperate files)' export function (7800 mode)
1 parent c38d866 commit 3753907

File tree

7 files changed

+81
-6
lines changed

7 files changed

+81
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The following enhancements and changes have been made to Atari Dev Studio:
77
* Updated the Sprite Editor with the following changes:
88
- fixed issue using scroll wheel to zoom on the Sprite List window
99
- Added shift key functionality (use background color/erase) when using line, rectange, ellipse and flood fill tools
10+
- When exporting using the 'All sprites (seperate files)' export function (7800 mode), you can now append the required number of zeros to the end of a filename to output with a consistent filename indexing length ie. filename000 will output as filename000.png, filename001.png, filename010.png, filename100.png etc
1011

1112
## 0.10.5
1213

out/application.js

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/application.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/pages/spriteeditor.js

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/pages/spriteeditor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/application.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,28 @@ export async function OpenBrowserWindow(path: string, browser:string = ''): Prom
398398
.catch((_: any) => {
399399
vscode.window.showErrorMessage(`Open browser failed!! Please check if you have installed the browser ${browser} correctly!`);
400400
});
401+
}
402+
403+
export function CountTrailingZeros(str: string): number {
404+
if (!str) return 0; // Handle empty string
405+
const match = str.match(/0+$/);
406+
return match ? match[0].length : 0;
407+
}
408+
409+
export function TrimRight(str: string, length: number): string {
410+
if (length <= 0) return ''; // Handle invalid length
411+
return str.slice(-length); // Extract from end using negative index
412+
}
413+
414+
export function TrimLeft(str: string, length: number): string {
415+
if (length <= 0) return ''; // Handle invalid length
416+
return str.slice(0, length); // Extract from start to length
417+
}
418+
419+
export function ReplaceZerosTemplate(template: string, num: number): string {
420+
const numStr = num.toString();
421+
if (numStr.length > template.length) {
422+
return numStr; // If number is longer than template, return number as is
423+
}
424+
return template.slice(0, template.length - numStr.length) + numStr;
401425
}

src/pages/spriteeditor.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,22 @@ export class SpriteEditorPage implements vscode.Disposable {
412412
// Save
413413
filesystem.MkDirAsync(folder)
414414
.then(() => {
415+
// Prepare
416+
// NOTE: determine how many trailing zeros so we can build up a index replacement the size
417+
// requested by the user
418+
let templateFileName = data.fileName;
419+
let totalZerosLength = application.CountTrailingZeros(templateFileName);
420+
let indexTemplate = '0'.repeat(totalZerosLength);
421+
// if we have trailing zeros strip them from the template name
422+
if (totalZerosLength > 0) templateFileName = application.TrimLeft(templateFileName,templateFileName.length-totalZerosLength);
423+
415424
// Process each image
416425
for (let i = 0; i < data.count; i++) {
417-
// Loop through each file
418-
let fileName = data.fileName + i + ".png";
426+
// loop through each file
427+
428+
// build filename
429+
let fileName = templateFileName + application.ReplaceZerosTemplate(indexTemplate,i) + ".png";
430+
// create file
419431
let fileUri = vscode.Uri.file(path.join(folder,fileName));
420432
// We now send through in base64 to avoid Buffer.from() conversion errors
421433
let convertToBuffer = Buffer.from(data.sprites[i],"base64");

0 commit comments

Comments
 (0)