Restructure component bundle building so that character components can

have class names with slashes in them (for better heirarchicalization,
like male/torso).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1111 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-03-08 22:36:43 +00:00
parent 4b100da3bd
commit c3eb78e520
@@ -1,5 +1,5 @@
// //
// $Id: ComponentBundlerTask.java,v 1.4 2002/02/06 19:33:36 shaper Exp $ // $Id: ComponentBundlerTask.java,v 1.5 2002/03/08 22:36:43 mdb Exp $
package com.threerings.cast.bundle.tools; package com.threerings.cast.bundle.tools;
@@ -66,6 +66,16 @@ public class ComponentBundlerTask extends Task
_mapfile = mapfile; _mapfile = mapfile;
} }
/**
* Sets the root path which will be stripped from the image paths
* prior to parsing them to obtain the component class, type and
* action names.
*/
public void setRoot (File root)
{
_root = root.getPath();
}
/** /**
* Adds a nested <fileset> element. * Adds a nested <fileset> element.
*/ */
@@ -147,7 +157,20 @@ public class ComponentBundlerTask extends Task
protected String[] decomposePath (String path) protected String[] decomposePath (String path)
throws BuildException throws BuildException
{ {
// first strip off the file extension // first strip off the root
if (!path.startsWith(_root)) {
throw new BuildException("Can't bundle images outside the " +
"root directory [root=" + _root +
", path=" + path + "].");
}
path = path.substring(_root.length());
// strip off any preceding slash
if (path.startsWith("/")) {
path = path.substring(1);
}
// now strip off the file extension
if (!path.endsWith(BundleUtil.IMAGE_EXTENSION)) { if (!path.endsWith(BundleUtil.IMAGE_EXTENSION)) {
throw new BuildException("Can't bundle malformed image file " + throw new BuildException("Can't bundle malformed image file " +
"[path=" + path + "]."); "[path=" + path + "].");
@@ -155,15 +178,24 @@ public class ComponentBundlerTask extends Task
path = path.substring(0, path.length() - path = path.substring(0, path.length() -
BundleUtil.IMAGE_EXTENSION.length()); BundleUtil.IMAGE_EXTENSION.length());
// now decompose the path // now decompose the path; the component type and action must
String[] components = StringUtil.split(path, File.separator); // always be a single string but the class can span multiple
int clen = components.length; // directories for easier component organization; thus
if (clen < 3) { // "male/head/goatee/standing" will be parsed as [class=male/head,
throw new BuildException("Can't bundle malformed image file " + // type=goatee, action=standing]
"[path=" + path + "]."); String malmsg = "Can't decode malformed image path: '" + path + "'";
}
String[] info = new String[3]; String[] info = new String[3];
System.arraycopy(components, clen-3, info, 0, 3); int lsidx = path.lastIndexOf(File.separator);
if (lsidx == -1) {
throw new BuildException(malmsg);
}
info[2] = path.substring(lsidx+1);
int slsidx = path.lastIndexOf(File.separator, lsidx-1);
if (slsidx == -1) {
throw new BuildException(malmsg);
}
info[1] = path.substring(slsidx+1, lsidx);
info[0] = path.substring(0, slsidx);
return info; return info;
} }
@@ -206,7 +238,7 @@ public class ComponentBundlerTask extends Task
} catch (Exception e) { } catch (Exception e) {
throw new BuildException("Error loading component ID map " + throw new BuildException("Error loading component ID map " +
"[mapfile=" + mapfile + "].", e); "[mapfile=" + mapfile + "]", e);
} }
return broker; return broker;
@@ -226,7 +258,7 @@ public class ComponentBundlerTask extends Task
oout.close(); oout.close();
} catch (IOException ioe) { } catch (IOException ioe) {
throw new BuildException("Unable to store component ID map " + throw new BuildException("Unable to store component ID map " +
"[mapfile=" + mapfile + "].", ioe); "[mapfile=" + mapfile + "]", ioe);
} }
} }
@@ -260,6 +292,9 @@ public class ComponentBundlerTask extends Task
/** The path to our component map file. */ /** The path to our component map file. */
protected File _mapfile; protected File _mapfile;
/** The component directory root. */
protected String _root;
/** A list of filesets that contain tile images. */ /** A list of filesets that contain tile images. */
protected ArrayList _filesets = new ArrayList(); protected ArrayList _filesets = new ArrayList();
} }