[PlutoLib/PlutoStatic] Added AWT to Pluto color conversion, code cleanup and equals for ResourceAddress

This commit is contained in:
Tefek 2021-01-16 17:51:53 +01:00
parent a4d5d102f2
commit a2b4db86df
6 changed files with 77 additions and 23 deletions

View File

@ -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;

View File

@ -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 <i>"sample.textures.test"</i> formats as
* Java package.
*
* <p>
* For example, <i>"sample.textures.test"</i> formats as
* <code>[root_folder]/sample/textures/test</code> when converted using
* <code>toPath()</code>. To define a file extension for your address, use the
* <code>fileExtension(String)</code> method. To remove the file extension use
* <code>fileExtension(null)</code>.
* </p>
*
* @author 493msi
*
@ -291,14 +296,24 @@ public class ResourceAddress
return Path.of(pathBuilder.toString());
}
@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (o == null || this.getClass() != o.getClass())
return false;
ResourceAddress that = (ResourceAddress) o;
return this.subAddress.equals(that.subAddress) &&
this.resSubscriber.equals(that.resSubscriber) &&
Objects.equals(this.fileExtension, that.fileExtension);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((this.fileExtension == null) ? 0 : this.fileExtension.hashCode());
result = prime * result + this.resSubscriber.hashCode();
result = prime * result + this.subAddress.hashCode();
return result;
return Objects.hash(subAddress, resSubscriber, fileExtension);
}
}

View File

@ -11,7 +11,7 @@ public class PlutoL10n
{
private static Locale defaultLocale;
private static Map<Locale, Map<String, String>> localizations = new HashMap<>();
private static final Map<Locale, Map<String, String>> localizations = new HashMap<>();
public static void init(Locale locale)
{
@ -25,12 +25,7 @@ public class PlutoL10n
public static void registerLocale(Locale locale)
{
if (localizations.containsKey(locale))
{
return;
}
localizations.put(locale, new HashMap<>());
localizations.computeIfAbsent(locale, key -> new HashMap<>());
}
public static void setLocale(Locale locale)

View File

@ -3,7 +3,20 @@ package cz.tefek.pluto.util.color;
import javax.annotation.Nonnull;
/**
* TODO
* A simple 8-bit RGBA color container.
*
* <p><em>
* Some methods mutate the object to avoid new object creation.
* These methods are prefixed with "store".
* </em></p>
*
* @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.
*
* <p>
* This however should not be a problem as <em>this class is not designed
* for large-scale or performance-sensitive color operations</em>.
* </p>
*
* @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);
}
}

View File

@ -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;
}

View File

@ -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;
}