From 9fe85b3ca539928f05c15d953bec21f3e1539145 Mon Sep 17 00:00:00 2001 From: Tefek <31473117+493msi@users.noreply.github.com> Date: Sat, 16 Jan 2021 17:51:53 +0100 Subject: [PATCH] [PlutoLib/PlutoStatic] Added AWT to Pluto color conversion, code cleanup and equals for ResourceAddress --- .../tefek/pluto/engine/audio/AudioLoader.java | 2 +- .../io/asl/resource/ResourceAddress.java | 29 ++++++++--- .../java/cz/tefek/pluto/l10n/PlutoL10n.java | 9 +--- .../java/cz/tefek/pluto/util/color/Color.java | 52 +++++++++++++++++-- .../pluto/engine/graphics/gl/DrawMode.java | 4 +- .../graphics/gl/vbo/EnumArrayBufferType.java | 4 +- 6 files changed, 77 insertions(+), 23 deletions(-) diff --git a/plutoaudio/src/main/java/cz/tefek/pluto/engine/audio/AudioLoader.java b/plutoaudio/src/main/java/cz/tefek/pluto/engine/audio/AudioLoader.java index dedb0a2..51a0b3b 100644 --- a/plutoaudio/src/main/java/cz/tefek/pluto/engine/audio/AudioLoader.java +++ b/plutoaudio/src/main/java/cz/tefek/pluto/engine/audio/AudioLoader.java @@ -108,7 +108,7 @@ public class AudioLoader public static class MemoryPCMTrack extends SeekableTrack { - private ShortBuffer pcmAudio = null; + private final ShortBuffer pcmAudio; private int sampleOffset = 0; diff --git a/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/ResourceAddress.java b/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/ResourceAddress.java index 0a62edb..89f0bd3 100644 --- a/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/ResourceAddress.java +++ b/plutolib/src/main/java/cz/tefek/pluto/io/asl/resource/ResourceAddress.java @@ -5,6 +5,7 @@ import java.nio.file.FileSystems; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; import cz.tefek.pluto.io.logger.Logger; @@ -15,11 +16,15 @@ import cz.tefek.pluto.modloader.ModLoaderCore; * Resource address is a universal key for all resource and file loading. You * just need a {@link ResourceSubscriber} (which holds the root folder location) * and a {@link String} containing the address. The address itself works like a - * Java package. For example "sample.textures.test" formats as + * Java package. + * + *
+ * For example, "sample.textures.test" formats as
* [root_folder]/sample/textures/test
when converted using
* toPath()
. To define a file extension for your address, use the
* fileExtension(String)
method. To remove the file extension use
* fileExtension(null)
.
+ *
+ * Some methods mutate the object to avoid new object creation. + * These methods are prefixed with "store". + *
+ * + * @implNote Each of the color components is stored separately as a 32-bit integer + * to avoid unnecessary type conversion at the cost of some memory. + * + *+ * This however should not be a problem as this class is not designed + * for large-scale or performance-sensitive color operations. + *
* * @since 20.2.0.0-alpha.3 * @author 493msi @@ -73,7 +86,7 @@ public final class Color public int alpha = 255; /** - * TODO + * Creates a new Color object from the supplied RGBA color components. * * @since 20.2.0.0-alpha.3 * @author 493msi @@ -87,7 +100,9 @@ public final class Color } /** - * TODO + * Creates a new Color object from the supplied RGBA color components. + * + * Alpha is set to 255 by default. * * @since 20.2.0.0-alpha.3 * @author 493msi @@ -100,7 +115,13 @@ public final class Color } /** - * TODO + * Converts the supplied float-based {@link IRGBA} color object to a new {@link Color} object and returns it. + * + * @return A new {@link Color} object + * + * @param colorComponents An {@link IRGBA} color object + * + * @implNote Color values are rounded to the nearest integer. * * @since 20.2.0.0-alpha.3 * @author 493msi @@ -153,6 +174,17 @@ public final class Color } } + /** + * TODO + * + * @since 20.2.0.0-alpha.3 + * @author 493msi + */ + public static Color fromAWT(@Nonnull java.awt.Color color) + { + return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + } + /** * TODO * @@ -443,4 +475,16 @@ public final class Color target.s = hsb.s; target.b = hsb.b; } + + + /** + * TODO + * + * @since 20.2.0.0-alpha.3 + * @author 493msi + */ + public java.awt.Color toAWT() + { + return new java.awt.Color(this.red, this.green, this.blue, this.alpha); + } } diff --git a/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/DrawMode.java b/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/DrawMode.java index 5492999..516eb94 100644 --- a/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/DrawMode.java +++ b/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/DrawMode.java @@ -26,9 +26,9 @@ public enum DrawMode implements IOpenGLEnum TRIANGLE_STRIP_ADJACENCY(GL33.GL_TRIANGLE_STRIP_ADJACENCY), PATCHES(GL40.GL_PATCHES); - private int glID; + private final int glID; - private DrawMode(int id) + DrawMode(int id) { this.glID = id; } diff --git a/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/vbo/EnumArrayBufferType.java b/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/vbo/EnumArrayBufferType.java index 6e53745..708669a 100644 --- a/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/vbo/EnumArrayBufferType.java +++ b/plutomesher/src/main/java/cz/tefek/pluto/engine/graphics/gl/vbo/EnumArrayBufferType.java @@ -10,9 +10,9 @@ public enum EnumArrayBufferType implements IOpenGLEnum INT(GL33.GL_INT), UNSIGNED_INT(GL33.GL_UNSIGNED_INT); - private int glID; + private final int glID; - private EnumArrayBufferType(int glEnum) + EnumArrayBufferType(int glEnum) { this.glID = glEnum; }