From a382ebb46bb6e4a1042c6985df7ddb918f46038c Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 1 Nov 2024 16:55:36 +0100 Subject: [PATCH] fix: add some fail-safes for gifs --- core/src/main/kotlin/com/mineinabyss/emojy/config/Gif.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/mineinabyss/emojy/config/Gif.kt b/core/src/main/kotlin/com/mineinabyss/emojy/config/Gif.kt index 895c4f2..7efa6e3 100644 --- a/core/src/main/kotlin/com/mineinabyss/emojy/config/Gif.kt +++ b/core/src/main/kotlin/com/mineinabyss/emojy/config/Gif.kt @@ -120,10 +120,12 @@ data class Gif( runCatching { val gifFolder = gifFolder.resolve(id) - GifConverter.splitGif(gifFile, calculateFramecount()) + if (gifFile.exists()) GifConverter.splitGif(gifFile, calculateFramecount()) + else if (!gifSpriteSheet.exists() && !gifFolder.exists()) emojy.logger.w("No .gif or sprite-sheet found for $id") createSpritesheet(gifFolder) - Texture.texture(Key.key("${framePath.asString()}.png"), Writable.file(gifSpriteSheet)).addTo(resourcePack) + if (gifSpriteSheet.exists()) Texture.texture(Key.key("${framePath.asString()}.png"), Writable.file(gifSpriteSheet)).addTo(resourcePack) + else emojy.logger.w("Could not find sprite-sheet for ${id}") gifFolder.deleteRecursively() }.onFailure { emojy.logger.d("Could not generate split gif for ${id}.gif: ${it.message}") @@ -134,7 +136,7 @@ data class Gif( val frames = gifFolder.listFiles() ?.filter { it.isFile && it.extension == "png" } ?.sortedBy { it.nameWithoutExtension.toIntOrNull() } - ?: throw IllegalStateException("No frame files found in $gifFolder") + ?: return emojy.logger.w("No frame files found in $gifFolder") val (frameWidth, frameHeight) = ImageIO.read(frames.first()).let { it.width to it.height } val spritesheet = BufferedImage(frameWidth, frameCount * frameHeight, BufferedImage.TYPE_INT_ARGB)