diff --git a/scripts/stats.js b/scripts/stats.js index b75ef7f01..f5da4f778 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -1,6 +1,7 @@ import * as Style from "../src/js/style.js"; import config from "../src/config.js"; import { Command, Option } from "commander"; +import fs from "node:fs"; const program = new Command(); program @@ -18,6 +19,18 @@ program .addOption( new Option("-s, --layer-size", "size of all layers").conflicts("allJson") ) + .addOption( + new Option( + "-ss1, --spritesheet-1x-size", + "size of 1x sprite sheet" + ).conflicts("allJson") + ) + .addOption( + new Option( + "-ss2, --spritesheet-2x-size", + "size of 2x sprite sheet" + ).conflicts("allJson") + ) .option("-loc, --locales ", "language codes", ["mul"]) .option("-j, --all-json", "output all stats in JSON") .option("-pp, --pretty", "pretty-print JSON output"); @@ -45,6 +58,27 @@ if (opts.layerCount) { process.exit(); } +function spriteSheetSize(single) { + let size = single ? "" : "@2x"; + return ( + fs.statSync(`dist/sprites/sprite${size}.png`).size + + fs.statSync(`dist/sprites/sprite${size}.json`).size + ); +} + +const spriteSheet1xSize = spriteSheetSize(true); +const spriteSheet2xSize = spriteSheetSize(false); + +if (opts.spritesheet1xSize) { + console.log(spriteSheet1xSize); + process.exit(); +} + +if (opts.spritesheet2xSize) { + console.log(spriteSheet2xSize); + process.exit(); +} + const styleSize = JSON.stringify(layers).length; if (opts.layerSize) { @@ -58,6 +92,8 @@ const stats = { layerCount, styleSize, layerGroup: {}, + spriteSheet1xSize, + spriteSheet2xSize, }; for (let i = 0; i < layerCount; i++) { diff --git a/scripts/stats_compare.js b/scripts/stats_compare.js index 45f70dad7..7f71e23ba 100644 --- a/scripts/stats_compare.js +++ b/scripts/stats_compare.js @@ -22,12 +22,26 @@ const layersRow = mdCompareRow( ); const sizeRow = mdCompareRow( - "Size (b)", + "StyleJSON Size (b)", stats1.styleSize, stats2.styleSize, difference.styleSize ); +const ss1xRow = mdCompareRow( + "1x Sprite Sheet Size (b)", + stats1.spriteSheet1xSize, + stats2.spriteSheet1xSize, + difference.spriteSheet1xSize +); + +const ss2xRow = mdCompareRow( + "2x Sprite Sheet Size (b)", + stats1.spriteSheet2xSize, + stats2.spriteSheet2xSize, + difference.spriteSheet2xSize +); + printTable("Style size statistics", [layersRow, sizeRow]); /**