Animation: implement necessary bits for normalForm()

This allows a layered image to specify an animation as one of its
layers, and for it to still be recognized as an animation after
being processed by MakeTiles.
This commit is contained in:
Jason Long 2015-01-18 09:28:39 -08:00
parent d9761ec54f
commit bf0c33fbe9
2 changed files with 33 additions and 2 deletions

View file

@ -182,6 +182,8 @@ public class MakeTiles
continue;
}
ref = ref.normalForm();
TileImage dest = prepareFrames(ref, c);
TileMapping m = new TileMapping(tileName, ref, dest);
mappings.add(m);

View file

@ -7,7 +7,7 @@ import java.util.*;
import javax.xml.stream.*;
import static micropolisj.XML_Helper.*;
public class Animation extends TileImage
public class Animation extends TileImage implements TileImage.MultiPart
{
static final int DEFAULT_DURATION = 125;
@ -52,6 +52,30 @@ public class Animation extends TileImage
return a;
}
//implements MultiPart
public MultiPart makeEmptyCopy()
{
return new Animation();
}
//implements MultiPart
public Iterable<? extends Part> parts()
{
return frames;
}
//implements MultiPart
public void addPartLike(TileImage image, Part refPart)
{
addFrame(image, ((Frame)refPart).duration);
}
//implements MultiPart
public TileImage asTileImage()
{
return this;
}
public void addFrame(TileImage img, int duration)
{
totalDuration += duration;
@ -98,7 +122,7 @@ public class Animation extends TileImage
}
}
public class Frame
public class Frame implements Part
{
public final TileImage frame;
public final int duration;
@ -108,6 +132,11 @@ public class Animation extends TileImage
this.frame = frame;
this.duration = duration;
}
//implements TileImage.Part
public TileImage getImage() {
return frame;
}
}
private TileImage getDefaultImage()