TileImages: refactor: move AnimatedTile to graphics package
This commit is contained in:
parent
0c29bbfcf8
commit
d64126f05e
2 changed files with 36 additions and 33 deletions
|
@ -2,6 +2,7 @@ package micropolisj.graphics;
|
|||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.*;
|
||||
import javax.xml.stream.*;
|
||||
|
||||
import static micropolisj.XML_Helper.*;
|
||||
|
@ -125,4 +126,39 @@ public abstract class TileImage
|
|||
skipToEndElement(in);
|
||||
return img;
|
||||
}
|
||||
|
||||
public static class AnimatedTile extends TileImage
|
||||
{
|
||||
public SimpleTileImage [] frames;
|
||||
|
||||
public SimpleTileImage getFrameByTime(int acycle)
|
||||
{
|
||||
return frames[acycle % frames.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFragment(Graphics2D gr, int destX, int destY, int srcX, int srcY) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public static AnimatedTile readAnimation(XMLStreamReader in, LoaderContext ctx)
|
||||
throws XMLStreamException
|
||||
{
|
||||
assert in.getLocalName().equals("animation");
|
||||
|
||||
ArrayList<SimpleTileImage> frames = new ArrayList<SimpleTileImage>();
|
||||
|
||||
while (in.nextTag() != XMLStreamConstants.END_ELEMENT) {
|
||||
String tagName = in.getLocalName();
|
||||
if (tagName.equals("frame")) {
|
||||
frames.add(readSimpleImage(in, ctx));
|
||||
}
|
||||
skipToEndElement(in);
|
||||
}
|
||||
|
||||
AnimatedTile anim = new AnimatedTile();
|
||||
anim.frames = frames.toArray(new SimpleTileImage[0]);
|
||||
return anim;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,21 +31,6 @@ public class TileImages
|
|||
TileImage [] tileImageMap;
|
||||
Map<SpriteKind, Map<Integer, Image> > spriteImages;
|
||||
|
||||
static class AnimatedTile extends TileImage
|
||||
{
|
||||
SimpleTileImage [] frames;
|
||||
|
||||
public SimpleTileImage getFrameByTime(int acycle)
|
||||
{
|
||||
return frames[acycle % frames.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFragment(Graphics2D gr, int destX, int destY, int srcX, int srcY) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private TileImages(String name, int size)
|
||||
{
|
||||
this.name = name;
|
||||
|
@ -60,24 +45,6 @@ public class TileImages
|
|||
return "/" + name + "/tiles.png";
|
||||
}
|
||||
|
||||
static AnimatedTile readAnimation(XMLStreamReader in, LoaderContext ctx)
|
||||
throws XMLStreamException
|
||||
{
|
||||
ArrayList<SimpleTileImage> frames = new ArrayList<SimpleTileImage>();
|
||||
|
||||
while (in.nextTag() != XMLStreamConstants.END_ELEMENT) {
|
||||
String tagName = in.getLocalName();
|
||||
if (tagName.equals("frame")) {
|
||||
frames.add(readSimpleImage(in, ctx));
|
||||
}
|
||||
skipToEndElement(in);
|
||||
}
|
||||
|
||||
AnimatedTile anim = new AnimatedTile();
|
||||
anim.frames = frames.toArray(new SimpleTileImage[0]);
|
||||
return anim;
|
||||
}
|
||||
|
||||
static TileImage readTileImage(XMLStreamReader in, LoaderContext ctx)
|
||||
throws XMLStreamException
|
||||
{
|
||||
|
|
Reference in a new issue