diff options
author | isXander <xandersmith2008@gmail.com> | 2023-05-21 14:36:37 +0100 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-05-21 14:36:37 +0100 |
commit | c84415116455d108ad07fc8dd6232c9acc94c40f (patch) | |
tree | 9c6a20b611e45eedeb512b8294f7147575d56af9 /common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java | |
parent | 21afea0da3956f2d8cca81a54fa9820152e0c077 (diff) | |
download | YetAnotherConfigLib-c84415116455d108ad07fc8dd6232c9acc94c40f.tar.gz YetAnotherConfigLib-c84415116455d108ad07fc8dd6232c9acc94c40f.tar.bz2 YetAnotherConfigLib-c84415116455d108ad07fc8dd6232c9acc94c40f.zip |
Automatic WebP frame duration detection
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java')
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java b/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java index f57a410..c866b43 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java @@ -38,7 +38,7 @@ public record OptionDescriptionImpl(Component descriptiveName, Component descrip Validate.isTrue(width > 0, "Width must be greater than 0!"); Validate.isTrue(height > 0, "Height must be greater than 0!"); - this.image = CompletableFuture.completedFuture(Optional.of(new ImageRenderer.TextureBacked(image, width, height))); + this.image = ImageRenderer.getOrMakeSync(image, () -> Optional.of(new ImageRenderer.TextureBacked(image, width, height))); imageUnset = false; return this; } @@ -46,7 +46,7 @@ public record OptionDescriptionImpl(Component descriptiveName, Component descrip @Override public Builder image(Path path, ResourceLocation uniqueLocation) { Validate.isTrue(imageUnset, "Image already set!"); - this.image = CompletableFuture.supplyAsync(() -> ImageRenderer.NativeImageBacked.createFromPath(path, uniqueLocation)); + this.image = ImageRenderer.getOrMakeAsync(uniqueLocation, () -> ImageRenderer.NativeImageBacked.createFromPath(path, uniqueLocation)); imageUnset = false; return this; } @@ -54,7 +54,7 @@ public record OptionDescriptionImpl(Component descriptiveName, Component descrip @Override public Builder gifImage(ResourceLocation image) { Validate.isTrue(imageUnset, "Image already set!"); - this.image = CompletableFuture.supplyAsync(() -> { + this.image = ImageRenderer.getOrMakeAsync(image, () -> { try { return Optional.of(ImageRenderer.AnimatedNativeImageBacked.createGIFFromTexture(image)); } catch (IOException e) { @@ -69,7 +69,7 @@ public record OptionDescriptionImpl(Component descriptiveName, Component descrip @Override public Builder gifImage(Path path, ResourceLocation uniqueLocation) { Validate.isTrue(imageUnset, "Image already set!"); - this.image = CompletableFuture.supplyAsync(() -> { + this.image = ImageRenderer.getOrMakeAsync(uniqueLocation, () -> { try { return Optional.of(ImageRenderer.AnimatedNativeImageBacked.createGIF(new FileInputStream(path.toFile()), uniqueLocation)); } catch (IOException e) { @@ -82,11 +82,11 @@ public record OptionDescriptionImpl(Component descriptiveName, Component descrip } @Override - public Builder webpImage(ResourceLocation image, int frameDelayMS) { + public Builder webpImage(ResourceLocation image) { Validate.isTrue(imageUnset, "Image already set!"); - this.image = CompletableFuture.supplyAsync(() -> { + this.image = ImageRenderer.getOrMakeAsync(image, () -> { try { - return Optional.of(ImageRenderer.AnimatedNativeImageBacked.createWEBPFromTexture(image, frameDelayMS)); + return Optional.of(ImageRenderer.AnimatedNativeImageBacked.createWEBPFromTexture(image)); } catch (IOException e) { e.printStackTrace(); return Optional.empty(); @@ -97,11 +97,11 @@ public record OptionDescriptionImpl(Component descriptiveName, Component descrip } @Override - public Builder webpImage(Path path, ResourceLocation uniqueLocation, int frameDelayMS) { + public Builder webpImage(Path path, ResourceLocation uniqueLocation) { Validate.isTrue(imageUnset, "Image already set!"); - this.image = CompletableFuture.supplyAsync(() -> { + this.image = ImageRenderer.getOrMakeAsync(uniqueLocation, () -> { try { - return Optional.of(ImageRenderer.AnimatedNativeImageBacked.createWEBP(new FileInputStream(path.toFile()), uniqueLocation, frameDelayMS)); + return Optional.of(ImageRenderer.AnimatedNativeImageBacked.createWEBP(new FileInputStream(path.toFile()), uniqueLocation)); } catch (IOException e) { e.printStackTrace(); return Optional.empty(); |