Restore previous behaviour for unknown colours

Unknown blit colours, such as " " will be translated to black for the
background or white for the foreground. This restores the behaviour from
before #412.
This commit is contained in:
SquidDev 2020-05-04 09:15:23 +01:00
parent 17b7727262
commit 550ada2f9e
2 changed files with 11 additions and 8 deletions

View File

@ -55,10 +55,9 @@ private static float toGreyscale( double[] rgb )
return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3);
}
private static int getColour( char c )
private static int getColour( char c, Colour def )
{
int i = "0123456789abcdef".indexOf( c );
return i < 0 ? 0 : 15 - i;
return 15 - Terminal.getColour( c, def );
}
private static void drawChar( BufferBuilder buffer, float x, float y, int index, float r, float g, float b )
@ -92,7 +91,7 @@ private static void drawQuad( BufferBuilder buffer, float x, float y, float widt
private static void drawQuad( BufferBuilder buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex )
{
double[] colour = palette.getColour( getColour( colourIndex ) );
double[] colour = palette.getColour( getColour( colourIndex, Colour.Black ) );
float r, g, b;
if( greyscale )
{
@ -160,7 +159,7 @@ public static void drawString(
for( int i = 0; i < text.length(); i++ )
{
double[] colour = palette.getColour( getColour( textColour.charAt( i ) ) );
double[] colour = palette.getColour( getColour( textColour.charAt( i ), Colour.White ) );
float r, g, b;
if( greyscale )
{

View File

@ -5,6 +5,7 @@
*/
package dan200.computercraft.core.terminal;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Palette;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
@ -342,7 +343,10 @@ public synchronized void write( PacketBuffer buffer )
for( int x = 0; x < m_width; x++ )
{
buffer.writeByte( text.charAt( x ) & 0xFF );
buffer.writeByte( colourIndex( backColour.charAt( x ) ) << 4 | colourIndex( textColour.charAt( x ) ) );
buffer.writeByte( getColour(
backColour.charAt( x ), Colour.Black ) << 4 |
getColour( textColour.charAt( x ), Colour.White )
);
}
}
@ -428,10 +432,10 @@ public synchronized void readFromNBT( NBTTagCompound nbt )
setChanged();
}
private static int colourIndex( char c )
public static int getColour( char c, Colour def )
{
if( c >= '0' && c <= '9' ) return c - '0';
if( c >= 'a' && c <= 'f' ) return c - 'a' + 10;
return 0;
return 15 - def.ordinal();
}
}