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

Network the colour palette

Which means it actually has a visible effect! 🎉
This commit is contained in:
Lignum 2017-05-05 17:21:53 +02:00
parent b0f0d8fd71
commit 088dab799e
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D
4 changed files with 43 additions and 4 deletions

View File

@ -72,9 +72,7 @@ public String[] getMethodNames()
"setColour",
"setColor",
"getColour",
"getColor",
"resetColour",
"resetColor"
"getColor"
};
}
@ -302,6 +300,7 @@ public Object[] callMethod( ILuaContext context, int method, Object[] args ) thr
if( m_terminal.getPalette() != null )
{
m_terminal.getPalette().setColour( colour, r, g, b );
m_terminal.setChanged();
}
}
return null;

View File

@ -307,7 +307,12 @@ public boolean getChanged()
{
return m_changed;
}
public void setChanged()
{
m_changed = true;
}
public void clearChanged()
{
m_changed = false;
@ -326,6 +331,10 @@ public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound )
nbttagcompound.setString( "term_textColour_" + n, m_textColour[n].toString() );
nbttagcompound.setString( "term_textBgColour_" + n, m_backgroundColour[ n ].toString() );
}
if(m_palette != null)
{
m_palette.writeToNBT( nbttagcompound );
}
return nbttagcompound;
}
@ -355,6 +364,10 @@ public void readFromNBT( NBTTagCompound nbttagcompound )
m_backgroundColour[n].write( nbttagcompound.getString( "term_textBgColour_" + n ) );
}
}
if (m_palette != null)
{
m_palette.readFromNBT( nbttagcompound );
}
m_changed = true;
}
}

View File

@ -1,5 +1,7 @@
package dan200.computercraft.shared.util;
import net.minecraft.nbt.NBTTagCompound;
public class Palette
{
private static class PaletteColour
@ -93,4 +95,28 @@ public void resetColours()
resetColour( i );
}
}
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
for(int i = 0; i < colours.length; ++i)
{
PaletteColour c = colours[i];
String prefix = "term_palette_colour_" + i;
nbt.setFloat( prefix + "_r", c.m_r );
nbt.setFloat( prefix + "_g", c.m_g );
nbt.setFloat( prefix + "_b", c.m_b );
}
return nbt;
}
public void readFromNBT( NBTTagCompound nbt )
{
for(int i = 0; i < colours.length; ++i)
{
String prefix = "term_palette_colour_" + i;
colours[i].m_r = nbt.getFloat( prefix + "_r" );
colours[i].m_g = nbt.getFloat( prefix + "_g" );
colours[i].m_b = nbt.getFloat( prefix + "_b" );
}
}
}

View File

@ -383,6 +383,7 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible )
updateCursorBlink()
updateCursorColor()
updateCursorPos()
updatePalette()
end
end