1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-06-26 23:22:53 +00:00

Don't store a mutable array in Colour

It's kinda bad form, and we no longer need it anyway!
This commit is contained in:
Jonathan Coates 2022-10-21 19:07:58 +01:00
parent c0d20b72c9
commit 695ef0542a
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 9 additions and 21 deletions

View File

@ -55,12 +55,7 @@ public class TermAPI extends TermMethods implements ILuaAPI
{ {
int actualColour = 15 - parseColour( colour ); int actualColour = 15 - parseColour( colour );
Colour c = Colour.fromInt( actualColour ); Colour c = Colour.fromInt( actualColour );
return new Object[] { c.getR(), c.getG(), c.getB() };
float[] rgb = c.getRGB();
Object[] rgbObj = new Object[rgb.length];
for( int i = 0; i < rgbObj.length; ++i ) rgbObj[i] = rgb[i];
return rgbObj;
} }
@Nonnull @Nonnull

View File

@ -28,7 +28,7 @@ public enum Colour
public static Colour fromInt( int colour ) public static Colour fromInt( int colour )
{ {
return colour >= 0 && colour < 16 ? Colour.VALUES[colour] : null; return Colour.VALUES[colour];
} }
public static Colour fromHex( int colour ) public static Colour fromHex( int colour )
@ -42,16 +42,14 @@ public enum Colour
} }
private final int hex; private final int hex;
private final float[] rgb; private final float red, green, blue;
Colour( int hex ) Colour( int hex )
{ {
this.hex = hex; this.hex = hex;
rgb = new float[] { red = ((hex >> 16) & 0xFF) / 255.0f;
((hex >> 16) & 0xFF) / 255.0f, green = ((hex >> 8) & 0xFF) / 255.0f;
((hex >> 8) & 0xFF) / 255.0f, blue = (hex & 0xFF) / 255.0f;
(hex & 0xFF) / 255.0f,
};
} }
public Colour getNext() public Colour getNext()
@ -69,23 +67,18 @@ public enum Colour
return hex; return hex;
} }
public float[] getRGB()
{
return rgb;
}
public float getR() public float getR()
{ {
return rgb[0]; return red;
} }
public float getG() public float getG()
{ {
return rgb[1]; return green;
} }
public float getB() public float getB()
{ {
return rgb[2]; return blue;
} }
} }