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

Add term.nativePaletteColo(u)r

This commit is contained in:
Lignum 2017-09-04 16:19:38 +02:00 committed by SquidDev
parent fb59da2b06
commit 070fd1f2ff
2 changed files with 25 additions and 4 deletions

View File

@ -11,6 +11,7 @@
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.computer.IComputerEnvironment;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Palette;
import org.apache.commons.lang3.ArrayUtils;
@ -65,6 +66,8 @@ public String[] getMethodNames()
"setPaletteColor",
"getPaletteColour",
"getPaletteColor",
"nativePaletteColour",
"nativePaletteColor",
"getCursorBlink",
};
}
@ -289,6 +292,19 @@ public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull O
return null;
}
case 23:
case 24:
{
// nativePaletteColour/nativePaletteColor
int colour = 15 - parseColour( args );
Colour c = Colour.fromInt( colour );
float[] rgb = c.getRGB();
Object[] rgbObj = new Object[rgb.length];
for( int i = 0; i < rgbObj.length; ++i ) rgbObj[i] = rgb[i];
return rgbObj;
}
case 25:
// getCursorBlink
return new Object[] { m_terminal.getCursorBlink() };
default:

View File

@ -42,11 +42,16 @@ term.native = function()
return native
end
-- Some methods shouldn't go through redirects, so we move them to the main
-- term API.
for _, method in ipairs { "nativePaletteColor", "nativePaletteColour"} do
term[method] = native[method]
native[method] = nil
end
for k,v in pairs( native ) do
if type( k ) == "string" and type( v ) == "function" then
if term[k] == nil then
term[k] = wrap( k )
end
if type( k ) == "string" and type( v ) == "function" and term[k] == nil then
term[k] = wrap( k )
end
end