/*
Tiamat - a role-playing game framework
Map.java - Abstract map
 
 Copyright  (C) 2004-2005 Hugues Johnson
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package com.huguesjohnson.tiamat.graphics;

import com.huguesjohnson.serialization.Formatter;
import com.huguesjohnson.serialization.Storable;
import java.awt.Component;
import java.io.File;

/** class Map - abstract map
 * @author Hugues Johnson
 */
public abstract class Map extends Object implements Drawable,Storable{

/* begin public properties */
    //the height of the map
    protected int height;
    /** Returns the height of the Map.
     * @return The height of the Map.
     */
    public int getHeight(){ return(this.height); }
    /** Sets the height of the Map.
     * @param height The new height of the Map.
     */
    public void setHeight(int height){ this.height=height; }
    //the width of the map
    protected int width;
    /** Returns the width of the Map.
     * @return The width of the Map.
     */
    public int getWidth(){ return(this.width); }
    /** Sets the width of the Map.
     * @param width The new width of the Map.
     */
    public void setWidth(int width){ this.width=width; }
    //name of the map
    protected String name;
    /** Returns the name of the Map.
     * @return The name of the Map.
     */
    public String getName(){ return(this.name); }
    /** Sets the name of the Map.
     * @param name The new name of the Map.
     */
    public void setName(String name){ this.name=name; }
    //where to draw stuff
    private transient Component canvas;
    /** Returns the canvas for this Map.
     * @return The canvas for this Map.
     */
    public Component getCanvas(){ return(this.canvas); }
    /** Sets the canvas for this Map.
     * @param canvas The new canvas for this Map.
     */
    public void setCanvas(Component canvas){ this.canvas=canvas; }
    //absolute path to the directory where the images are saved
    protected transient String absoluteDir;
    public void setAbsoluteDir(String absoluteDir){
        if(absoluteDir.endsWith(File.separator)){
            this.absoluteDir=absoluteDir;
        } else{
            this.absoluteDir=absoluteDir+File.separator;
        }
    }    
/* end public properties */
    
/* begin constructors */    
    /** Default constructor, creates an empty Map.
     */
    public Map(){ }
/* end constructors */    
    
/* begin public methods */    
    /** Returns a string representation of the object. 
     * @return A string representation of the object.
     */
    public String toString(){
        StringBuffer tostring=new StringBuffer(this.getClass().getName());
        tostring.append("\n  name="+this.name);
        tostring.append("\n  width="+this.width);
        tostring.append("\n  height="+this.height);
        return(tostring.toString());
    }
    /** 
     * Draws the entire map. 
     */
    public abstract void draw();
    /** 
     * Draws the entire map at location specified by (x,y). 
     * @param x The x co-ordinate.
     * @param y The y co-ordinate.
     */
    public abstract void draw(int x,int y);
    /** 
     * Draws the map within the boundaries specified by (x1,y1) and (x2,y2). 
     * @param x1 The x co-ordinate to start at.
     * @param y1 The y co-ordinate to start at.
     * @param x2 The x co-ordinate to end at.
     * @param y2 The y co-ordinate to end at.
     */
    public abstract void draw(int x1,int y1,int x2,int y2);
    /** The onDeserialize event should be fired after an object is de-serialized.
     * @param formatter The formatter to use to load any storable members.
     * @param absoluteDir The working directory to use since all paths stored in the object should be relative.
     */
    public abstract void onDeserialize(Formatter formatter,String absoluteDir);    
/* end public methods */    
}