com.threerings.media.tile.bundle
Class BundledTileSetRepository

java.lang.Object
  extended by com.threerings.media.tile.bundle.BundledTileSetRepository
All Implemented Interfaces:
TileSetRepository

public class BundledTileSetRepository
extends Object
implements TileSetRepository

Loads tileset data from a set of resource bundles.

See Also:
ResourceManager

Field Summary
protected  HashIntMap<TileSet> _idmap
          A mapping from tileset id to tileset.
protected  ImageManager _imgr
          The image manager via which we load our images.
protected  HashMap<String,Integer> _namemap
          A mapping from tileset name to tileset id.
 
Constructor Summary
BundledTileSetRepository(ResourceManager rmgr, ImageManager imgr, String name)
          Constructs a repository which will obtain its resource set from the supplied resource manager.
 
Method Summary
protected  void addBundle(HashIntMap<TileSet> idmap, HashMap<String,Integer> namemap, ResourceBundle bundle)
          Extracts the tileset bundle from the supplied resource bundle and registers it.
protected  void addBundle(HashIntMap<TileSet> idmap, HashMap<String,Integer> namemap, TileSetBundle bundle)
          Adds the tilesets in the supplied bundle to our tileset mapping tables.
 void addBundle(ResourceBundle bundle)
          Registers the bundle with the tileset repository, overriding any bundle with the same id or name.
 Iterator<Integer> enumerateTileSetIds()
          Returns an iterator over the identifiers of all TileSet objects available.
 Iterator<TileSet> enumerateTileSets()
          Returns an iterator over all TileSet objects available.
 TileSet getTileSet(int tileSetId)
          Returns the TileSet with the specified tile set identifier.
 TileSet getTileSet(String setName)
          Returns the TileSet with the specified tile set name.
 int getTileSetId(String setName)
          Returns the unique identifier of the TileSet with the specified tile set name.
protected  void initBundles(ResourceManager rmgr, String name)
          Initializes our bundles,
protected  void waitForBundles()
          Used to allow bundle unpacking to proceed asynchronously.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_imgr

protected ImageManager _imgr
The image manager via which we load our images.


_idmap

protected HashIntMap<TileSet> _idmap
A mapping from tileset id to tileset.


_namemap

protected HashMap<String,Integer> _namemap
A mapping from tileset name to tileset id.

Constructor Detail

BundledTileSetRepository

public BundledTileSetRepository(ResourceManager rmgr,
                                ImageManager imgr,
                                String name)
Constructs a repository which will obtain its resource set from the supplied resource manager.

Parameters:
rmgr - the resource manager from which to obtain our resource set.
imgr - the image manager through which we will configure the tile sets to load their images, or null if image tiles should not be loaded (only the tile metadata)
name - the name of the resource set from which we will be loading our tile data.
Method Detail

initBundles

protected void initBundles(ResourceManager rmgr,
                           String name)
Initializes our bundles,


addBundle

public void addBundle(ResourceBundle bundle)
Registers the bundle with the tileset repository, overriding any bundle with the same id or name.


addBundle

protected void addBundle(HashIntMap<TileSet> idmap,
                         HashMap<String,Integer> namemap,
                         ResourceBundle bundle)
Extracts the tileset bundle from the supplied resource bundle and registers it.


addBundle

protected void addBundle(HashIntMap<TileSet> idmap,
                         HashMap<String,Integer> namemap,
                         TileSetBundle bundle)
Adds the tilesets in the supplied bundle to our tileset mapping tables. Any tilesets with the same name or id will be overwritten.


enumerateTileSetIds

public Iterator<Integer> enumerateTileSetIds()
                                      throws PersistenceException
Description copied from interface: TileSetRepository
Returns an iterator over the identifiers of all TileSet objects available.

Specified by:
enumerateTileSetIds in interface TileSetRepository
Throws:
PersistenceException

enumerateTileSets

public Iterator<TileSet> enumerateTileSets()
                                    throws PersistenceException
Description copied from interface: TileSetRepository
Returns an iterator over all TileSet objects available.

Specified by:
enumerateTileSets in interface TileSetRepository
Throws:
PersistenceException

getTileSet

public TileSet getTileSet(int tileSetId)
                   throws NoSuchTileSetException,
                          PersistenceException
Description copied from interface: TileSetRepository
Returns the TileSet with the specified tile set identifier. The repository is responsible for configuring the tile set with an image provider.

Specified by:
getTileSet in interface TileSetRepository
Throws:
NoSuchTileSetException - thrown if no tileset exists with the specified identifier.
PersistenceException - thrown if an error occurs communicating with the underlying persistence mechanism.

getTileSetId

public int getTileSetId(String setName)
                 throws NoSuchTileSetException,
                        PersistenceException
Description copied from interface: TileSetRepository
Returns the unique identifier of the TileSet with the specified tile set name.

Specified by:
getTileSetId in interface TileSetRepository
Throws:
NoSuchTileSetException - thrown if no tileset exists with the specified name.
PersistenceException - thrown if an error occurs communicating with the underlying persistence mechanism.

getTileSet

public TileSet getTileSet(String setName)
                   throws NoSuchTileSetException,
                          PersistenceException
Description copied from interface: TileSetRepository
Returns the TileSet with the specified tile set name. The repository is responsible for configuring the tile set with an image provider.

Specified by:
getTileSet in interface TileSetRepository
Throws:
NoSuchTileSetException - thrown if no tileset exists with the specified name.
PersistenceException - thrown if an error occurs communicating with the underlying persistence mechanism.

waitForBundles

protected void waitForBundles()
Used to allow bundle unpacking to proceed asynchronously.