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
src/micropolisj
|
@ -1,7 +1,7 @@
|
||||||
package micropolisj.build_tool;
|
package micropolisj.build_tool;
|
||||||
|
|
||||||
import micropolisj.engine.TileSpec;
|
import micropolisj.engine.TileSpec;
|
||||||
import micropolisj.graphics.TileImage;
|
import micropolisj.graphics.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -423,7 +423,7 @@ public class MakeTiles
|
||||||
{
|
{
|
||||||
File f = new File(fileName + ".ani");
|
File f = new File(fileName + ".ani");
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
return Animation.load(f);
|
return Animation.load(f, loaderContext);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return loadImage(fileName);
|
return loadImage(fileName);
|
||||||
|
@ -451,6 +451,12 @@ public class MakeTiles
|
||||||
|
|
||||||
return loadedImages.get(fileName);
|
return loadedImages.get(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileImage parseFrameSpec(String tmp)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
return MakeTiles.parseFrameSpec(tmp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
static MyLoaderContext loaderContext = new MyLoaderContext();
|
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.awt.Graphics2D;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.xml.stream.*;
|
import javax.xml.stream.*;
|
||||||
import static micropolisj.XML_Helper.*;
|
import static micropolisj.XML_Helper.*;
|
||||||
|
|
||||||
class Animation extends TileImage
|
public class Animation extends TileImage
|
||||||
{
|
{
|
||||||
static final int DEFAULT_DURATION = 125;
|
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
|
throws IOException
|
||||||
{
|
{
|
||||||
FileInputStream fis = new FileInputStream(aniFile);
|
FileInputStream fis = new FileInputStream(aniFile);
|
||||||
Animation self = new Animation();
|
Animation self = new Animation();
|
||||||
self.load(fis);
|
self.load(fis, ctx);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ class Animation extends TileImage
|
||||||
frames.add(f);
|
frames.add(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(InputStream inStream)
|
void load(InputStream inStream, LoaderContext ctx)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -51,7 +52,7 @@ class Animation extends TileImage
|
||||||
int duration = tmp != null ? Integer.parseInt(tmp) : DEFAULT_DURATION;
|
int duration = tmp != null ? Integer.parseInt(tmp) : DEFAULT_DURATION;
|
||||||
|
|
||||||
tmp = in.getElementText();
|
tmp = in.getElementText();
|
||||||
addFrame( MakeTiles.parseFrameSpec(tmp), duration );
|
addFrame( ctx.parseFrameSpec(tmp), duration );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// unrecognized element
|
// unrecognized element
|
||||||
|
@ -68,10 +69,10 @@ class Animation extends TileImage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Frame
|
public class Frame
|
||||||
{
|
{
|
||||||
TileImage frame;
|
public final TileImage frame;
|
||||||
int duration;
|
public final int duration;
|
||||||
|
|
||||||
public Frame(TileImage frame, int duration)
|
public Frame(TileImage frame, int duration)
|
||||||
{
|
{
|
|
@ -132,6 +132,9 @@ public abstract class TileImage
|
||||||
throws IOException;
|
throws IOException;
|
||||||
SourceImage getImage(String name)
|
SourceImage getImage(String name)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
|
TileImage parseFrameSpec(String tmp)
|
||||||
|
throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SimpleTileImage readSimpleImage(XMLStreamReader in, LoaderContext ctx)
|
static SimpleTileImage readSimpleImage(XMLStreamReader in, LoaderContext ctx)
|
||||||
|
|
|
@ -63,6 +63,10 @@ public class TileImages
|
||||||
}
|
}
|
||||||
return images.get(fileName);
|
return images.get(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileImage parseFrameSpec(String tmp) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTileImageMap()
|
void initTileImageMap()
|
||||||
|
|
Reference in a new issue