mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
Various improvements; options, version, info
Adds options to PNG importing so that any valid DMI file can be entirely built from PNG files and DMITool. Adds version string and "version" command Adds info command to get a list of states easily (the only way previously was to print the descriptor with "dmitool -vvvv verify $file" and parse with e.g. grep/sed)
This commit is contained in:
Binary file not shown.
@@ -420,6 +420,12 @@ public class DMI implements Comparator<IconState> {
|
||||
System.out.println(totalImages + " images, " + images.size() + " states, size "+w+"x"+h);
|
||||
}
|
||||
|
||||
public void printStateList() {
|
||||
for(IconState s: images) {
|
||||
System.out.println(s.getInfoLine());
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object obj) {
|
||||
if(obj == this) return true;
|
||||
if(!(obj instanceof DMI)) return false;
|
||||
|
||||
@@ -20,6 +20,21 @@ public class IconState {
|
||||
String hotspot;
|
||||
boolean movement;
|
||||
|
||||
public String getInfoLine() {
|
||||
String extraInfo = "";
|
||||
if(rewind) extraInfo += " rewind";
|
||||
if(frames != 1) {
|
||||
extraInfo += " loop(" + (loop==-1 ? "infinite" : loop) + ")";
|
||||
}
|
||||
if(hotspot != null) extraInfo += " hotspot('" + hotspot + "')";
|
||||
if(movement) extraInfo += " movement";
|
||||
if(extraInfo.equals("")) {
|
||||
return String.format("state \"%s\", %d dir(s), %d frame(s)", name, dirs, frames);
|
||||
} else {
|
||||
return String.format("state \"%s\", %d dir(s), %d frame(s),%s", name, dirs, frames, extraInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public IconState clone() {
|
||||
IconState is = new IconState(name, dirs, frames, images.clone(), delays==null ? null : delays.clone(), rewind, loop, hotspot, movement);
|
||||
is.delays = delays != null ? delays.clone() : null;
|
||||
@@ -148,7 +163,7 @@ public class IconState {
|
||||
out.end();
|
||||
}
|
||||
|
||||
public static IconState importFromPNG(DMI dmi, InputStream inS, String name) throws DMIException {
|
||||
public static IconState importFromPNG(DMI dmi, InputStream inS, String name, float[] delays, boolean rewind, int loop, String hotspot, boolean movement) throws DMIException {
|
||||
int w = dmi.w;
|
||||
int h = dmi.h;
|
||||
|
||||
@@ -192,15 +207,8 @@ public class IconState {
|
||||
}
|
||||
}
|
||||
|
||||
float[] delays = null;
|
||||
if(frames != 1) {
|
||||
delays = new float[frames];
|
||||
for(int i=0; i<delays.length; i++) {
|
||||
delays[i] = 1;
|
||||
}
|
||||
}
|
||||
//public IconState(String name, int dirs, int frames, Image[] images, float[] delays, boolean rewind, int loop, String hotspot, boolean movement) {
|
||||
return new IconState(name, dirs, frames, images, delays, false, -1, null, false);
|
||||
return new IconState(name, dirs, frames, images, delays, rewind, loop, hotspot, movement);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Set;
|
||||
public class Main {
|
||||
public static int VERBOSITY = 0;
|
||||
public static boolean STRICT = false;
|
||||
public static final String VERSION = "v0.6 (7 Jan 2015)";
|
||||
|
||||
public static final String[] dirs = new String[] {
|
||||
"S", "N", "E", "W", "SE", "SW", "NE", "NW"
|
||||
@@ -20,9 +21,15 @@ public class Main {
|
||||
"help\n" +
|
||||
"\tthis text\n" +
|
||||
|
||||
"version\n" +
|
||||
"\tprint version and exit\n" +
|
||||
|
||||
"verify [file]\n" +
|
||||
"\tattempt to load the given file to check format\n" +
|
||||
|
||||
"info [file]\n" +
|
||||
"\tprint information about [file], including a list of states\n" +
|
||||
|
||||
"diff [file1] [file2]\n" +
|
||||
"\tdiff between [file1] and [file2]\n" +
|
||||
|
||||
@@ -40,9 +47,18 @@ public class Main {
|
||||
"\tdirection specifier can be a single direction, or direction-direction\n" +
|
||||
"\tdirection can be 0-7 or S, N, E, W, SE, SW, NE, NW (non-case-sensitive)\n" +
|
||||
|
||||
"import [file] [state] [in]\n" +
|
||||
"import [file] [state] [in] [options]\n" +
|
||||
"\timport a PNG image from [in] into [file], with the name [state]\n" +
|
||||
"\tinput should be in the same format given by the 'extract' command with no direction or frame arguments\n" +
|
||||
"\t(i.e. frames should be on the x-axis, and directions on the y)\n" +
|
||||
"\tpossible options:\n" +
|
||||
"\t nodup | nd | n : if the state [state] already exists in [file], replace it instead of append\n" +
|
||||
"\t rewind | rw | r : if there is more than one frame, the animation should be played forwards-backwards-forwards-[...]\n" +
|
||||
"\t loop | lp | l : loop the animation infinitely; equivalent to \"loopn -1\"\n" +
|
||||
"\t loopn N | lpn N | ln N : loop the animation N times; for infinite animations, use 'loop' or N = -1\n" +
|
||||
"\t movement | move | mov | m : [state] should be marked as a movement state\n" +
|
||||
"\t delays L | delay L | del L | d L : use the list L as a comma-separated list of delays (e.g. '1,1,2,2,1')\n" +
|
||||
"\t hotspot H | hs H | h H : use H as the hotspot for this state\n" +
|
||||
"";
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException, IOException, DMIException {
|
||||
@@ -249,22 +265,98 @@ public class Main {
|
||||
pngFile = argq.pollFirst();
|
||||
|
||||
boolean noDup = false;
|
||||
if(!argq.isEmpty()) {
|
||||
switch(argq.pollFirst().toLowerCase()) {
|
||||
boolean rewind = false;
|
||||
int loop = 0;
|
||||
boolean movement = false;
|
||||
String hotspot = null;
|
||||
float[] delays = null;
|
||||
while(!argq.isEmpty()) {
|
||||
String s = argq.pollFirst();
|
||||
switch(s.toLowerCase()) {
|
||||
case "nodup":
|
||||
case "nd":
|
||||
case "n":
|
||||
noDup = true;
|
||||
break;
|
||||
case "rewind":
|
||||
case "rw":
|
||||
case "r":
|
||||
rewind = true;
|
||||
break;
|
||||
case "loop":
|
||||
case "lp":
|
||||
case "l":
|
||||
loop = -1;
|
||||
break;
|
||||
case "loopn":
|
||||
case "lpn":
|
||||
case "ln":
|
||||
if(!argq.isEmpty()) {
|
||||
String loopTimes = argq.pollFirst();
|
||||
try {
|
||||
loop = Integer.parseInt(loopTimes);
|
||||
} catch(NumberFormatException nfe) {
|
||||
System.out.println("Illegal number '" + loopTimes + "' as argument to '" + s + "'!");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
System.out.println("Argument '" + s + "' requires a numeric argument following it!");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "movement":
|
||||
case "move":
|
||||
case "mov":
|
||||
case "m":
|
||||
movement = true;
|
||||
break;
|
||||
case "delays":
|
||||
case "delay":
|
||||
case "del":
|
||||
case "d":
|
||||
if(!argq.isEmpty()) {
|
||||
String delaysString = argq.pollFirst();
|
||||
String[] delaysSplit = delaysString.split(",");
|
||||
delays = new float[delaysSplit.length];
|
||||
for(int i=0; i<delaysSplit.length; i++) {
|
||||
try {
|
||||
delays[i] = Integer.parseInt(delaysSplit[i]);
|
||||
} catch(NumberFormatException nfe) {
|
||||
System.out.println("Illegal number '" + delaysSplit[i] + "' as argument to '" + s + "'!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Argument '" + s + "' requires a list of delays (in the format 'a,b,c,d,[...]') following it!");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "hotspot":
|
||||
case "hs":
|
||||
case "h":
|
||||
if(!argq.isEmpty()) {
|
||||
hotspot = argq.pollFirst();
|
||||
} else {
|
||||
System.out.println("Argument '" + s + "' requires a hotspot string following it!");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unknown import argument '" + s + "', ignoring.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(VERBOSITY >= 0) System.out.println("Loading " + dmiFile);
|
||||
DMI toImportTo = doDMILoad(dmiFile);
|
||||
if(VERBOSITY >= 0) toImportTo.printInfo();
|
||||
//public static IconState importFromPNG(DMI dmi, InputStream inS, String name) throws DMIException {
|
||||
IconState is = IconState.importFromPNG(toImportTo, new FileInputStream(pngFile), stateName);
|
||||
IconState is = IconState.importFromPNG(toImportTo, new FileInputStream(pngFile), stateName, delays, rewind, loop, hotspot, movement);
|
||||
|
||||
|
||||
if(!(noDup && toImportTo.setIconState(is))) {
|
||||
if(noDup) {
|
||||
if(!toImportTo.setIconState(is)) {
|
||||
toImportTo.addIconState(null, is);
|
||||
}
|
||||
} else {
|
||||
toImportTo.addIconState(null, is);
|
||||
}
|
||||
|
||||
@@ -286,6 +378,22 @@ public class Main {
|
||||
if(VERBOSITY >= 0) v.printInfo();
|
||||
break;
|
||||
}
|
||||
case "info": {
|
||||
if(argq.size() < 1) {
|
||||
System.out.println("Insufficient arguments for command!");
|
||||
System.out.println(helpStr);
|
||||
return;
|
||||
}
|
||||
String infoFile = argq.pollFirst();
|
||||
if(VERBOSITY >= 0) System.out.println("Loading " + infoFile);
|
||||
DMI info = doDMILoad(infoFile);
|
||||
info.printInfo();
|
||||
info.printStateList();
|
||||
break;
|
||||
}
|
||||
case "version":
|
||||
System.out.println(VERSION);
|
||||
return;
|
||||
default:
|
||||
System.out.println("Command '" + op + "' not found!");
|
||||
case "help":
|
||||
|
||||
Reference in New Issue
Block a user