Skip to content

Commit

Permalink
feat: New option --group-folder
Browse files Browse the repository at this point in the history
groupFolder option will try to pack sprites within same folder into the same atlas to save
drawcalls. Adapting new option `exclusiveTag` from module `maxrects-packer`
  • Loading branch information
soimy committed Sep 17, 2020
1 parent 6804108 commit 4e6183a
Show file tree
Hide file tree
Showing 36 changed files with 3,365 additions and 1,494 deletions.
3 changes: 3 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cli
.option(' --debug', 'draw debug gizmo on atlas (Default: false)', false)
.option(' --instant', 'instant packing is quicker and skip sorting (Default: false)', false)
.option(' --seperate-folder', 'Seperate bin based on folder (Default: false)', false)
.option(' --group-folder', 'Group bin based on folder (Default: false)', false)
.option(' --search-dummy', 'Search duplicate sprites to reduce atlas size (Default: false)', false)
.option(' --save', 'Save configuration for reuse (Default: false)', false)

Expand Down Expand Up @@ -78,6 +79,7 @@ opt.trim = utils.valueQueue([opt.trim, false]);
opt.debug = utils.valueQueue([opt.debug, false]);
opt.instant = utils.valueQueue([opt.instant, false]);
opt.seperateFolder = utils.valueQueue([opt.seperateFolder, false]);
opt.groupFolder = utils.valueQueue([opt.groupFolder, false]);
opt.searchDummy = utils.valueQueue([opt.searchDummy, false]);
opt.save = utils.valueQueue([opt.save, false]);

Expand All @@ -97,6 +99,7 @@ atlasifyOptions.debug = opt.debug;
atlasifyOptions.extrude = opt.extrude;
atlasifyOptions.instant = opt.instant;
atlasifyOptions.seperateFolder = opt.seperateFolder;
atlasifyOptions.groupFolder = opt.groupFolder;
atlasifyOptions.searchDummy = opt.searchDummy;

//
Expand Down
1,632 changes: 746 additions & 886 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"doc": "typedoc && touch docs/.nojekyll",
"doc:json": "typedoc --json docs/typedoc.json",
"doc:publish": "gh-pages --dotfiles=true -m \"[ci skip] Updates\" -d docs",
"test": "cd ./test && node --inspect-brk=9229 ../bin/cli.js --load ./sprite.atl -astr -p 2 -m 1024,1024 --extrude 1 --trim --search-dummy --debug --save ./atlas/ui/",
"test": "cd ./test && node --inspect-brk=9229 ../bin/cli.js --group-folder -astr -p 2 -m 1024,1024 --extrude 1 --trim --search-dummy --debug ./atlas",
"version": "standard-version",
"commit": "npx git-cz"
},
Expand Down Expand Up @@ -44,17 +44,17 @@
"@types/mustache": "^0.8.32",
"@types/node": "^12.12.14",
"cz-conventional-changelog": "^2.1.0",
"gh-pages": "^2.1.1",
"patch-package": "^6.2.0",
"gh-pages": "^2.2.0",
"patch-package": "^6.2.2",
"postinstall-prepare": "^1.0.1",
"rimraf": "^2.7.1",
"standard-version": "^6.0.1",
"ts-node": "^8.5.4",
"tslib": "^1.10.0",
"ts-node": "^8.10.2",
"tslib": "^1.13.0",
"tslint": "^5.20.1",
"tslint-config-standard": "^8.0.1",
"typedoc": "^0.15.3",
"typescript": "^3.7.2"
"typedoc": "^0.15.8",
"typescript": "^3.9.7"
},
"dependencies": {
"@types/pixelmatch": "^5.0.0",
Expand All @@ -63,7 +63,7 @@
"maxrects-packer": "^2.5.0",
"mustache": "^3.1.0",
"pixelmatch": "^5.1.0",
"resource-loader": "^4.0.0-rc3"
"resource-loader": "^4.0.0-rc4"
},
"config": {
"commitizen": {
Expand Down
15 changes: 14 additions & 1 deletion src/atlasify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ export class Options implements IOption {
public seperateFolder: boolean = false;
public tag?: boolean;

/**
* Group sheets packing based on folder
*
* @type {boolean}
* @memberof Options
*/
public groupFolder: boolean = false;
public exclusiveTag?: boolean;

/**
* Remove surrounding transparent pixels
*
Expand Down Expand Up @@ -190,6 +199,10 @@ export class Atlasify {
this._inputPaths = [];
this._sheets = [];
if (options.seperateFolder) options.tag = true;
if (options.groupFolder) {
options.tag = true;
options.exclusiveTag = false;
}
this._packer = new MaxRectsPacker<Sheet>(options.width, options.height, options.padding, options);
this._exporter = new Exporter();
this._exporter.setExportFormat(this.options.type);
Expand Down Expand Up @@ -232,7 +245,7 @@ export class Atlasify {
} else if (this.options.trimAlpha) {
sheet.trimAlpha(this.options.alphaTolerence);
}
if (this.options.seperateFolder) {
if (this.options.seperateFolder || this.options.groupFolder) {
const tag = this.getLeafFolder(imgPath);
if (tag) sheet.tag = tag;
}
Expand Down
Binary file added test/atlas/items/coinBronze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/coinGold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/coinSilver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagBlue1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagBlue2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagBlue_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagGreen1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagGreen2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagGreen_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagRed1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagRed2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagRed_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagYellow1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagYellow2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/flagYellow_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/gemBlue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/gemGreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/gemRed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/gemYellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/keyBlue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/keyGreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/keyRed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/keyYellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/atlas/items/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4e6183a

Please sign in to comment.