Skip to content

Commit

Permalink
fix: Tagcount 0 eq. null bug
Browse files Browse the repository at this point in the history
This bug will result overwriting when multiple sprites are generated

fix #8
  • Loading branch information
soimy committed Sep 17, 2019
1 parent f741692 commit c554cdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if (opt.load) {

function fileIO(result) {
for (let a of result.atlas) {
const imageName = a.id ? `${a.name}.${a.id}.${a.ext}` : `${a.name}.${a.ext}`
const imageName = a.hasOwnProperty("id") ? `${a.name}.${a.id}.${a.ext}` : `${a.name}.${a.ext}`
a.image.writeAsync(imageName)
.then(() => {
console.log(`Saved atlas: ${imageName}`);
Expand All @@ -133,7 +133,7 @@ function fileIO(result) {
});
}
for (let s of result.spritesheets) {
const sheetName = s.id ? `${s.name}.${s.id}.${s.ext}` : `${s.name}.${s.ext}`;
const sheetName = s.hasOwnProperty("id") ? `${s.name}.${s.id}.${s.ext}` : `${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
6 changes: 3 additions & 3 deletions src/atlasify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class Atlasify {
this._packer.bins.forEach((bin, index: number) => {
// Count tags
let tag = bin.tag ? bin.tag : "_";
if (!tagCount[tag]) tagCount[tag] = 0; // create index key if not exist
if (!tagCount.hasOwnProperty(tag)) tagCount[tag] = 0; // create index key if not exist
else tagCount[tag]++;

if (!bin.dirty) return; // early return if bin is not changed
Expand Down Expand Up @@ -561,11 +561,11 @@ export class Atlasify {
private pruneTagIndex (tagCount: { [index: string]: number; }) {
for (let a of this._atlas) {
const tag = a.tag ? a.tag : "_";
if (tagCount[tag] < 2 && a.id) delete a.id;
if (tagCount[tag] < 1 && a.id) delete a.id;
}
for (let s of this._spritesheets) {
const tag = s.tag ? s.tag : "_";
if (tagCount[tag] < 2 && s.id) delete s.id;
if (tagCount[tag] < 1 && s.id) delete s.id;
}
}
}
Expand Down

0 comments on commit c554cdb

Please sign in to comment.