Skip to content

Commit

Permalink
add linting rule to ensure textures are minimum power of 16
Browse files Browse the repository at this point in the history
- if a texture isn't (e.g. its width is 1 pixel), we get a warning in the Minecraft game output (log)
- e.g. `Texture animated_java:item/black with size 1x1 limits mip level from 4 to 0`
  • Loading branch information
TheAfroOfDoom committed Jan 8, 2024
1 parent 87df41c commit 5767cc8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
29 changes: 29 additions & 0 deletions package-scripts/linting-rules/correct-texture-dimensions.js
Original file line number Diff line number Diff line change
@@ -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,
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 5767cc8

Please sign in to comment.