Moved some bundle stuff into BundleUtil. Added methods to support
post-parsing tileset validation. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@699 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ObjectTileSet.java,v 1.2 2001/11/18 04:09:21 mdb Exp $
|
// $Id: ObjectTileSet.java,v 1.3 2001/11/29 21:57:31 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -40,6 +40,26 @@ public class ObjectTileSet extends SwissArmyTileSet
|
|||||||
_oheights[tileIndex] = objHeight;
|
_oheights[tileIndex] = objHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the widths (in unit tile count) of the objects in this
|
||||||
|
* tileset. This must be accompanied by a call to {@link
|
||||||
|
* #setObjectHeights}.
|
||||||
|
*/
|
||||||
|
public void setObjectWidths (int[] objectWidths)
|
||||||
|
{
|
||||||
|
_owidths = objectWidths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the heights (in unit tile count) of the objects in this
|
||||||
|
* tileset. This must be accompanied by a call to {@link
|
||||||
|
* #setObjectWidths}.
|
||||||
|
*/
|
||||||
|
public void setObjectHeights (int[] objectHeights)
|
||||||
|
{
|
||||||
|
_oheights = objectHeights;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates instances of {@link ObjectTile}, which can span more than a
|
* Creates instances of {@link ObjectTile}, which can span more than a
|
||||||
* single tile's space in a display.
|
* single tile's space in a display.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SwissArmyTileSet.java,v 1.3 2001/11/27 08:41:01 mdb Exp $
|
// $Id: SwissArmyTileSet.java,v 1.4 2001/11/29 21:57:31 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -43,6 +43,14 @@ public class SwissArmyTileSet extends TileSet
|
|||||||
computeTileCount();
|
computeTileCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the tile count settings.
|
||||||
|
*/
|
||||||
|
public int[] getTileCounts ()
|
||||||
|
{
|
||||||
|
return _tileCounts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes our total tile count from the individual counts for each
|
* Computes our total tile count from the individual counts for each
|
||||||
* row.
|
* row.
|
||||||
@@ -65,6 +73,14 @@ public class SwissArmyTileSet extends TileSet
|
|||||||
_widths = widths;
|
_widths = widths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the width settings.
|
||||||
|
*/
|
||||||
|
public int[] getWidths ()
|
||||||
|
{
|
||||||
|
return _widths;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the tile heights for each row. Each row can have tiles of a
|
* Sets the tile heights for each row. Each row can have tiles of a
|
||||||
* different height.
|
* different height.
|
||||||
@@ -74,6 +90,14 @@ public class SwissArmyTileSet extends TileSet
|
|||||||
_heights = heights;
|
_heights = heights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the height settings.
|
||||||
|
*/
|
||||||
|
public int[] getHeights ()
|
||||||
|
{
|
||||||
|
return _heights;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the offset in pixels of the upper left corner of the first
|
* Sets the offset in pixels of the upper left corner of the first
|
||||||
* tile in the first row. If the tileset image has a border, this can
|
* tile in the first row. If the tileset image has a border, this can
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: UniformTileSet.java,v 1.3 2001/11/18 04:09:21 mdb Exp $
|
// $Id: UniformTileSet.java,v 1.4 2001/11/29 21:57:31 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -41,6 +41,14 @@ public class UniformTileSet extends TileSet
|
|||||||
_width = width;
|
_width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the width of the tiles in this tileset.
|
||||||
|
*/
|
||||||
|
public int getWidth ()
|
||||||
|
{
|
||||||
|
return _width;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the height of the tiles in this tileset.
|
* Specifies the height of the tiles in this tileset.
|
||||||
*/
|
*/
|
||||||
@@ -49,6 +57,14 @@ public class UniformTileSet extends TileSet
|
|||||||
_height = height;
|
_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the height of the tiles in this tileset.
|
||||||
|
*/
|
||||||
|
public int getHeight ()
|
||||||
|
{
|
||||||
|
return _height;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected Image extractTileImage (int tileId)
|
protected Image extractTileImage (int tileId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// $Id: BundleUtil.java,v 1.1 2001/11/29 21:57:31 mdb Exp $
|
||||||
|
|
||||||
|
package com.threerings.media.tile.bundle;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
|
||||||
|
import com.threerings.resource.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bundle related utility functions.
|
||||||
|
*/
|
||||||
|
public class BundleUtil
|
||||||
|
{
|
||||||
|
/** The path to the metadata resource that we will attempt to load
|
||||||
|
* from our resource set. */
|
||||||
|
public static final String METADATA_PATH = "tsbundles.dat";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts and initializes a serialized tileset bundle instance from
|
||||||
|
* the supplied resource bundle.
|
||||||
|
*/
|
||||||
|
public static TileSetBundle extractBundle (ResourceBundle bundle)
|
||||||
|
throws IOException, ClassNotFoundException
|
||||||
|
{
|
||||||
|
// unserialize the tileset bundles array
|
||||||
|
InputStream tbin = bundle.getResource(METADATA_PATH);
|
||||||
|
ObjectInputStream oin = new ObjectInputStream(
|
||||||
|
new BufferedInputStream(tbin));
|
||||||
|
TileSetBundle tsb = (TileSetBundle)oin.readObject();
|
||||||
|
// initialize the bundle and add it to the list
|
||||||
|
tsb.init(bundle);
|
||||||
|
return tsb;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
//
|
//
|
||||||
// $Id: BundledTileSetRepository.java,v 1.3 2001/11/29 00:12:42 mdb Exp $
|
// $Id: BundledTileSetRepository.java,v 1.4 2001/11/29 21:57:31 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile.bundle;
|
package com.threerings.media.tile.bundle;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -31,10 +28,6 @@ import com.threerings.media.tile.TileSetRepository;
|
|||||||
public class BundledTileSetRepository
|
public class BundledTileSetRepository
|
||||||
implements TileSetRepository
|
implements TileSetRepository
|
||||||
{
|
{
|
||||||
/** The path to the metadata resource that we will attempt to load
|
|
||||||
* from our resource set. */
|
|
||||||
public static final String METADATA_PATH = "tsbundles.dat";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a repository which will obtain its resource set from the
|
* Constructs a repository which will obtain its resource set from the
|
||||||
* supplied resource manager.
|
* supplied resource manager.
|
||||||
@@ -64,17 +57,9 @@ public class BundledTileSetRepository
|
|||||||
ArrayList tbundles = new ArrayList();;
|
ArrayList tbundles = new ArrayList();;
|
||||||
for (int i = 0; i < rbundles.length; i++) {
|
for (int i = 0; i < rbundles.length; i++) {
|
||||||
try {
|
try {
|
||||||
// unserialize the tileset bundles array
|
tbundles.add(BundleUtil.extractBundle(rbundles[i]));
|
||||||
InputStream tbin = rbundles[i].getResource(METADATA_PATH);
|
|
||||||
ObjectInputStream oin = new ObjectInputStream(
|
|
||||||
new BufferedInputStream(tbin));
|
|
||||||
TileSetBundle tsb = (TileSetBundle)oin.readObject();
|
|
||||||
// initialize the bundle and add it to the list
|
|
||||||
tsb.init(rbundles[i]);
|
|
||||||
tbundles.add(tsb);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning("Unable to load tileset bundles from resource " +
|
Log.warning("Unable to load tileset bundle from resource " +
|
||||||
"bundle [rbundle=" + rbundles[i] +
|
"bundle [rbundle=" + rbundles[i] +
|
||||||
", error=" + e + "].");
|
", error=" + e + "].");
|
||||||
Log.logStackTrace(e);
|
Log.logStackTrace(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user