General updating per initial code review. Created EditableSceneView
to separate scene display from editing functionality. Load and initialize managers in a fashion that more appropriately hides the implementation details. Tidied comments up a bit. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@103 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ImageManager.java,v 1.2 2001/07/18 22:45:34 shaper Exp $
|
||||
// $Id: ImageManager.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.media;
|
||||
|
||||
@@ -15,15 +15,12 @@ import java.util.Hashtable;
|
||||
* The ImageManager class provides a single point of access for image
|
||||
* retrieval and caching.
|
||||
*
|
||||
* <p> <b>Note:</b> The ImageManager must be initialized with a root
|
||||
* AWT component before images can be retrieved, in the interest of
|
||||
* allowing for proper preparation of images for optimal storage and
|
||||
* eventual display.
|
||||
* <p> <b>Note:</b> The ImageManager must be constructed with a root
|
||||
* AWT component, in the interest of allowing for proper preparation
|
||||
* of images for optimal storage and eventual display.
|
||||
*/
|
||||
public class ImageManager
|
||||
{
|
||||
public Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
|
||||
/**
|
||||
* Construct an ImageManager object with the ResourceManager from
|
||||
* which it will obtain its data, and a root component to which
|
||||
@@ -33,7 +30,7 @@ public class ImageManager
|
||||
{
|
||||
_rmgr = rmgr;
|
||||
_root = root;
|
||||
tk = root.getToolkit();
|
||||
_tk = root.getToolkit();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +54,7 @@ public class ImageManager
|
||||
|
||||
try {
|
||||
byte[] data = _rmgr.getResourceAsBytes(fname);
|
||||
img = tk.createImage(data);
|
||||
img = _tk.createImage(data);
|
||||
MediaTracker tracker = new MediaTracker(_root);
|
||||
tracker.addImage(img, 0);
|
||||
|
||||
@@ -99,4 +96,5 @@ public class ImageManager
|
||||
protected ResourceManager _rmgr;
|
||||
protected Component _root;
|
||||
protected Hashtable _imgs = new Hashtable();
|
||||
protected Toolkit _tk = Toolkit.getDefaultToolkit();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Tile.java,v 1.6 2001/07/20 08:17:10 shaper Exp $
|
||||
// $Id: Tile.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -10,25 +10,33 @@ import java.awt.Image;
|
||||
*/
|
||||
public class Tile
|
||||
{
|
||||
public Image img; // the tile image
|
||||
public short tsid; // the tile set identifier
|
||||
public short tid; // the tile identifier within the set
|
||||
/** The tile image. */
|
||||
public Image img;
|
||||
|
||||
/** The tile set identifier. */
|
||||
public short tsid;
|
||||
|
||||
/** The tile identifier within the set. */
|
||||
public short tid;
|
||||
|
||||
/** The tile height in pixels. */
|
||||
public short height; // the tile height in pixels
|
||||
|
||||
// height and width of a tile image in pixels
|
||||
/** The height and width of a tile image in pixels. */
|
||||
public static final int HEIGHT = 16;
|
||||
public static final int WIDTH = 32;
|
||||
|
||||
// halved values of tile width/height in pixels for use in common
|
||||
// tile-dimension-related calculations
|
||||
/** Halved tile width in pixels for use in common calculations. */
|
||||
public static final int HALF_HEIGHT = HEIGHT / 2;
|
||||
|
||||
/** Halved tile height in pixels for use in common calculations. */
|
||||
public static final int HALF_WIDTH = WIDTH / 2;
|
||||
|
||||
/**
|
||||
* Construct a new tile with the specified identifiers. Intended
|
||||
* only for use by the TileManager. Do not use this method.
|
||||
*
|
||||
* @see com.threerings.miso.TileManager#getTile
|
||||
* @see TileManager#getTile
|
||||
*/
|
||||
public Tile (int tsid, int tid)
|
||||
{
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
//
|
||||
// $Id: TileManager.java,v 1.9 2001/07/21 01:51:10 shaper Exp $
|
||||
// $Id: TileManager.java,v 1.10 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
|
||||
import com.samskivert.util.ConfigUtil;
|
||||
import com.samskivert.util.IntMap;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -33,7 +31,7 @@ public class TileManager
|
||||
public Tile getTile (int tsid, int tid)
|
||||
{
|
||||
// the fully unique tile id is the conjoined tile set and tile id
|
||||
int utid = tsid << 16 | tid;
|
||||
int utid = (tsid << 16) | tid;
|
||||
|
||||
// look the tile up in our hash
|
||||
Tile tile = (Tile) _tiles.get(utid);
|
||||
@@ -65,30 +63,9 @@ public class TileManager
|
||||
return _tsmgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all tileset objects described in the specified file into
|
||||
* the set of available tilesets.
|
||||
*/
|
||||
public void loadTileSets (String fname)
|
||||
{
|
||||
try {
|
||||
InputStream tis = ConfigUtil.getStream(fname);
|
||||
if (tis == null) {
|
||||
Log.warning("Couldn't find file [fname=" + fname + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
_tsmgr.loadTileSets(tis);
|
||||
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading tileset [fname=" + fname +
|
||||
", ioe=" + ioe + "].");
|
||||
}
|
||||
}
|
||||
|
||||
// mapping from (tsid << 16 | tid) to tile objects
|
||||
/** Cache of tiles that have been requested thus far. */
|
||||
protected IntMap _tiles = new IntMap();
|
||||
|
||||
// our tile set manager
|
||||
/** Our tileset manager. */
|
||||
protected TileSetManager _tsmgr;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
//
|
||||
// $Id: TileSet.java,v 1.9 2001/07/20 08:17:10 shaper Exp $
|
||||
// $Id: TileSet.java,v 1.10 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.*;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.*;
|
||||
|
||||
/**
|
||||
* A tileset stores information on a single logical set of tiles. It
|
||||
* provides a clean interface for the TileManager to retrieve
|
||||
* individual tile images from a particular tile in the tileset.
|
||||
*
|
||||
* <p> The width of each tile in every tileset is a constant
|
||||
* Tile.WIDTH in pixels. The tile count in each row can vary. The
|
||||
* height of the tiles in each row can also vary. This information is
|
||||
* obtained from the config object.
|
||||
* <code>Tile.WIDTH</code> in pixels. The tile count in each row can
|
||||
* vary. The height of the tiles in each row can also vary. This
|
||||
* information is obtained from the config object.
|
||||
*
|
||||
* <p> Tiles are retrieved from the tile set by the TileManager, and
|
||||
* are referenced by their tile id (essentially the tile number,
|
||||
@@ -116,27 +116,33 @@ public class TileSet
|
||||
buf.append(", tsid=").append(_tsid);
|
||||
buf.append(", numtiles=").append(_numTiles);
|
||||
|
||||
buf.append(", rowheight={");
|
||||
for (int ii = 0; ii < _rowHeight.length; ii++) {
|
||||
if (ii > 0) buf.append(",");
|
||||
buf.append(_rowHeight[ii]);
|
||||
}
|
||||
buf.append(", rowheight=");
|
||||
StringUtil.toString(buf, _rowHeight);
|
||||
|
||||
buf.append("}, tilecount={");
|
||||
for (int ii = 0; ii < _tileCount.length; ii++) {
|
||||
if (ii > 0) buf.append(",");
|
||||
buf.append(_tileCount[ii]);
|
||||
}
|
||||
buf.append(", tilecount=");
|
||||
StringUtil.toString(buf, _tileCount);
|
||||
|
||||
return buf.append("}]").toString();
|
||||
return buf.append("]").toString();
|
||||
}
|
||||
|
||||
protected String _name; // the tileset name
|
||||
protected String _imgFile; // the file containing the tile images
|
||||
protected int _tsid; // the tileset unique identifier
|
||||
protected int _rowHeight[]; // the height of each row in pixels
|
||||
protected int _tileCount[]; // the number of tiles in each row
|
||||
protected int _numTiles; // the total number of tiles
|
||||
/** The tileset name. */
|
||||
protected String _name;
|
||||
|
||||
/** The file containing the tile images. */
|
||||
protected String _imgFile;
|
||||
|
||||
/** The tileset unique identifier. */
|
||||
protected int _tsid;
|
||||
|
||||
/** The height of each row in pixels. */
|
||||
protected int _rowHeight[];
|
||||
|
||||
/** The number of tiles in each row. */
|
||||
protected int _tileCount[];
|
||||
|
||||
/** The total number of tiles. */
|
||||
protected int _numTiles;
|
||||
|
||||
/** The image containing all tile images for this set. */
|
||||
protected Image _imgTiles;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
//
|
||||
// $Id: TileSetManager.java,v 1.7 2001/07/21 01:51:10 shaper Exp $
|
||||
// $Id: TileSetManager.java,v 1.8 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface TileSetManager
|
||||
{
|
||||
/**
|
||||
* Initialize the TileSetManager with the given ImageManager.
|
||||
*/
|
||||
public void init (ImageManager imgmgr);
|
||||
|
||||
/**
|
||||
* Return the total number of tiles in the specified tileset.
|
||||
*/
|
||||
@@ -41,10 +34,4 @@ public interface TileSetManager
|
||||
* Return the total number of tilesets.
|
||||
*/
|
||||
public int getNumTileSets ();
|
||||
|
||||
/**
|
||||
* Load the tilesets described in the specified input stream into
|
||||
* the set of available tilesets.
|
||||
*/
|
||||
public void loadTileSets (InputStream tis) throws IOException;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
//
|
||||
// $Id: TileSetManagerImpl.java,v 1.6 2001/07/21 01:51:10 shaper Exp $
|
||||
// $Id: TileSetManagerImpl.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
import com.samskivert.util.IntMap;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import com.samskivert.util.*;
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
public abstract class TileSetManagerImpl implements TileSetManager
|
||||
{
|
||||
public void init (ImageManager imgr)
|
||||
/**
|
||||
* Initialize the TileSetManager with a Config object to obtain
|
||||
* configuration information and an ImageManager object for use in
|
||||
* retrieving tile images.
|
||||
*/
|
||||
public void init (Config config, ImageManager imgmgr)
|
||||
{
|
||||
_imgr = imgr;
|
||||
_imgmgr = imgmgr;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public int getNumTilesInSet (int tsid)
|
||||
@@ -32,7 +38,7 @@ public abstract class TileSetManagerImpl implements TileSetManager
|
||||
public Image getTileImage (int tsid, int tid)
|
||||
{
|
||||
TileSet tset = getTileSet(tsid);
|
||||
return (tset != null) ? tset.getTileImage(_imgr, tid) : null;
|
||||
return (tset != null) ? tset.getTileImage(_imgmgr, tid) : null;
|
||||
}
|
||||
|
||||
public ArrayList getAllTileSets ()
|
||||
@@ -41,12 +47,7 @@ public abstract class TileSetManagerImpl implements TileSetManager
|
||||
if (size == 0) return null;
|
||||
|
||||
ArrayList list = new ArrayList();
|
||||
|
||||
Enumeration sets = _tilesets.elements();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
list.add(sets.nextElement());
|
||||
}
|
||||
|
||||
CollectionUtil.addAll(list, _tilesets.elements());
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -55,6 +56,7 @@ public abstract class TileSetManagerImpl implements TileSetManager
|
||||
return _tilesets.size();
|
||||
}
|
||||
|
||||
protected ImageManager _imgr;
|
||||
protected Config _config;
|
||||
protected ImageManager _imgmgr;
|
||||
protected IntMap _tilesets = new IntMap();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileSetParser.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
|
||||
// $Id: TileSetParser.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -15,16 +15,10 @@ import java.util.ArrayList;
|
||||
public interface TileSetParser
|
||||
{
|
||||
/**
|
||||
* Return all tileset objects constructed from any previous
|
||||
* parsing activity.
|
||||
* Read tileset description data from the given input stream and
|
||||
* construct TileSet objects to suit. Return an ArrayList of all
|
||||
* TileSet objects constructed, or a zero-length array if no
|
||||
* tileset descriptions were fully parsed.
|
||||
*/
|
||||
public ArrayList getTileSets ();
|
||||
|
||||
/**
|
||||
* Construct tileset objects from the tileset description data on
|
||||
* the given input stream. Classes that implement this method
|
||||
* should store the tileset objects for later retrieval via the
|
||||
* <code>getTileSets()</code> method.
|
||||
*/
|
||||
public void loadTileSets (InputStream tis) throws IOException;
|
||||
public ArrayList loadTileSets (InputStream tis) throws IOException;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: XMLTileSetParser.java,v 1.4 2001/07/20 23:41:12 shaper Exp $
|
||||
// $Id: XMLTileSetParser.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -75,10 +75,11 @@ public class XMLTileSetParser extends DefaultHandler
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTileSets (InputStream tis) throws IOException
|
||||
public ArrayList loadTileSets (InputStream tis) throws IOException
|
||||
{
|
||||
try {
|
||||
XMLUtil.parse(this, tis);
|
||||
return _tilesets;
|
||||
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new IOException(pce.toString());
|
||||
@@ -88,13 +89,10 @@ public class XMLTileSetParser extends DefaultHandler
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList getTileSets ()
|
||||
{
|
||||
if (_tilesets.size() == 0) return null;
|
||||
return _tilesets;
|
||||
}
|
||||
|
||||
/** The XML element tag currently being processed. */
|
||||
protected String _tag;
|
||||
|
||||
/** The tilesets constructed thus far. */
|
||||
protected ArrayList _tilesets = new ArrayList();
|
||||
|
||||
// temporary storage of tileset object values
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
//
|
||||
// $Id: CompiledSceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||
// $Id: CompiledSceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CompiledSceneManager extends SceneManagerImpl
|
||||
{
|
||||
public void loadScenes (InputStream in) throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.8 2001/07/20 07:09:56 shaper Exp $
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.9 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -43,18 +43,6 @@ public class Scene
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_file = null;
|
||||
}
|
||||
|
||||
public File getFile ()
|
||||
{
|
||||
return _file;
|
||||
}
|
||||
|
||||
public void setFile (File file)
|
||||
{
|
||||
_file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,7 +213,5 @@ public class Scene
|
||||
protected Point _hotspots[]; // hot spot zone points
|
||||
protected ExitPoint _exits[]; // exit points to different scenes
|
||||
|
||||
protected File _file; // the file last associated with this scene
|
||||
|
||||
protected TileManager _tmgr;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
//
|
||||
// $Id: EditableSceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||
// $Id: EditableSceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class EditableSceneManager extends SceneManagerImpl
|
||||
{
|
||||
public void loadScenes (InputStream in) throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
//
|
||||
// $Id: ExitPoint.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
|
||||
// $Id: ExitPoint.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
/**
|
||||
* Represents a point in a scene that leads to a different scene.
|
||||
* The ExitPoint class represents a point in a scene that leads to a
|
||||
* different scene.
|
||||
*/
|
||||
public class ExitPoint
|
||||
{
|
||||
byte x, y; // coordinates for this exit point
|
||||
short sid; // scene id this exit transitions to
|
||||
/** Coordinates for this exit point. */
|
||||
public byte x, y;
|
||||
|
||||
/** The scene id this exit transitions to. */
|
||||
public short sid;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.13 2001/07/20 08:17:10 shaper Exp $
|
||||
// $Id: IsoSceneView.java,v 1.14 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.awt.image.*;
|
||||
* The IsoSceneView provides an isometric graphics view of a
|
||||
* particular scene.
|
||||
*/
|
||||
public class IsoSceneView implements SceneView
|
||||
public class IsoSceneView implements EditableSceneView
|
||||
{
|
||||
public IsoSceneView (TileManager tmgr)
|
||||
{
|
||||
@@ -246,19 +246,23 @@ public class IsoSceneView implements SceneView
|
||||
_scene.tiles[tpos.x][tpos.y][lnum] = tile;
|
||||
}
|
||||
|
||||
// default dimensions of the scene view
|
||||
/** The default width of a scene in pixels. */
|
||||
protected static final int DEF_BOUNDS_WIDTH = 18 * Tile.WIDTH;
|
||||
|
||||
/** The default height of a scene in pixels. */
|
||||
protected static final int DEF_BOUNDS_HEIGHT = 37 * Tile.HEIGHT;
|
||||
|
||||
// total number of tile rows to render the full view
|
||||
/** The total number of tile rows to render the full scene view. */
|
||||
protected static final int TILE_RENDER_ROWS =
|
||||
(Scene.TILE_WIDTH * Scene.TILE_HEIGHT) - 1;
|
||||
|
||||
// starting x/y-positions to render the view
|
||||
/** The starting x-position to render the view. */
|
||||
protected static final int DEF_CENTER_X = DEF_BOUNDS_WIDTH / 2;
|
||||
|
||||
/** The starting y-position to render the view. */
|
||||
protected static final int DEF_CENTER_Y = -(9 * Tile.HEIGHT);
|
||||
|
||||
// length of a tile edge as rendered from an isometric perspective
|
||||
/** The length of a tile edge as rendered from an isometric perspective. */
|
||||
public static final float TILE_EDGE_LENGTH = (float)
|
||||
Math.sqrt((Tile.HALF_WIDTH * Tile.HALF_WIDTH) +
|
||||
(Tile.HALF_HEIGHT * Tile.HALF_HEIGHT));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||
// $Id: SceneManager.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -22,16 +22,4 @@ public interface SceneManager
|
||||
* layer id.
|
||||
*/
|
||||
public String[] getLayerNames ();
|
||||
|
||||
/**
|
||||
* Load all scene objects described in the specified file into the
|
||||
* set of available scenes.
|
||||
*/
|
||||
public void loadScenes (String fname);
|
||||
|
||||
/**
|
||||
* Load all scene objects described in the specified input stream
|
||||
* into the set of available scenes.
|
||||
*/
|
||||
public void loadScenes (InputStream in) throws IOException;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneManagerImpl.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||
// $Id: SceneManagerImpl.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -22,21 +22,4 @@ public abstract class SceneManagerImpl implements SceneManager
|
||||
{
|
||||
return Scene.XLATE_LAYERS;
|
||||
}
|
||||
|
||||
public void loadScenes (String fname)
|
||||
{
|
||||
try {
|
||||
InputStream tis = ConfigUtil.getStream(fname);
|
||||
if (tis == null) {
|
||||
Log.warning("Couldn't find file [fname=" + fname + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
loadScenes(tis);
|
||||
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading tileset [fname=" + fname +
|
||||
", ioe=" + ioe + "].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneView.java,v 1.6 2001/07/20 00:35:09 shaper Exp $
|
||||
// $Id: SceneView.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -9,9 +9,9 @@ import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
|
||||
/**
|
||||
* An interface to be implemented by classes that provide a view of a
|
||||
* given scene by drawing the scene contents onto a particular GUI
|
||||
* component.
|
||||
* The SceneView interface provides an interface to be implemented by
|
||||
* classes that provide a view of a given scene by drawing the scene
|
||||
* contents onto a particular GUI component.
|
||||
*/
|
||||
public interface SceneView
|
||||
{
|
||||
@@ -20,23 +20,8 @@ public interface SceneView
|
||||
*/
|
||||
public void paint (Graphics g);
|
||||
|
||||
/**
|
||||
* Set a tile to be highlighted when the scene is rendered.
|
||||
*/
|
||||
public void setHighlightedTile (int x, int y);
|
||||
|
||||
/**
|
||||
* Set the scene that we're rendering.
|
||||
*/
|
||||
public void setScene (Scene scene);
|
||||
|
||||
/**
|
||||
* Set whether coordinates should be drawn for each tile.
|
||||
*/
|
||||
public void setShowCoordinates (boolean show);
|
||||
|
||||
/**
|
||||
* Set the tile at the specified location and layer in the scene.
|
||||
*/
|
||||
public void setTile (int x, int y, int lnum, Tile tile);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
//
|
||||
// $Id: CompiledTileSetManager.java,v 1.6 2001/07/21 01:51:10 shaper Exp $
|
||||
// $Id: CompiledTileSetManager.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CompiledTileSetManager extends TileSetManagerImpl
|
||||
{
|
||||
public void loadTileSets (InputStream tis) throws IOException
|
||||
{
|
||||
// TBD
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
//
|
||||
// $Id: EditableTileSetManager.java,v 1.6 2001/07/21 01:51:10 shaper Exp $
|
||||
// $Id: EditableTileSetManager.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.util.ConfigUtil;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
/**
|
||||
* Extends general tileset manager functionality to allow reading
|
||||
* tileset information from XML files. The XML file format allows for
|
||||
@@ -18,25 +20,47 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class EditableTileSetManager extends TileSetManagerImpl
|
||||
{
|
||||
public void loadTileSets (InputStream tis) throws IOException
|
||||
public void init (Config config, ImageManager imgmgr)
|
||||
{
|
||||
// read all tileset descriptions from the XML input stream
|
||||
XMLTileSetParser parser = new XMLTileSetParser();
|
||||
parser.loadTileSets(tis);
|
||||
super.init(config, imgmgr);
|
||||
|
||||
// grab any resulting tileset objects
|
||||
ArrayList tsets = parser.getTileSets();
|
||||
if (tsets == null) {
|
||||
Log.warning("No tileset descriptions found [tis=" + tis + "].");
|
||||
return;
|
||||
}
|
||||
// load the tileset descriptions
|
||||
String fname = config.getValue("miso.tilesets", (String)null);
|
||||
loadTileSets(fname);
|
||||
}
|
||||
|
||||
// and copy them into the main tileset hashtable
|
||||
int size = tsets.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
TileSet tset = (TileSet)tsets.get(ii);
|
||||
_tilesets.put(tset.getId(), tset);
|
||||
Log.info("Adding tileset to cache [tset=" + tset + "].");
|
||||
/**
|
||||
* Load the tilesets described in the specified file into the set
|
||||
* of available tilesets.
|
||||
*/
|
||||
protected void loadTileSets (String fname)
|
||||
{
|
||||
try {
|
||||
InputStream tis = ConfigUtil.getStream(fname);
|
||||
if (tis == null) {
|
||||
Log.warning("Couldn't find file [fname=" + fname + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// read all tileset descriptions from the XML input stream
|
||||
XMLTileSetParser parser = new XMLTileSetParser();
|
||||
ArrayList tsets = parser.loadTileSets(tis);
|
||||
if (tsets == null) {
|
||||
Log.warning("No tilesets found [tis=" + tis + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// copy new tilesets into the main tileset hashtable
|
||||
int size = tsets.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
TileSet tset = (TileSet)tsets.get(ii);
|
||||
_tilesets.put(tset.getId(), tset);
|
||||
Log.info("Adding tileset to cache [tset=" + tset + "].");
|
||||
}
|
||||
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading tileset [fname=" + fname +
|
||||
", ioe=" + ioe + "].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,44 @@
|
||||
//
|
||||
// $Id: MisoUtil.java,v 1.1 2001/07/21 01:51:10 shaper Exp $
|
||||
// $Id: MisoUtil.java,v 1.2 2001/07/23 18:52:51 shaper Exp $
|
||||
|
||||
package com.threerings.miso.util;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.util.*;
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.*;
|
||||
import com.threerings.miso.tile.*;
|
||||
import com.threerings.resource.ResourceManager;
|
||||
|
||||
/**
|
||||
* MisoUtil provides miscellaneous routines for applications or other
|
||||
* layers that intend to make use of Miso services.
|
||||
*/
|
||||
public class MisoUtil
|
||||
{
|
||||
/**
|
||||
* Populate the config object with miso configuration values.
|
||||
*
|
||||
* @param config the Config object to populate.
|
||||
*/
|
||||
public static void bindProperties (Config config) throws IOException
|
||||
{
|
||||
config.bindProperties("miso", "rsrc/config/miso/miso");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SceneManager object, reading the class name to
|
||||
* instantiate from the "miso.scenemgr" config value.
|
||||
*
|
||||
* @param config the Config object.
|
||||
*
|
||||
* @return the new SceneManager object or null if an error occurred.
|
||||
*/
|
||||
public static SceneManager createSceneManager (Config config)
|
||||
{
|
||||
try {
|
||||
@@ -34,6 +51,14 @@ public class MisoUtil
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a TileManager object.
|
||||
*
|
||||
* @param config the Config object.
|
||||
* @param frame the root frame to which images will be rendered.
|
||||
*
|
||||
* @return the new TileManager object or null if an error occurred.
|
||||
*/
|
||||
public static TileManager createTileManager (Config config, Frame frame)
|
||||
{
|
||||
ResourceManager rmgr = createResourceManager();
|
||||
@@ -41,13 +66,14 @@ public class MisoUtil
|
||||
TileSetManager tilesetmgr = createTileSetManager(config, imgmgr);
|
||||
TileManager tilemgr = new TileManager(tilesetmgr);
|
||||
|
||||
// load the tileset descriptions
|
||||
String tfile = config.getValue("miso.tilesets", (String)null);
|
||||
tilemgr.loadTileSets(tfile);
|
||||
|
||||
return tilemgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ResourceManager object.
|
||||
*
|
||||
* @return the new ResourceManager object or null if an error occurred.
|
||||
*/
|
||||
protected static ResourceManager createResourceManager ()
|
||||
{
|
||||
String root = System.getProperty("root", "");
|
||||
@@ -59,19 +85,27 @@ public class MisoUtil
|
||||
} catch (MalformedURLException mue) {
|
||||
Log.warning("Malformed resource manager URL [url=" + localroot +
|
||||
", mue=" + mue + "].");
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a TileSetManager object, reading the class name to
|
||||
* instantiate from the "miso.tilesetmgr" config value.
|
||||
*
|
||||
* @param config the Config object.
|
||||
* @param imgmgr the ImageManager object from which images are obtained.
|
||||
*
|
||||
* @return the new TileSetManager object or null if an error occurred.
|
||||
*/
|
||||
protected static TileSetManager
|
||||
createTileSetManager (Config config, ImageManager imgmgr)
|
||||
{
|
||||
TileSetManager tilesetmgr = null;
|
||||
TileSetManagerImpl tilesetmgr = null;
|
||||
try {
|
||||
tilesetmgr = (TileSetManager)
|
||||
tilesetmgr = (TileSetManagerImpl)
|
||||
config.instantiateValue("miso.tilesetmgr", DEF_TILESETMGR);
|
||||
tilesetmgr.init(imgmgr);
|
||||
tilesetmgr.init(config, imgmgr);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failed to instantiate tileset manager " +
|
||||
@@ -81,8 +115,11 @@ public class MisoUtil
|
||||
return tilesetmgr;
|
||||
}
|
||||
|
||||
protected static final String DEF_SCENEMGR =
|
||||
/** The default SceneManager class name. */
|
||||
protected static final String DEF_SCENEMGR =
|
||||
CompiledSceneManager.class.getName();
|
||||
|
||||
/** The default TileSetManager class name. */
|
||||
protected static final String DEF_TILESETMGR =
|
||||
EditableTileSetManager.class.getName();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user