TileImages: refactor: move readTileImage() to graphics package

This commit is contained in:
Jason Long 2015-01-10 12:45:51 -05:00
parent d64126f05e
commit 030abc4512
2 changed files with 27 additions and 27 deletions

View file

@ -161,4 +161,31 @@ public abstract class TileImage
anim.frames = frames.toArray(new SimpleTileImage[0]); anim.frames = frames.toArray(new SimpleTileImage[0]);
return anim; return anim;
} }
public static TileImage readTileImage(XMLStreamReader in, LoaderContext ctx)
throws XMLStreamException
{
TileImage img = null;
while (in.nextTag() != XMLStreamConstants.END_ELEMENT) {
assert in.isStartElement();
if (in.getLocalName().equals("image")) {
img = readSimpleImage(in, ctx);
}
else if (in.getLocalName().equals("animation")) {
img = readAnimation(in, ctx);
}
else {
skipToEndElement(in);
}
}
if (img == null) {
throw new XMLStreamException(
"missing image descriptor"
);
}
return img;
}
} }

View file

@ -45,33 +45,6 @@ public class TileImages
return "/" + name + "/tiles.png"; return "/" + name + "/tiles.png";
} }
static TileImage readTileImage(XMLStreamReader in, LoaderContext ctx)
throws XMLStreamException
{
TileImage img = null;
while (in.nextTag() != XMLStreamConstants.END_ELEMENT) {
assert in.isStartElement();
if (in.getLocalName().equals("image")) {
img = readSimpleImage(in, ctx);
}
else if (in.getLocalName().equals("animation")) {
img = readAnimation(in, ctx);
}
else {
skipToEndElement(in);
}
}
if (img == null) {
throw new XMLStreamException(
"missing image descriptor"
);
}
return img;
}
class MyLoaderContext implements LoaderContext class MyLoaderContext implements LoaderContext
{ {
Map<String,BufferedImage> images = new HashMap<String,BufferedImage>(); Map<String,BufferedImage> images = new HashMap<String,BufferedImage>();