UNPKG

@image/packer

Version:
48 lines (47 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Spritesheet_1 = require("./Spritesheet"); var MultiBinPacker_1 = require("./MultiBinPacker"); var AtlasGroup = (function () { function AtlasGroup(scaledSprites, layoutConfig, exportConfig, cache, imageProcessor, log) { this.scaledSprites = scaledSprites; this.layoutConfig = layoutConfig; this.exportConfig = exportConfig; this.cache = cache; this.imageProcessor = imageProcessor; this.log = log; this.spritesheets = []; this.hash = this.calculateHash(); } AtlasGroup.prototype.calculateHash = function () { var str = this.scaledSprites.map(function (i) { return i.hash; }).sort().join(" "); str += JSON.stringify(this.layoutConfig, null, 2); str += JSON.stringify(this.exportConfig, null, 2); return this.cache.createHash(str); }; AtlasGroup.prototype.process = function (queue) { var _this = this; var packer = new MultiBinPacker_1.MultiBinPacker(this.layoutConfig.max_width, this.layoutConfig.max_height, this.layoutConfig.padding); packer.addArray(this.scaledSprites.map(function (scaledSprite) { return { width: scaledSprite.trim ? scaledSprite.trim.width : scaledSprite.width, height: scaledSprite.trim ? scaledSprite.trim.height : scaledSprite.height, data: scaledSprite }; })); if (this.layoutConfig.oversized_warning) { packer.oversizedElements.map(function (bin) { _this.log.warn('Oversized sprite: ' + bin.data.sprite.path + ' with size ' + bin.width + 'x' + bin.height); }); } this.spritesheets = packer.bins.map(function (bin) { return new Spritesheet_1.default(_this, bin, _this.exportConfig, _this.cache, _this.imageProcessor); }); return Promise.all(this.spritesheets.map(function (spritesheet) { return queue.add(function () { return spritesheet.process(); }); })); }; return AtlasGroup; }()); exports.default = AtlasGroup;