mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-11 08:30:04 +00:00
Get rid of setPaletteColour table overload
This commit is contained in:
parent
941d47908f
commit
c10e1ba78c
@ -120,50 +120,6 @@ public class TermAPI implements ILuaAPI
|
||||
}
|
||||
}
|
||||
|
||||
public static void setColour( Terminal terminal, HashMap<Object, Object> colours) throws LuaException
|
||||
{
|
||||
final double lg2 = Math.log( 2 );
|
||||
|
||||
for(Map.Entry<Object, Object> e : colours.entrySet())
|
||||
{
|
||||
if(e.getKey() instanceof Double)
|
||||
{
|
||||
int index = 15 - (int)( Math.log( (Double)e.getKey() ) / lg2 );
|
||||
|
||||
try
|
||||
{
|
||||
if (e.getValue() instanceof HashMap)
|
||||
{
|
||||
@SuppressWarnings({ "unchecked" }) // There isn't really a nice way around this :(
|
||||
HashMap<Object, Object> colour = (HashMap<Object, Object>) e.getValue();
|
||||
|
||||
setColour(
|
||||
terminal,
|
||||
index,
|
||||
( (Double)colour.get( 1.0 ) ).floatValue(),
|
||||
( (Double)colour.get( 2.0 ) ).floatValue(),
|
||||
( (Double)colour.get( 3.0 ) ).floatValue()
|
||||
);
|
||||
}
|
||||
else if (e.getValue() instanceof Double)
|
||||
{
|
||||
float[] rgb = Palette.decodeRGB8( ((Double)e.getValue()).intValue() );
|
||||
|
||||
setColour(
|
||||
terminal,
|
||||
index,
|
||||
rgb[0], rgb[1], rgb[2]
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(ClassCastException cce)
|
||||
{
|
||||
throw new LuaException( "Malformed colour table " + cce.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException
|
||||
{
|
||||
@ -337,14 +293,6 @@ public class TermAPI implements ILuaAPI
|
||||
case 20:
|
||||
{
|
||||
// setPaletteColour/setPaletteColor
|
||||
if(args.length >= 1 && args[0] instanceof HashMap)
|
||||
{
|
||||
@SuppressWarnings( { "unchecked" } ) // There isn't really a nice way around this :(
|
||||
HashMap<Object, Object> colourTbl = (HashMap<Object, Object>)args[0];
|
||||
setColour( m_terminal, colourTbl );
|
||||
return null;
|
||||
}
|
||||
|
||||
if(args.length == 2 && args[0] instanceof Double && args[1] instanceof Double)
|
||||
{
|
||||
int colour = 15 - parseColour( args, true );
|
||||
@ -364,7 +312,7 @@ public class TermAPI implements ILuaAPI
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new LuaException( "Expected table or number, number or number, number, number, number" );
|
||||
throw new LuaException( "Expected number, number or number, number, number, number" );
|
||||
}
|
||||
case 21:
|
||||
case 22:
|
||||
|
@ -232,14 +232,6 @@ public class MonitorPeripheral implements IPeripheral
|
||||
// setPaletteColour/setPaletteColor
|
||||
Terminal terminal = m_monitor.getTerminal().getTerminal();
|
||||
|
||||
if(args.length >= 1 && args[0] instanceof HashMap )
|
||||
{
|
||||
@SuppressWarnings( { "unchecked" } ) // There isn't really a nice way around this :(
|
||||
HashMap<Object, Object> colourTbl = (HashMap<Object, Object>)args[0];
|
||||
dan200.computercraft.core.apis.TermAPI.setColour( terminal, colourTbl );
|
||||
return null;
|
||||
}
|
||||
|
||||
if(args.length == 2 && args[0] instanceof Double && args[1] instanceof Double)
|
||||
{
|
||||
int colour = 15 - dan200.computercraft.core.apis.TermAPI.parseColour( args, true );
|
||||
@ -259,7 +251,7 @@ public class MonitorPeripheral implements IPeripheral
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new LuaException( "Expected table or number, number, number, number" );
|
||||
throw new LuaException( "Expected number, number or number, number, number, number" );
|
||||
}
|
||||
case 22:
|
||||
case 23:
|
||||
|
@ -107,7 +107,9 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible )
|
||||
end
|
||||
|
||||
local function updatePalette()
|
||||
return parent.setPaletteColour( tPalette )
|
||||
for k,v in pairs( tPalette ) do
|
||||
parent.setPaletteColour( k, table.unpack( v ) )
|
||||
end
|
||||
end
|
||||
|
||||
local function internalBlit( sText, sTextColor, sBackgroundColor )
|
||||
@ -287,19 +289,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible )
|
||||
end
|
||||
|
||||
function window.setPaletteColour( colour, r, g, b )
|
||||
if type(colour) == "table" then
|
||||
for k,v in pairs(colour) do
|
||||
if type(v) == "number" then
|
||||
local vr, vg, vb = colours.rgb8( v )
|
||||
tPalette[k] = { vr, vg, vb }
|
||||
parent.setPaletteColour( k, vr, vg, vb )
|
||||
elseif type(v) == "table" then
|
||||
tPalette[k] = v
|
||||
parent.setPaletteColour( k, table.unpack( v ) )
|
||||
end
|
||||
end
|
||||
return
|
||||
elseif type(colour) == "number" and type(r) == "number" and g == nil and b == nil then
|
||||
if type(colour) == "number" and type(r) == "number" and g == nil and b == nil then
|
||||
tPalette[ colour ] = { colours.rgb8( r ) }
|
||||
elseif type(colour) == "number" and type(r) == "number" and type(g) == "number" and type(b) == "number" then
|
||||
local tCol = tPalette[ colour ]
|
||||
|
Loading…
x
Reference in New Issue
Block a user