Keep class references of config package within config so it can be used at the ASM level

Add simple extensible config serialisation
This commit is contained in:
Chicken-Bomes committed 2014-08-05 18:00:41 +10:00
1 parent 76a6c9e7d5
commit 3b081ed3cd
3 files changed
+244 -320

No files matched your search

+30
View File
@@ -1,13 +1,43 @@
package codechicken.lib.colour;
import codechicken.lib.config.ConfigTag.IConfigType;
import codechicken.lib.math.MathHelper;
import codechicken.lib.util.Copyable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class Colour implements Copyable<Colour>
{
public static IConfigType<Colour> configRGB = new IConfigType<Colour>()
{
@Override
public String configValue(Colour entry) {
String s = Long.toString(((long) entry.rgb()) << 32 >>> 32, 16);
while (s.length() < 6)
s = "0" + s;
return "0x" + s.toUpperCase();
}
private final Pattern patternRGB = Pattern.compile("(\\d+),(\\d+),(\\d+)");
@Override
public Colour valueOf(String text) throws Exception {
Matcher matcherRGB = patternRGB.matcher(text.replaceAll("\\s", ""));
if(matcherRGB.matches())
return new ColourRGBA(
Integer.parseInt(matcherRGB.group(1)),
Integer.parseInt(matcherRGB.group(2)),
Integer.parseInt(matcherRGB.group(3)),
0xFF);
int hex = (int) Long.parseLong(text.replace("0x", ""), 16);
return new ColourRGBA(hex<<8|0xFF);
}
};
public byte r;
public byte g;
public byte b;