refactor: make readTileImage() to read any tile image descriptor type
This commit is contained in:
parent
d95ad15b99
commit
409f338e6b
1 changed files with 30 additions and 12 deletions
|
@ -82,6 +82,8 @@ public class TileImages
|
|||
}
|
||||
String tmp = in.getAttributeValue(null, "offsetY");
|
||||
img.offsetY = tmp != null ? Integer.parseInt(tmp) : 0;
|
||||
|
||||
skipToEndElement(in);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
@ -103,6 +105,33 @@ public class TileImages
|
|||
return anim;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
Map<String,BufferedImage> images = new HashMap<String,BufferedImage>();
|
||||
|
@ -158,18 +187,7 @@ public class TileImages
|
|||
}
|
||||
|
||||
String tileName = in.getAttributeValue(null, "name");
|
||||
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);
|
||||
}
|
||||
skipToEndElement(in);
|
||||
}
|
||||
TileImage img = readTileImage(in, ctx);
|
||||
|
||||
assert tileName != null;
|
||||
assert img != null;
|
||||
|
|
Reference in a new issue