ok, so, I can’t seem to find a solid answer on how to do this and it’s driving me crazy. My game uses integers for item colors parsed out of a .properties file initially on launching a new game or generating new items, since all my equipment is drawn in gray scale and colored in game. Problem is, the color is applied with a packed integer, and I can’t seem to figure out how to convert the string in my .properties files from my external data into something the engine can use.
Example of one of my generic item files: tshirt.properties
type=shirt
name=shirt_tshirt
nameProper=T-Shirt
color=0xFFFF0000 <–a “red” shirt, basically. RGBA: 255,0,0,255
value=10
weight=5
Well, I need to convert those values, including the x, into an Integer to pass to my Color class, but I can’t seem to find a way to. Integer.parseInt throws back an error because it doesnt know how to handle the 0x part, I also tried a few various ways of Byte.parseByte and none of those work either.
I could easily just take the RGB values as 3 different properties then combine them all into a packed Integer, but then I’d have to have 3 property lines in all my files/saves/etc for every single item everywhere just to store the colors, and have to do 3 ugly Integer.parseInts to pull them out. Just bad news all around. Be nice if I can keep the ugly Integer parsing down to only pulling 1 value.
Here’s an example of the actual code, specifically for reading the player’s skin color when it loads the game.
Fired when the game loads, to color the character’s skin:
public static int getSkinColor(){return getPropertyAsInt("skinColor", "0xFFFFFFFF");}
…that fires:
public static int getPropertyAsInt(String p, String n){
try {
playerProperties.getProperty(p).toString();
} catch (NullPointerException npe) {
playerProperties.setProperty(p, n);
}
return Integer.parseInt(playerProperties.getProperty(p));
}
Basically, it takes the value p and looks for it in the properties file, if it’s not found it assigns it to n. (Basically n is the default value). But the error is thrown at return Integer.parseInt(playerProperties.getProperty§); because it can’t figure out what to do with the 0x part of the packed int.
Any suggestions that will allow me to keep my packed int in my property files? :o