Skip to content

Commit

Permalink
fix: Fix multi spritesheet image filename sequence bug
Browse files Browse the repository at this point in the history
fix #8
  • Loading branch information
soimy committed Jan 28, 2020
1 parent be61458 commit 45d4a56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ if (opt.load) {

function fileIO(result) {
for (let a of result.atlas) {
const imageName = a.hasOwnProperty("id") ? `${a.name}.${a.id}.${a.ext}` : `${a.name}.${a.ext}`
const imageName = `${a.name}.${a.ext}`
a.image.writeAsync(imageName)
.then(() => {
console.log(`Saved atlas: ${imageName}`);
Expand All @@ -136,7 +136,7 @@ function fileIO(result) {
});
}
for (let s of result.spritesheets) {
const sheetName = s.hasOwnProperty("id") ? `${s.name}.${s.id}.${s.ext}` : `${s.name}.${s.ext}`;
const sheetName = `${s.name}.${s.ext}`;
fs.writeFile(sheetName, result.exporter.compile(s), 'utf-8', err => {
if(err) console.error(`Failed saving spritesheet ${sheetName}: ${err}`);
else console.log(`Saved spritesheet: ${sheetName}`);
Expand Down
8 changes: 8 additions & 0 deletions src/atlasify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,18 @@ export class Atlasify {
for (let a of this._atlas) {
const tag = a.tag ? a.tag : "_";
if (tagCount[tag] < 1 && a.hasOwnProperty("id")) delete a.id;
if (a.hasOwnProperty("id")) {
a.name = `${a.name}.${a.id}`; // append index to image filename
}
}
for (let s of this._spritesheets) {
const tag = s.tag ? s.tag : "_";
if (tagCount[tag] < 1 && s.hasOwnProperty("id")) delete s.id;
if (s.hasOwnProperty("id")) {
s.name = `${s.name}.${s.id}`; // append index to spritesheet filename
const ext = path.extname(s.imageName);
s.imageName = `${s.name}${ext}`;
}
}
}
}
Expand Down

0 comments on commit 45d4a56

Please sign in to comment.