ImagePacker detects changed settings file, improve documentation. (#11625)

This commit is contained in:
SomeTroglodyte
2024-05-21 18:55:22 +02:00
committed by GitHub
parent 65b519cb1f
commit ec253a5886
3 changed files with 23 additions and 14 deletions

View File

@ -105,8 +105,8 @@ object AndroidImagePacker {
if (File(input).listTree().none { if (File(input).listTree().none {
val attr: BasicFileAttributes = Files.readAttributes(it.toPath(), BasicFileAttributes::class.java) val attr: BasicFileAttributes = Files.readAttributes(it.toPath(), BasicFileAttributes::class.java)
val createdAt: Long = attr.creationTime().toMillis() val createdAt: Long = attr.creationTime().toMillis()
it.extension in listOf("png", "jpg", "jpeg") (it.extension in listOf("png", "jpg", "jpeg") || it.name == "TexturePacker.settings")
&& (it.lastModified() > atlasModTime || createdAt > atlasModTime) && (it.lastModified() > atlasModTime || createdAt > atlasModTime)
}) return }) return
} }
@ -131,4 +131,3 @@ object AndroidImagePacker {
} }
} }
} }

View File

@ -58,7 +58,7 @@ internal object ImagePacker {
// Trying to disable the subdirectory combine lead to even worse results. Don't. // Trying to disable the subdirectory combine lead to even worse results. Don't.
combineSubdirectories = true combineSubdirectories = true
pot = true // powers of two only for width/height pot = true // powers of two only for width/height, default anyway, repeat for clarity
fast = true // with pot on this just sorts by width fast = true // with pot on this just sorts by width
// settings.rotation - do not set. Allows rotation, potentially packing tighter. // settings.rotation - do not set. Allows rotation, potentially packing tighter.
// Proper rendering is mostly automatic - except borders which overwrite rotation. // Proper rendering is mostly automatic - except borders which overwrite rotation.
@ -68,7 +68,7 @@ internal object ImagePacker {
paddingY = 8 paddingY = 8
duplicatePadding = true duplicatePadding = true
filterMin = Texture.TextureFilter.MipMapLinearLinear filterMin = Texture.TextureFilter.MipMapLinearLinear
filterMag = Texture.TextureFilter.MipMapLinearLinear // I'm pretty sure this doesn't make sense for magnification, but setting it to Linear gives strange results filterMag = Texture.TextureFilter.MipMapLinearLinear // This is changed to Linear if the folder name ends in `Icons` - see `suffixUsingLinear`
} }
fun packImages(isRunFromJAR: Boolean) { fun packImages(isRunFromJAR: Boolean) {
@ -135,7 +135,7 @@ internal object ImagePacker {
if (File(input).listTree().none { if (File(input).listTree().none {
val attr: BasicFileAttributes = Files.readAttributes(it.toPath(), BasicFileAttributes::class.java) val attr: BasicFileAttributes = Files.readAttributes(it.toPath(), BasicFileAttributes::class.java)
val createdAt: Long = attr.creationTime().toMillis() val createdAt: Long = attr.creationTime().toMillis()
it.extension in imageExtensions (it.extension in imageExtensions || it.name == "TexturePacker.settings")
&& (it.lastModified() > atlasModTime || createdAt > atlasModTime) && (it.lastModified() > atlasModTime || createdAt > atlasModTime)
}) return }) return
} }

View File

@ -13,7 +13,7 @@ If you're developing your mod on an Android version of Unciv (not recommended!)
### Ways to pack texture atlases ### Ways to pack texture atlases
- Texture atlases *CANNOT BE PACKED* on Android (technical reason: TexturePacker uses `java.awt` to do heavy lifting, which is unavailable on Android 0_0) - Texture atlases *CANNOT BE PACKED* on Android (technical reason: TexturePacker uses `java.awt` to do heavy lifting, which is unavailable on Android 0_0)
- Launch the desktop version with your mod (your mod's main folder is a subfolder of the game's "mods" folder, or symlinked there). - Launch the desktop version with your mod (your mod's main folder is a subfolder of the game's "mods" folder, or symlinked there). This uses the packing methods [documented here](https://libgdx.com/wiki/tools/texture-packer).
- You can ask someone in the Discord server to help you out. - You can ask someone in the Discord server to help you out.
- You can use external tools, [e.g. gdx-texture-packer-gui](https://github.com/crashinvaders/gdx-texture-packer-gui). Utmost care needs to be taken that the files can be discovered by Unciv and internal relative paths are correct. - You can use external tools, [e.g. gdx-texture-packer-gui](https://github.com/crashinvaders/gdx-texture-packer-gui). Utmost care needs to be taken that the files can be discovered by Unciv and internal relative paths are correct.
- The Unciv repo itself has a feature that can pack images on github runners - documentation still needs to be done. - The Unciv repo itself has a feature that can pack images on github runners - documentation still needs to be done.
@ -34,13 +34,23 @@ If you use external tools and multiple atlases, you will need to maintain this f
The texture packers built into Unciv will look for a `TexturePacker.settings` file in each `Images` directory (_not_ under `jsons`). The texture packers built into Unciv will look for a `TexturePacker.settings` file in each `Images` directory (_not_ under `jsons`).
With this file you can tune the packer - e.g. control pixel interpolation filters. With this file you can tune the packer - e.g. control pixel interpolation filters.
It is a json of a [Gdx TexturePacker.Settings](https://libgdx.com/wiki/tools/texture-packer#settings) instance. It is a json of a [Gdx TexturePacker.Settings](https://libgdx.com/wiki/tools/texture-packer#settings) instance.
The default settings are as shown in the Gdx documentation linked above if you do supply a settings file, but without such a file, some fields have different defaults: The default settings are as shown in the Gdx documentation linked above if you do supply a settings file, but without such a file, some fields have different defaults.
- `maxWidth`, `maxHeight`: 2048 To get these changed defaults, start with the following as base for your custom `TexturePacker.settings` file:
- `fast`: true
- `paddingX`, `paddingY`: 8 ```json
- `duplicatePadding`: true {
- `filterMin`: MipMapLinearLinear "fast": true,
- `filterMag`: MipMapLinearLinear unless the atlas name ends in `Icons`, then Linear. "combineSubdirectories": true,
"maxWidth": 2048,
"maxHeight": 2048,
"paddingX": 8,
"paddingY": 8,
"duplicatePadding": true,
"filterMin": "MipMapLinearLinear",
"filterMag": "MipMapLinearLinear",
}
```
(change "filterMag" to "Linear" if your atlas name will end in "Icons".)
### Texture atlas encoding ### Texture atlas encoding