wyvern.lib.classes.construct
Class MagicMapper

java.lang.Object
  extended bywyvern.lib.classes.construct.MagicMapper

public final class MagicMapper
extends java.lang.Object

Knows how to take a GameMap and turn it into a scaled image. (gif, png, or jpeg format). Don't call it on the Kernel thread - it will just throw an exception, since we don't want the game to lock up while this is processing.

Version:
1.0, Oct 20, 2001
Author:
Steve Yegge

Field Summary
static int DEFAULT_TYPE
           
static int GIF
           
static int JPG
           
static int PNG
           
 
Constructor Summary
MagicMapper()
          Constructs a new MapRenderer
 
Method Summary
static java.awt.image.BufferedImage createBufferedImage(java.awt.Image image)
          Creates a buffered image from an image.
 java.awt.Image createImage(DenseMap map)
          Creates an Image of a dense map (using the entire bounds), at scale factor set by setScale()
 java.awt.Image createImage(GameMap map, Rectangle bounds)
          Creates an Image of any map, with the specified bounding rectangle.
 Predicate getDrawFilter()
          Returns the drawing filter to use, if one has been set.
 boolean getDrawInvisible()
          Returns true if we draw engine-invis objects.
 boolean getLighting()
          Returns true if we
 int getScale()
          Returns the current scale factor.
 boolean getTerrainBorders()
          Returns true if we draw terrain borders.
static void main(java.lang.String[] args)
          Tests the functions by choosing a map and creating an image from it.
 java.awt.Image mapToImage(GameMap map, Rectangle bounds)
          Does the work of creating the image.
 void setDrawFilter(Predicate p)
          Sets a Predicate that tells whether or not to draw each object in the map.
 void setDrawInvisible(boolean invis)
          Sets whether to draw invisible (-10) objects.
 void setImageType(int type)
          Sets an image type: MagicMapper.JPG, MagicMapper.PNG, etc.
 void setLighting(boolean lighting)
          Turns lighting model on and off.
 void setScale(int scale)
          Sets the scale factor for the map, for shrinking it.
 void setTerrainBorders(boolean borders)
          Sets whether to draw terrain borders.
 void writeGIF(java.awt.Image image, java.lang.String filename)
          Writes the specified image out as a GIF.
 void writeImage(java.awt.Image image, java.lang.String filename)
          Writes an image out in the default format.
 void writeJPG(java.awt.Image image, java.lang.String filename)
          Writes an Image to a jpeg file.
 void writePNG(java.awt.Image image, java.lang.String filename)
          Writes an Image to a PNG file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JPG

public static final int JPG
See Also:
Constant Field Values

GIF

public static final int GIF
See Also:
Constant Field Values

PNG

public static final int PNG
See Also:
Constant Field Values

DEFAULT_TYPE

public static final int DEFAULT_TYPE
See Also:
Constant Field Values
Constructor Detail

MagicMapper

public MagicMapper()
Constructs a new MapRenderer

Method Detail

setImageType

public void setImageType(int type)
Sets an image type: MagicMapper.JPG, MagicMapper.PNG, etc.


setScale

public void setScale(int scale)
Sets the scale factor for the map, for shrinking it.

Parameters:
scale - the scaling factor: 2 is 1/2 size, 4 is 1/4 size, and so on. Powers of 2 look the best.

getScale

public int getScale()
Returns the current scale factor.

Returns:
the scale factor

setTerrainBorders

public void setTerrainBorders(boolean borders)
Sets whether to draw terrain borders.

Parameters:
borders - true to draw terrain borders

getTerrainBorders

public boolean getTerrainBorders()
Returns true if we draw terrain borders.


setDrawInvisible

public void setDrawInvisible(boolean invis)
Sets whether to draw invisible (-10) objects.

Parameters:
invis - true to draw engine-invis objects.

getDrawInvisible

public boolean getDrawInvisible()
Returns true if we draw engine-invis objects.


setLighting

public void setLighting(boolean lighting)
Turns lighting model on and off.

Parameters:
lighting - true to draw in the lighting level in dark maps

getLighting

public boolean getLighting()
Returns true if we

Returns:
true if we draw in the lighting level in dark maps

setDrawFilter

public void setDrawFilter(Predicate p)
Sets a Predicate that tells whether or not to draw each object in the map.

Parameters:
p - a Predicate object that is passed each object in the map. The predicate should return true if you want the MagicMapper to draw the object into the output image.

getDrawFilter

public Predicate getDrawFilter()
Returns the drawing filter to use, if one has been set.


writeImage

public void writeImage(java.awt.Image image,
                       java.lang.String filename)
                throws java.lang.Exception
Writes an image out in the default format.

Parameters:
image - the Image to write
filename - absolute path, without extension (chooses an extension for you)
Throws:
java.lang.Exception

writeGIF

public void writeGIF(java.awt.Image image,
                     java.lang.String filename)
              throws java.lang.Exception
Writes the specified image out as a GIF.

Parameters:
image - the Image to write
filename - absolute path, including extension
Throws:
java.lang.Exception

writeJPG

public void writeJPG(java.awt.Image image,
                     java.lang.String filename)
              throws java.lang.Exception
Writes an Image to a jpeg file.

Parameters:
image - the Image to write
filename - absolute path, including extension
Throws:
java.lang.Exception

writePNG

public void writePNG(java.awt.Image image,
                     java.lang.String filename)
              throws java.lang.Exception
Writes an Image to a PNG file.

Parameters:
image - the Image to write
filename - absolute path, including extension
Throws:
java.lang.Exception

createImage

public java.awt.Image createImage(DenseMap map)
Creates an Image of a dense map (using the entire bounds), at scale factor set by setScale()


createImage

public java.awt.Image createImage(GameMap map,
                                  Rectangle bounds)
Creates an Image of any map, with the specified bounding rectangle.


mapToImage

public java.awt.Image mapToImage(GameMap map,
                                 Rectangle bounds)
Does the work of creating the image.

Parameters:
map - the map
bounds - the map bounds

createBufferedImage

public static java.awt.image.BufferedImage createBufferedImage(java.awt.Image image)
Creates a buffered image from an image.

Parameters:
image - any java.awt.Image or subclass
Returns:
a java.awt.image.BufferedImage containing the source image.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Tests the functions by choosing a map and creating an image from it.

Throws:
java.lang.Exception