package actor;
import java.io.*;
import java.util.Properties;
public abstract class AnimationFactory
{
public static final KeyFrameAnimation IDLE;
public static final KeyFrameAnimation SCAMPER;
public static final KeyFrameAnimation SWAGGER;
public static final KeyFrameAnimation BROADJUMP;
public static final KeyFrameAnimation PROWL;
public static final KeyFrameAnimation LUMBER;
public static final KeyFrameAnimation DEJECTED;
public static final KeyFrameAnimation NO;
public static final KeyFrameAnimation YES;
public static final KeyFrameAnimation HOTFEET;
public static final KeyFrameAnimation SPRINT;
public static final KeyFrameAnimation HOP;
public static final KeyFrameAnimation SCAMPER_BACKWARDS;
public static void main(String[] args)
{
System.out.println(getAnimationByFile("scamper.properties"));
}
public static KeyFrameAnimation getAnimationByName(String a)
{
for(int i = 0; i < name.length; i++)
if(a.equalsIgnoreCase(name[i]+""))
return getAnimationByIndex(i);
throw new RuntimeException("Unable to match animation name: "+a);
}
public static KeyFrameAnimation getAnimationByFile(String fileName)
{
return new KeyFrameAnimation(loadProperties(fileName));
}
private static KeyFrame[] getFramesByIdx(int idx)
{
KeyFrame[] frames = new KeyFrame[4];
for (int i = 0; i < 4; i++)
{
Point3D[] pts = new Point3D[6];
for (int j = 0; j < 6; j++)
pts[j] =
new Point3D(
actions[idx][(18 * i) + (3 * j)],
actions[idx][(18 * i) + (3 * j) + 1],
actions[idx][(18 * i) + (3 * j) + 2]);
frames[i] = new KeyFrame((i * .25), pts);
}
return frames;
}
public static KeyFrameAnimation getAnimationByIndex(int idx)
{
KeyFrame[] frames = new KeyFrame[4];
for (int i = 0; i < 4; i++)
{
Point3D[] pts = new Point3D[6];
for (int j = 0; j < 6; j++)
pts[j] =
new Point3D(
actions[idx][(18 * i) + (3 * j)],
actions[idx][(18 * i) + (3 * j) + 1],
actions[idx][(18 * i) + (3 * j) + 2]);
frames[i] = new KeyFrame((i*.25), pts);
}
return new KeyFrameAnimation(name[idx], frames, rate[idx], travel[idx]);
}
public static int getStockAnimationCount()
{
return name.length;
}
public static void storeProperties(KeyFrameAnimation kf)
{
storeProperties(kf, kf.getName()+".properties");
}
public static void storeProperties(KeyFrameAnimation kf, String fName)
{
try
{
BufferedOutputStream bos = new BufferedOutputStream
(new FileOutputStream(fName));
kf.getProperties().store(bos, null);
bos.flush();
bos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
static Properties loadProperties(String fileName)
{
Properties props = null;
try
{
props = new Properties();
props.load(new BufferedInputStream
(new FileInputStream(new File(fileName))));
return props;
}
catch(FileNotFoundException e)
{
if (props == null)
System.err.println("Unable to load '"+ fileName+"'");
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
static String name[] =
{
"idle",
"scamper",
"swagger",
"broadjump",
"prowl",
"lumber",
"dejected",
"no",
"yes",
"hotfeet",
"sprint",
"hop",
"scamper_backwards"
};
static double rate[] = {4, 8, 6, 7, 2, 2, 2, 10, 12, 10, 9, 10, 4};
static double travel[] = {0, .5, .5, .45, .45, .5, .3, 0, 0, 0, .7, 0, -.5};
static double actions[][] = {
{
0.01, 0.00, 0.00, 0.00, 0.00, 0.00, 0.02, 0.00, 0.01, 0.02, 0.00, 0.03, 0.00, 0.00, 0.00, 0.01, 0.00, 0.03,
0.03, 0.00, 0.02, 0.00, 0.00, 0.00, 0.00, 0.03, 0.03, 0.01, 0.00, 0.02, 0.00, 0.00, 0.00, 0.00, 0.03, 0.00,
0.01, 0.00, 0.01, 0.00, 0.00, 0.00, 0.01, 0.00, 0.00, 0.03, 0.00, 0.00, 0.00, 0.00, 0.00, 0.03, 0.00, 0.01,
0.02, 0.00, 0.01, 0.00, 0.00, 0.00, 0.00,-0.03, 0.02, 0.00, 0.00, 0.01, 0.00, 0.00, 0.00, 0.02,-0.03, 0.02,
},
{
0.00, 0.03, 0.00, 0.10, 0.00, 0.50, 0.00, 0.03, 0.00, 0.00, 0.17, 0.00, -0.10, 0.00,-0.50, 0.00, 0.17, 0.00,
0.00, 0.17, 0.00, 0.00, 0.20, 0.00, 0.00, 0.17, 0.00, 0.00, 0.03, 0.00, -0.10, 0.00, 0.00, 0.00, 0.03, 0.00,
0.00, 0.17, 0.00, 0.10, 0.00,-0.50, 0.00, 0.17, 0.00, 0.00, 0.03, 0.00, -0.10, 0.00, 0.50, 0.00, 0.03, 0.00,
0.00, 0.03, 0.00, 0.10, 0.00, 0.00, 0.00, 0.03, 0.00, 0.00, 0.17, 0.00, 0.00, 0.20, 0.00, 0.00, 0.17, 0.00,
},
{
0.00, 0.00, 0.00, 0.10, 0.00, 0.50, 0.00, 0.00, 0.00, 0.00, 0.00,-0.10, -0.10, 0.00,-0.50, 0.00,-0.10, 0.00,
0.20, 0.50, 0.00, 0.00, 0.50,-0.20, 0.20, 0.50, 0.00, 0.20, 0.00, 0.00, -0.10, 0.00,-0.20, 0.20, 0.00, 0.00,
0.00, 0.00,-0.10, 0.10, 0.00,-0.50, 0.00, 0.00,-0.10, 0.00, 0.00, 0.00, -0.10, 0.00, 0.50, 0.00, 0.00, 0.00,
-0.20, 0.00, 0.00, 0.10, 0.00,-0.20, -0.20, 0.00, 0.00, -0.20, 0.50, 0.00, 0.00, 0.50,-0.20, -0.20, 0.50, 0.00,
},
{
0.00,-0.60, 0.10, 0.00, 0.00, 0.40, 0.00,-0.30, 0.00, 0.00,-0.60, 0.10, 0.00, 0.00, 0.40, 0.00,-0.30, 0.00,
0.00, 0.90, 0.00, 0.10, 0.70, 0.00, 0.00, 0.80, 0.00, 0.00, 0.90, 0.00, -0.10, 0.70, 0.00, 0.00, 0.80, 0.00,
0.00, 0.90, 0.00, 0.10, 0.50,-0.50, 0.00, 0.60, 0.00, 0.00, 0.90, 0.00, -0.10, 0.50,-0.50, 0.00, 0.60, 0.00,
0.00, 0.00, 0.00, 0.00, 0.00,-0.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,-0.20, 0.00, 0.00, 0.00,
},
{
0.00,-0.40,-0.10, 0.20, 0.00, 0.40, 0.00, 0.00, 0.00, 0.00,-0.20,-0.10, -0.20, 0.00,-0.50, 0.00, 0.00,-0.20,
0.10, 0.00, 0.00, 0.00, 0.30,-0.40, 0.10,-0.20, 0.00, 0.10, 0.00, 0.00, -0.20, 0.00,-0.05, 0.10,-0.20, 0.00,
0.00,-0.20,-0.10, 0.20, 0.00,-0.50, 0.00, 0.00,-0.20, 0.00,-0.40,-0.10, -0.20, 0.00, 0.40, 0.00, 0.00, 0.00,
-0.10, 0.00, 0.00, 0.20, 0.00,-0.05, -0.10,-0.20, 0.00, -0.10, 0.00, 0.00, 0.00, 0.30,-0.40, -0.10,-0.20, 0.00,
},
{
0.00, 0.00, 0.00, 0.10, 0.00, 0.50, 0.00, 0.00, 0.00, 0.00, 0.00,-0.10, -0.10, 0.00,-0.50, 0.00,-0.10, 0.00,
0.00, 0.20, 0.00, 0.00, 0.10, 0.00, 0.00, 0.20, 0.00, 0.00, 0.00, 0.00, -0.10, 0.00, 0.00, 0.00, 0.00, 0.00,
0.00, 0.00,-0.10, 0.10, 0.00,-0.50, 0.00, 0.00,-0.10, 0.00, 0.00, 0.00, -0.10, 0.00, 0.50, 0.00, 0.00, 0.00,
0.00, 0.00, 0.00, 0.10, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.20, 0.00, 0.00, 0.10, 0.00, 0.00, 0.20, 0.00,
},
{
0.00,-0.50, 0.00, 0.10, 0.00, 0.30, 0.00, 0.00, 0.00, 0.00,-0.30,-0.10, -0.10, 0.00,-0.30, 0.00,-0.05, 0.00,
0.00,-0.20, 0.00, 0.00, 0.10, 0.00, 0.00, 0.05, 0.00, 0.00,-0.30, 0.00, -0.10, 0.00, 0.00, 0.00, 0.00, 0.00,
0.00,-0.30,-0.10, 0.10, 0.00,-0.30, 0.00, 0.00,-0.10, 0.00,-0.50, 0.00, -0.10, 0.00, 0.30, 0.00, 0.00, 0.00,
0.00,-0.30, 0.00, 0.10, 0.00, 0.00, 0.00,-0.05, 0.00, 0.00,-0.20, 0.00, 0.00, 0.10, 0.00, 0.00, 0.05, 0.00,
},
{
0.10,-0.10,-0.10, 0.00, 0.00, 0.00, -0.10, 0.10,-0.10, 0.10,-0.10, 0.10, 0.00, 0.00, 0.00, -0.10, 0.10, 0.10,
0.10,-0.10,-0.10, 0.00, 0.00, 0.00, -0.10, 0.10,-0.10, 0.10,-0.10, 0.10, 0.00, 0.00, 0.00, -0.10, 0.10, 0.10,
-0.10,-0.10, 0.10, 0.00, 0.00, 0.00, 0.10, 0.10, 0.10, -0.10,-0.10,-0.10, 0.00, 0.00, 0.00, 0.10, 0.10,-0.10,
-0.10,-0.10, 0.10, 0.00, 0.00, 0.00, 0.10, 0.10, 0.10, -0.10,-0.10,-0.10, 0.00, 0.00, 0.00, 0.10, 0.10,-0.10,
},
{
0.00,-0.10,-0.10, 0.00, 0.00, 0.00, 0.00, 0.05, 0.00, 0.00,-0.10,-0.10, 0.00, 0.00, 0.00, 0.00, 0.05, 0.00,
0.00, 0.15,-0.10, 0.00, 0.00, 0.00, 0.00,-0.07, 0.00, 0.00, 0.15,-0.10, 0.00, 0.00, 0.00, 0.00,-0.07, 0.00,
0.00, 0.15,-0.10, 0.00, 0.00, 0.00, 0.00,-0.07, 0.00, 0.00, 0.15,-0.10, 0.00, 0.00, 0.00, 0.00,-0.07, 0.00,
0.00,-0.10,-0.10, 0.00, 0.00, 0.00, 0.00, 0.05, 0.00, 0.00,-0.10,-0.10, 0.00, 0.00, 0.00, 0.00, 0.05, 0.00,
},
{
0.00, 0.20, 0.10, 0.00, 0.30, 0.00, 0.00, 0.20, 0.00, 0.00, 0.20, 0.00, 0.00, 0.30, 0.00, 0.00, 0.20, 0.00,
0.00, 0.30, 0.00, 0.20, 0.50, 0.00, 0.00, 0.30, 0.00, 0.00, 0.10, 0.00, 0.00,-0.10, 0.00, 0.00, 0.10, 0.00,
0.00, 0.20, 0.00, 0.00, 0.30, 0.00, 0.00, 0.20, 0.00, 0.00, 0.20, 0.10, 0.00, 0.30, 0.00, 0.00, 0.20, 0.00,
0.00, 0.10, 0.00, 0.00,-0.10, 0.00, 0.00, 0.10, 0.00, 0.00, 0.30, 0.00, -0.20, 0.50, 0.00, 0.00, 0.30, 0.00,
},
{
0.00, 0.10, 0.10, 0.20, 0.30, 0.50, 0.00, 0.20, 0.00, 0.00, 0.10, 0.00, -0.20, 0.30,-0.30, 0.00, 0.20, 0.00,
0.00, 0.00, 0.00, -0.10, 0.50, 0.10, 0.00, 0.10, 0.00, 0.00, 0.20, 0.00, -0.20,-0.10, 0.10, 0.00, 0.30, 0.00,
0.00, 0.10, 0.00, 0.20, 0.30,-0.30, 0.00, 0.20, 0.00, 0.00, 0.10, 0.10, -0.20, 0.30, 0.50, 0.00, 0.20, 0.00,
0.00, 0.20, 0.00, 0.20,-0.10, 0.10, 0.00, 0.30, 0.00, 0.00, 0.00, 0.00, 0.10, 0.50, 0.10, 0.00, 0.10, 0.00,
},
{
0.70, 0.30, 0.00, 0.20, 0.40, 0.00, 0.70, 0.30, 0.00, 0.40, 0.00, 0.00, 0.00, 0.00, 0.00, 0.40, 0.00, 0.00,
0.70, 0.40, 0.00, 0.20, 0.50, 0.00, 0.70, 0.40, 0.00, 0.50,-0.10, 0.00, 0.00, 0.00, 0.00, 0.50, 0.00,-0.10,
0.70, 0.50, 0.00, 0.20, 0.60, 0.00, 0.70, 0.50, 0.00, 0.60,-0.20, 0.00, 0.00, 0.20, 0.00, 0.60, 0.00,-0.20,
0.70, 0.40, 0.00, 0.20, 0.50, 0.00, 0.70, 0.40, 0.00, 0.50,-0.10, 0.00, 0.00, 0.00, 0.00, 0.50, 0.00,-0.10,
},
{
0.00, 0.03, 0.00, 0.10, 0.00, 0.50, 0.00, 0.03, 0.00, 0.00, 0.17, 0.00, -0.10, 0.00,-0.50, 0.00, 0.17, 0.00,
0.00, 0.03, 0.00, 0.10, 0.00, 0.00, 0.00, 0.03, 0.00, 0.00, 0.17, 0.00, 0.00, 0.20, 0.00, 0.00, 0.17, 0.00,
0.00, 0.17, 0.00, 0.10, 0.00,-0.50, 0.00, 0.17, 0.00, 0.00, 0.03, 0.00, -0.10, 0.00, 0.50, 0.00, 0.03, 0.00,
0.00, 0.17, 0.00, 0.00, 0.20, 0.00, 0.00, 0.17, 0.00, 0.00, 0.03, 0.00, -0.10, 0.00, 0.00, 0.00, 0.03, 0.00,
},
};
static {
IDLE = getAnimationByIndex(0);
SCAMPER = getAnimationByIndex(1);
SWAGGER = getAnimationByIndex(2);
BROADJUMP = getAnimationByIndex(3);
PROWL = getAnimationByIndex(4);
LUMBER = getAnimationByIndex(5);
DEJECTED = getAnimationByIndex(6);
NO = getAnimationByIndex(7);
YES = getAnimationByIndex(8);
HOTFEET = getAnimationByIndex(9);
SPRINT = getAnimationByIndex(10);
HOP = getAnimationByIndex(11);
SCAMPER_BACKWARDS = getAnimationByIndex(12);
}
}