From bf0c33fbe9e621ae3c851250407769290bebb7f4 Mon Sep 17 00:00:00 2001 From: Jason Long Date: Sun, 18 Jan 2015 09:28:39 -0800 Subject: [PATCH] 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. --- src/micropolisj/build_tool/MakeTiles.java | 2 ++ src/micropolisj/graphics/Animation.java | 33 +++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/micropolisj/build_tool/MakeTiles.java b/src/micropolisj/build_tool/MakeTiles.java index e50cb7c..d4bde8a 100644 --- a/src/micropolisj/build_tool/MakeTiles.java +++ b/src/micropolisj/build_tool/MakeTiles.java @@ -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); diff --git a/src/micropolisj/graphics/Animation.java b/src/micropolisj/graphics/Animation.java index 503478e..b47ea9d 100644 --- a/src/micropolisj/graphics/Animation.java +++ b/src/micropolisj/graphics/Animation.java @@ -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 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()