mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 11:10:29 +00:00
Merge pull request #120 from SquidDev-CC/feature/palette-improvements
Minor palette improvements
This commit is contained in:
commit
257a35f3ed
@ -11,6 +11,7 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.core.computer.IComputerEnvironment;
|
import dan200.computercraft.core.computer.IComputerEnvironment;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
@ -65,6 +66,8 @@ public class TermAPI implements ILuaAPI
|
|||||||
"setPaletteColor",
|
"setPaletteColor",
|
||||||
"getPaletteColour",
|
"getPaletteColour",
|
||||||
"getPaletteColor",
|
"getPaletteColor",
|
||||||
|
"nativePaletteColour",
|
||||||
|
"nativePaletteColor",
|
||||||
"getCursorBlink",
|
"getCursorBlink",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -289,6 +292,19 @@ public class TermAPI implements ILuaAPI
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 23:
|
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
|
// getCursorBlink
|
||||||
return new Object[] { m_terminal.getCursorBlink() };
|
return new Object[] { m_terminal.getCursorBlink() };
|
||||||
default:
|
default:
|
||||||
|
@ -48,22 +48,36 @@ function test( colors, color )
|
|||||||
if type( color ) ~= "number" then
|
if type( color ) ~= "number" then
|
||||||
error( "bad argument #2 (expected number, got " .. type( color ) .. ")", 2 )
|
error( "bad argument #2 (expected number, got " .. type( color ) .. ")", 2 )
|
||||||
end
|
end
|
||||||
return ((bit32.band(colors, color)) == color)
|
return bit32.band(colors, color) == color
|
||||||
|
end
|
||||||
|
|
||||||
|
function packRGB( r, g, b )
|
||||||
|
if type( r ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( r ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if type( g ) ~= "number" then
|
||||||
|
error( "bad argument #2 (expected number, got " .. type( g ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if type( b ) ~= "number" then
|
||||||
|
error( "bad argument #3 (expected number, got " .. type( b ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
return
|
||||||
|
bit32.band( r, 0xFF ) * 2^16 +
|
||||||
|
bit32.band( g, 0xFF ) * 2^8 +
|
||||||
|
bit32.band( b, 0xFF )
|
||||||
|
end
|
||||||
|
|
||||||
|
function unpackRGB( rgb )
|
||||||
|
if type( rgb ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( rgb ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
return bit32.band( bit32.rshift( rgb, 16 ), 0xFF ), bit32.band( bit32.rshift( rgb, 8 ), 0xFF ), bit32.band( rgb, 0xFF )
|
||||||
end
|
end
|
||||||
|
|
||||||
function rgb8( r, g, b )
|
function rgb8( r, g, b )
|
||||||
if type( r ) ~= "number" then
|
if g == nil and b == nil then
|
||||||
error( "bad argument #1 (expected number, got " .. type( r ) .. ")", 2 )
|
return unpackRGB( r )
|
||||||
elseif type(r) == "number" and g == nil and b == nil then
|
else
|
||||||
return bit32.band( bit32.rshift( r, 16 ), 0xFF ) / 255, bit32.band( bit32.rshift( r, 8 ), 0xFF ) / 255, bit32.band( r, 0xFF ) / 255
|
return packRGB( r, g, b )
|
||||||
elseif type(r) == "number" and type(g) == "number" and type(b) == "number" then
|
|
||||||
return
|
|
||||||
bit32.lshift( bit32.band(r * 255, 0xFF), 16 ) +
|
|
||||||
bit32.lshift( bit32.band(g * 255, 0xFF), 8 ) +
|
|
||||||
bit32.band(b * 255, 0xFF)
|
|
||||||
elseif type( g ) ~= "number" then
|
|
||||||
error( "bad argument #2 (expected number, got " .. type( g ) .. ")", 2 )
|
|
||||||
elseif type( b ) ~= "number" then
|
|
||||||
error( "bad argument #3 (expected number, got " .. type( b ) .. ")", 2 )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,11 +42,16 @@ term.native = function()
|
|||||||
return native
|
return native
|
||||||
end
|
end
|
||||||
|
|
||||||
for k,v in pairs( native ) do
|
-- Some methods shouldn't go through redirects, so we move them to the main
|
||||||
if type( k ) == "string" and type( v ) == "function" then
|
-- term API.
|
||||||
if term[k] == nil then
|
for _, method in ipairs { "nativePaletteColor", "nativePaletteColour"} do
|
||||||
term[k] = wrap( k )
|
term[method] = native[method]
|
||||||
|
native[method] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for k,v in pairs( native ) do
|
||||||
|
if type( k ) == "string" and type( v ) == "function" and term[k] == nil then
|
||||||
|
term[k] = wrap( k )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible )
|
|||||||
|
|
||||||
local tCol
|
local tCol
|
||||||
if type(r) == "number" and g == nil and b == nil then
|
if type(r) == "number" and g == nil and b == nil then
|
||||||
tCol = { colours.rgb8( r ) }
|
tCol = { colours.unpackRGB( r ) }
|
||||||
tPalette[ colour ] = tCol
|
tPalette[ colour ] = tCol
|
||||||
else
|
else
|
||||||
if type( r ) ~= "number" then error( "bad argument #2 (expected number, got " .. type( r ) .. ")", 2 ) end
|
if type( r ) ~= "number" then error( "bad argument #2 (expected number, got " .. type( r ) .. ")", 2 ) end
|
||||||
|
Loading…
Reference in New Issue
Block a user