TileImageLayer: require both elements to be non-null
simplifies some algorithms
This commit is contained in:
parent
744e74267a
commit
a99a6f0f1c
3 changed files with 30 additions and 25 deletions
|
@ -49,6 +49,7 @@
|
|||
fork="true" failonerror="true" dir="graphics" inputstring="">
|
||||
<arg file="graphics/tiles.rc" />
|
||||
<arg file="${builddir}/16x16" />
|
||||
<assertions><enable/></assertions>
|
||||
</java>
|
||||
<java classname="micropolisj.build_tool.MakeTiles" classpath="${builddir}"
|
||||
fork="true" failonerror="true" dir="graphics" inputstring="">
|
||||
|
|
|
@ -308,19 +308,19 @@ public class MakeTiles
|
|||
static TileImage parseFrameSpec(String [] layerStrings)
|
||||
throws IOException
|
||||
{
|
||||
if (layerStrings.length == 1) {
|
||||
return parseLayerSpec(layerStrings[0]);
|
||||
}
|
||||
|
||||
TileImageLayer result = null;
|
||||
TileImage result = null;
|
||||
|
||||
for (String layerStr : layerStrings) {
|
||||
|
||||
TileImageLayer rv = new TileImageLayer(
|
||||
result,
|
||||
parseLayerSpec(layerStr)
|
||||
);
|
||||
result = rv;
|
||||
TileImage newLayer = parseLayerSpec(layerStr);
|
||||
if (result == null) {
|
||||
result = newLayer;
|
||||
}
|
||||
else {
|
||||
result = new TileImageLayer(
|
||||
result,
|
||||
newLayer);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -24,11 +24,14 @@ public abstract class TileImage
|
|||
|
||||
public static class TileImageLayer extends TileImage
|
||||
{
|
||||
public final TileImageLayer below;
|
||||
public final TileImage below;
|
||||
public final TileImage above;
|
||||
|
||||
public TileImageLayer(TileImageLayer below, TileImage above)
|
||||
public TileImageLayer(TileImage below, TileImage above)
|
||||
{
|
||||
assert below != null;
|
||||
assert above != null;
|
||||
|
||||
this.below = below;
|
||||
this.above = above;
|
||||
}
|
||||
|
@ -36,9 +39,7 @@ public abstract class TileImage
|
|||
@Override
|
||||
public void drawFragment(Graphics2D gr, int destX, int destY, int srcX, int srcY)
|
||||
{
|
||||
if (below != null) {
|
||||
below.drawFragment(gr, destX, destY, srcX, srcY);
|
||||
}
|
||||
below.drawFragment(gr, destX, destY, srcX, srcY);
|
||||
above.drawFragment(gr, destX, destY, srcX, srcY);
|
||||
}
|
||||
}
|
||||
|
@ -204,25 +205,28 @@ public abstract class TileImage
|
|||
static TileImage readLayeredImage(XMLStreamReader in, LoaderContext ctx)
|
||||
throws XMLStreamException
|
||||
{
|
||||
TileImageLayer result = null;
|
||||
TileImage result = null;
|
||||
|
||||
while (in.nextTag() != XMLStreamConstants.END_ELEMENT) {
|
||||
assert in.isStartElement();
|
||||
|
||||
TileImage newImg = readTileImage(in, ctx);
|
||||
TileImageLayer rv = new TileImageLayer(
|
||||
result, //below
|
||||
newImg //above
|
||||
if (result == null) {
|
||||
result = newImg;
|
||||
}
|
||||
else {
|
||||
result = new TileImageLayer(
|
||||
result, //below
|
||||
newImg //above
|
||||
);
|
||||
result = rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null && result.below == null) {
|
||||
return result.above;
|
||||
}
|
||||
else {
|
||||
return result;
|
||||
if (result == null) {
|
||||
throw new XMLStreamException("layer must have at least one image");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static TileImage readTileImage(XMLStreamReader in, LoaderContext ctx)
|
||||
|
|
Reference in a new issue