TileImage: move Animation class from MakeTools into Graphics package
This commit is contained in:
parent
a99a6f0f1c
commit
6d76b43164
4 changed files with 28 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
|||
package micropolisj.build_tool;
|
||||
|
||||
import micropolisj.engine.TileSpec;
|
||||
import micropolisj.graphics.TileImage;
|
||||
import micropolisj.graphics.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
|
@ -423,7 +423,7 @@ public class MakeTiles
|
|||
{
|
||||
File f = new File(fileName + ".ani");
|
||||
if (f.exists()) {
|
||||
return Animation.load(f);
|
||||
return Animation.load(f, loaderContext);
|
||||
}
|
||||
else {
|
||||
return loadImage(fileName);
|
||||
|
@ -451,6 +451,12 @@ public class MakeTiles
|
|||
|
||||
return loadedImages.get(fileName);
|
||||
}
|
||||
|
||||
public TileImage parseFrameSpec(String tmp)
|
||||
throws IOException
|
||||
{
|
||||
return MakeTiles.parseFrameSpec(tmp);
|
||||
}
|
||||
}
|
||||
static MyLoaderContext loaderContext = new MyLoaderContext();
|
||||
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
package micropolisj.build_tool;
|
||||
package micropolisj.graphics;
|
||||
|
||||
import micropolisj.graphics.TileImage;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.xml.stream.*;
|
||||
import static micropolisj.XML_Helper.*;
|
||||
|
||||
class Animation extends TileImage
|
||||
public class Animation extends TileImage
|
||||
{
|
||||
static final int DEFAULT_DURATION = 125;
|
||||
List<Frame> frames = new ArrayList<Frame>();
|
||||
int totalDuration;
|
||||
|
||||
public static Animation load(File aniFile)
|
||||
public List<Frame> frames = new ArrayList<Frame>();
|
||||
public int totalDuration;
|
||||
|
||||
public static Animation load(File aniFile, LoaderContext ctx)
|
||||
throws IOException
|
||||
{
|
||||
FileInputStream fis = new FileInputStream(aniFile);
|
||||
Animation self = new Animation();
|
||||
self.load(fis);
|
||||
self.load(fis, ctx);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -29,7 +30,7 @@ class Animation extends TileImage
|
|||
frames.add(f);
|
||||
}
|
||||
|
||||
void load(InputStream inStream)
|
||||
void load(InputStream inStream, LoaderContext ctx)
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
|
@ -51,7 +52,7 @@ class Animation extends TileImage
|
|||
int duration = tmp != null ? Integer.parseInt(tmp) : DEFAULT_DURATION;
|
||||
|
||||
tmp = in.getElementText();
|
||||
addFrame( MakeTiles.parseFrameSpec(tmp), duration );
|
||||
addFrame( ctx.parseFrameSpec(tmp), duration );
|
||||
}
|
||||
else {
|
||||
// unrecognized element
|
||||
|
@ -68,10 +69,10 @@ class Animation extends TileImage
|
|||
}
|
||||
}
|
||||
|
||||
static class Frame
|
||||
public class Frame
|
||||
{
|
||||
TileImage frame;
|
||||
int duration;
|
||||
public final TileImage frame;
|
||||
public final int duration;
|
||||
|
||||
public Frame(TileImage frame, int duration)
|
||||
{
|
|
@ -132,6 +132,9 @@ public abstract class TileImage
|
|||
throws IOException;
|
||||
SourceImage getImage(String name)
|
||||
throws IOException;
|
||||
|
||||
TileImage parseFrameSpec(String tmp)
|
||||
throws IOException;
|
||||
}
|
||||
|
||||
static SimpleTileImage readSimpleImage(XMLStreamReader in, LoaderContext ctx)
|
||||
|
|
|
@ -63,6 +63,10 @@ public class TileImages
|
|||
}
|
||||
return images.get(fileName);
|
||||
}
|
||||
|
||||
public TileImage parseFrameSpec(String tmp) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
void initTileImageMap()
|
||||
|
|
Reference in a new issue