Add palette functions to monitor peripheral

This commit is contained in:
Lignum 2017-05-05 18:12:33 +02:00
parent 088dab799e
commit 6997471280
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D
3 changed files with 56 additions and 14 deletions

View File

@ -279,12 +279,12 @@ public Object[] callMethod( ILuaContext context, int method, Object[] args ) thr
case 20:
{
// setColour/setColor
if ( args.length < 4 || !(args[0] instanceof Double) || !(args[1] instanceof Double) || !(args[2] instanceof Double) || !(args[3] instanceof Double) ) // toil and trouble
if( args.length < 4 || !(args[0] instanceof Double) || !(args[1] instanceof Double) || !(args[2] instanceof Double) || !(args[3] instanceof Double) ) // toil and trouble
{
throw new LuaException( "Expected number, number, number, number" );
}
if ( !m_environment.isColour() )
if( !m_environment.isColour() )
{
// Make sure you can't circumvent greyscale terminals with this function.
throw new LuaException( "Colour not supported" );
@ -320,7 +320,7 @@ public Object[] callMethod( ILuaContext context, int method, Object[] args ) thr
{
if ( m_terminal.getPalette() != null )
{
return ArrayUtils.toObject( m_terminal.getPalette().getColour64( colour ) );
return ArrayUtils.toObject( m_terminal.getPalette().getColour( colour ) );
}
}
return null;

View File

@ -11,6 +11,8 @@
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.util.Palette;
import org.apache.commons.lang3.ArrayUtils;
public class MonitorPeripheral implements IPeripheral
{
@ -52,7 +54,11 @@ public String[] getMethodNames()
"getTextColor",
"getBackgroundColour",
"getBackgroundColor",
"blit"
"blit",
"setColour",
"setColor",
"getColour",
"getColor"
};
}
@ -218,6 +224,52 @@ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int m
terminal.setCursorPos( terminal.getCursorX() + text.length(), terminal.getCursorY() );
return null;
}
case 20:
case 21:
{
// setColour/setColor
Terminal terminal = m_monitor.getTerminal().getTerminal();
Palette palette = terminal.getPalette();
// setColour/setColor
if( args.length < 4 || !(args[0] instanceof Double) || !(args[1] instanceof Double) || !(args[2] instanceof Double) || !(args[3] instanceof Double) )
{
throw new LuaException( "Expected number, number, number, number" );
}
boolean isColour = m_monitor.getTerminal().isColour();
if( !isColour )
{
throw new LuaException( "Colour not supported" );
}
int colour = 15 - dan200.computercraft.core.apis.TermAPI.parseColour( args, true );
float r = ((Double)args[1]).floatValue();
float g = ((Double)args[2]).floatValue();
float b = ((Double)args[3]).floatValue();
if( palette != null )
{
palette.setColour( colour, r, g, b );
}
return null;
}
case 22:
case 23:
{
// getColour/getColor
Terminal terminal = m_monitor.getTerminal().getTerminal();
Palette palette = terminal.getPalette();
int colour = 15 - dan200.computercraft.core.apis.TermAPI.parseColour( args, m_monitor.getTerminal().isColour() );
if( palette != null )
{
return ArrayUtils.toObject( palette.getColour( colour ) );
}
return null;
}
}
return null;
}

View File

@ -70,16 +70,6 @@ public float[] getColour( int i )
return null;
}
public double[] getColour64( int i )
{
if( i >= 0 && i < colours.length )
{
PaletteColour c = colours[ i ];
return new double[] { (double)c.m_r, (double)c.m_g, (double)c.m_b };
}
return null;
}
public void resetColour( int i )
{
if(i >= 0 && i < colours.length )