diff --git a/package-scripts/linting-rules/correct-texture-dimensions.js b/package-scripts/linting-rules/correct-texture-dimensions.js new file mode 100644 index 000000000..c38585e09 --- /dev/null +++ b/package-scripts/linting-rules/correct-texture-dimensions.js @@ -0,0 +1,29 @@ +const sizeOf = require('image-size'); + +const name = 'correct-image-dimensions'; +const applicableExtensions = ['.png']; + +const correctImageDimensions = (file) => { + // Return early if file does not match any applicable extension + if (applicableExtensions.every((extension) => !file.endsWith(extension))) { + return []; + } + + const errors = []; + + const { width, height } = sizeOf(file); + + if (width % 16 !== 0) { + errors.push(`image width must be divisible by 16 (was ${width})`); + } + if (height % 16 !== 0) { + errors.push(`image height must be divisible by 16 (was ${height})`); + } + + return errors; +}; + +module.exports = { + function: correctImageDimensions, + name, +}; diff --git a/package.json b/package.json index 3e700da5f..2f59b81a6 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "cpy-cli": "5.0.0", "eslint": "8.56.0", "glob": "10.3.10", + "image-size": "1.1.1", "minimatch": "9.0.3", "minimist": "1.2.8", "nps": "5.10.0", diff --git a/yarn.lock b/yarn.lock index 3c3d02150..6763bb25d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1472,6 +1472,17 @@ __metadata: languageName: node linkType: hard +"image-size@npm:1.1.1": + version: 1.1.1 + resolution: "image-size@npm:1.1.1" + dependencies: + queue: 6.0.2 + bin: + image-size: bin/image-size.js + checksum: 23b3a515dded89e7f967d52b885b430d6a5a903da954fce703130bfb6069d738d80e6588efd29acfaf5b6933424a56535aa7bf06867e4ebd0250c2ee51f19a4a + languageName: node + linkType: hard + "import-fresh@npm:^3.2.1": version: 3.3.0 resolution: "import-fresh@npm:3.3.0" @@ -2142,6 +2153,7 @@ __metadata: cpy-cli: 5.0.0 eslint: 8.56.0 glob: 10.3.10 + image-size: 1.1.1 minimatch: 9.0.3 minimist: 1.2.8 nps: 5.10.0 @@ -2585,6 +2597,15 @@ __metadata: languageName: node linkType: hard +"queue@npm:6.0.2": + version: 6.0.2 + resolution: "queue@npm:6.0.2" + dependencies: + inherits: ~2.0.3 + checksum: ebc23639248e4fe40a789f713c20548e513e053b3dc4924b6cb0ad741e3f264dcff948225c8737834dd4f9ec286dbc06a1a7c13858ea382d9379f4303bcc0916 + languageName: node + linkType: hard + "read-pkg-up@npm:^1.0.1": version: 1.0.1 resolution: "read-pkg-up@npm:1.0.1"