diff --git a/src/micropolisj/build_tool/MakeTiles.java b/src/micropolisj/build_tool/MakeTiles.java index e856045..c30feb4 100644 --- a/src/micropolisj/build_tool/MakeTiles.java +++ b/src/micropolisj/build_tool/MakeTiles.java @@ -18,7 +18,6 @@ import static micropolisj.XML_Helper.*; public class MakeTiles { static HashMap tileData = new HashMap(); - static HashMap loadedImages = new HashMap(); static final Charset UTF8 = Charset.forName("UTF-8"); static int SKIP_TILES = 0; @@ -431,6 +430,30 @@ public class MakeTiles } } + static class MyLoaderContext implements LoaderContext + { + HashMap loadedImages = new HashMap(); + + //implements LoaderContext + public SourceImage getDefaultImage() + { + throw new UnsupportedOperationException(); + } + + //implements LoaderContext + public SourceImage getImage(String fileName) + throws IOException + { + if (!loadedImages.containsKey(fileName)) { + loadedImages.put(fileName, + loadImageNoCache(fileName)); + } + + return loadedImages.get(fileName); + } + } + static MyLoaderContext loaderContext = new MyLoaderContext(); + static TileImage loadImage(String fileName) throws IOException { @@ -439,12 +462,7 @@ public class MakeTiles return loadImageXml(xmlFile); } - if (!loadedImages.containsKey(fileName)) { - loadedImages.put(fileName, - loadImageNoCache(fileName)); - } - - return loadedImages.get(fileName); + return loaderContext.getImage(fileName); } static SourceImage loadImageReal(File pngFile, int basisSize) diff --git a/src/micropolisj/graphics/TileImage.java b/src/micropolisj/graphics/TileImage.java index 0bff983..40e5b3e 100644 --- a/src/micropolisj/graphics/TileImage.java +++ b/src/micropolisj/graphics/TileImage.java @@ -2,6 +2,7 @@ package micropolisj.graphics; import java.awt.*; import java.awt.image.BufferedImage; +import java.io.IOException; import java.util.*; import javax.xml.stream.*; @@ -125,20 +126,27 @@ public abstract class TileImage public interface LoaderContext { - SourceImage getDefaultImage(); - SourceImage getImage(String name); + SourceImage getDefaultImage() + throws IOException; + SourceImage getImage(String name) + throws IOException; } static SimpleTileImage readSimpleImage(XMLStreamReader in, LoaderContext ctx) throws XMLStreamException { SimpleTileImage img = new SimpleTileImage(); - String srcImageName = in.getAttributeValue(null, "src"); - if (srcImageName != null) { - img.srcImage = ctx.getImage(srcImageName); + try { + String srcImageName = in.getAttributeValue(null, "src"); + if (srcImageName != null) { + img.srcImage = ctx.getImage(srcImageName); + } + else { + img.srcImage = ctx.getDefaultImage(); + } } - else { - img.srcImage = ctx.getDefaultImage(); + catch (IOException e) { + throw new XMLStreamException("image source not found", e); } String tmp = in.getAttributeValue(null, "offsetY"); img.offsetY = tmp != null ? Integer.parseInt(tmp) : 0;