From be5428a2f792ce0f0267b6e7d30fe0fa7125ac5f Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 29 Nov 2001 21:57:31 +0000 Subject: [PATCH] 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 --- .../threerings/media/tile/ObjectTileSet.java | 22 ++++++++++- .../media/tile/SwissArmyTileSet.java | 26 ++++++++++++- .../threerings/media/tile/UniformTileSet.java | 18 ++++++++- .../media/tile/bundle/BundleUtil.java | 38 +++++++++++++++++++ .../tile/bundle/BundledTileSetRepository.java | 21 ++-------- 5 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 src/java/com/threerings/media/tile/bundle/BundleUtil.java diff --git a/src/java/com/threerings/media/tile/ObjectTileSet.java b/src/java/com/threerings/media/tile/ObjectTileSet.java index 4c2e2a730..e61ab7090 100644 --- a/src/java/com/threerings/media/tile/ObjectTileSet.java +++ b/src/java/com/threerings/media/tile/ObjectTileSet.java @@ -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; @@ -40,6 +40,26 @@ public class ObjectTileSet extends SwissArmyTileSet _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 * single tile's space in a display. diff --git a/src/java/com/threerings/media/tile/SwissArmyTileSet.java b/src/java/com/threerings/media/tile/SwissArmyTileSet.java index 1ccf1b116..1485f906b 100644 --- a/src/java/com/threerings/media/tile/SwissArmyTileSet.java +++ b/src/java/com/threerings/media/tile/SwissArmyTileSet.java @@ -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; @@ -43,6 +43,14 @@ public class SwissArmyTileSet extends TileSet computeTileCount(); } + /** + * Returns the tile count settings. + */ + public int[] getTileCounts () + { + return _tileCounts; + } + /** * Computes our total tile count from the individual counts for each * row. @@ -65,6 +73,14 @@ public class SwissArmyTileSet extends TileSet _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 * different height. @@ -74,6 +90,14 @@ public class SwissArmyTileSet extends TileSet _heights = heights; } + /** + * Returns the height settings. + */ + public int[] getHeights () + { + return _heights; + } + /** * 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 diff --git a/src/java/com/threerings/media/tile/UniformTileSet.java b/src/java/com/threerings/media/tile/UniformTileSet.java index 6ddc261e7..53b6115fd 100644 --- a/src/java/com/threerings/media/tile/UniformTileSet.java +++ b/src/java/com/threerings/media/tile/UniformTileSet.java @@ -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; @@ -41,6 +41,14 @@ public class UniformTileSet extends TileSet _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. */ @@ -49,6 +57,14 @@ public class UniformTileSet extends TileSet _height = height; } + /** + * Returns the height of the tiles in this tileset. + */ + public int getHeight () + { + return _height; + } + // documentation inherited protected Image extractTileImage (int tileId) { diff --git a/src/java/com/threerings/media/tile/bundle/BundleUtil.java b/src/java/com/threerings/media/tile/bundle/BundleUtil.java new file mode 100644 index 000000000..29b37102f --- /dev/null +++ b/src/java/com/threerings/media/tile/bundle/BundleUtil.java @@ -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; + } +} diff --git a/src/java/com/threerings/media/tile/bundle/BundledTileSetRepository.java b/src/java/com/threerings/media/tile/bundle/BundledTileSetRepository.java index 8b7d932e7..e0f2bff8d 100644 --- a/src/java/com/threerings/media/tile/bundle/BundledTileSetRepository.java +++ b/src/java/com/threerings/media/tile/bundle/BundledTileSetRepository.java @@ -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; -import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; import java.util.ArrayList; import java.util.Iterator; @@ -31,10 +28,6 @@ import com.threerings.media.tile.TileSetRepository; public class BundledTileSetRepository 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 * supplied resource manager. @@ -64,17 +57,9 @@ public class BundledTileSetRepository ArrayList tbundles = new ArrayList();; for (int i = 0; i < rbundles.length; i++) { try { - // unserialize the tileset bundles array - 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); - + tbundles.add(BundleUtil.extractBundle(rbundles[i])); } 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] + ", error=" + e + "]."); Log.logStackTrace(e);