-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add linting rule to ensure textures are minimum power of 16
- 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
1 parent
87df41c
commit 5767cc8
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
package-scripts/linting-rules/correct-texture-dimensions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters