MakeTiles: when generating intermediate images, use a staging directory

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@748 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-07-20 21:29:28 +00:00
parent e3dcff2804
commit f5b0089abc
3 changed files with 15 additions and 6 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
build build
*.jar *.jar
docs/api docs/api
graphics/generated

View file

@ -91,6 +91,7 @@
<target name="clean"> <target name="clean">
<delete dir="${builddir}" /> <delete dir="${builddir}" />
<delete dir="graphics/generated" />
<delete file="${distfile}" /> <delete file="${distfile}" />
<delete> <delete>
<fileset dir="." includes="${ant.project.name}*.zip" /> <fileset dir="." includes="${ant.project.name}*.zip" />

View file

@ -158,14 +158,16 @@ public class MakeTiles
throw new Error("INKSCAPE not installed (or not found)"); throw new Error("INKSCAPE not installed (or not found)");
} }
static void renderSvg(File svgFile, File pngFile) static File stagingDir = new File("generated");
static File renderSvg(String fileName, File svgFile)
throws IOException throws IOException
{ {
File pngFile = new File(stagingDir, fileName+"_"+TILE_SIZE+"x"+TILE_SIZE+".png");
if (pngFile.exists() && if (pngFile.exists() &&
pngFile.lastModified() > svgFile.lastModified()) pngFile.lastModified() > svgFile.lastModified())
{ {
// looks like the PNG file is already up-to-date // looks like the PNG file is already up-to-date
return; return pngFile;
} }
File inkscapeBin = findInkscape(); File inkscapeBin = findInkscape();
@ -174,6 +176,9 @@ public class MakeTiles
if (pngFile.exists()) { if (pngFile.exists()) {
pngFile.delete(); pngFile.delete();
} }
else if (!stagingDir.exists()) {
stagingDir.mkdir();
}
String [] cmdline = { String [] cmdline = {
inkscapeBin.toString(), inkscapeBin.toString(),
@ -198,26 +203,28 @@ public class MakeTiles
if (!pngFile.exists()) { if (!pngFile.exists()) {
throw new RuntimeException("File not found: "+pngFile); throw new RuntimeException("File not found: "+pngFile);
} }
return pngFile;
} }
static SourceImage loadImage(String fileName) static SourceImage loadImage(String fileName)
throws IOException throws IOException
{ {
File svgFile, pngFile; File svgFile, pngFile = null;
svgFile = new File(fileName+"_"+TILE_SIZE+"x"+TILE_SIZE+".svg"); svgFile = new File(fileName+"_"+TILE_SIZE+"x"+TILE_SIZE+".svg");
pngFile = new File(fileName+"_"+TILE_SIZE+"x"+TILE_SIZE+".png");
if (svgFile.exists()) { if (svgFile.exists()) {
renderSvg(svgFile, pngFile); pngFile = renderSvg(fileName, svgFile);
} }
else { else {
svgFile = new File(fileName+".svg"); svgFile = new File(fileName+".svg");
if (svgFile.exists()) { if (svgFile.exists()) {
renderSvg(svgFile, pngFile); pngFile = renderSvg(fileName, svgFile);
} }
} }
pngFile = new File(fileName+"_"+TILE_SIZE+"x"+TILE_SIZE+".png");
if (pngFile.exists()) { if (pngFile.exists()) {
ImageIcon ii = new ImageIcon(pngFile.toString()); ImageIcon ii = new ImageIcon(pngFile.toString());
return new SourceImage( return new SourceImage(