/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csa.tiletools.tiles;

import csa.tiletools.map.Layer;
import csa.tiletools.map.MapPanel;
import csa.tiletools.map.TMap;
import java.awt.image.BufferedImage;

/**
 *
 * @author salchr
 */
public class CompositeTile extends Tile
{
    Layer mLayer = null;
    public Layer getLayer()
    {
        return mLayer;
    }
    
    TMap mMap = null;
    MapPanel mMapPanel = null;
    
    public CompositeTile()
    {
        super();
        data = new TileData();
        data.mIsCompositeTile = true;
        // init();
    }
    public CompositeTile(TileData d)
    {
        data = d;
        data.mIsCompositeTile = true;
        init();
    }
    @Override public boolean isShallowTile()
    {
        return false;
    }
    @Override public boolean isCompositeTile()
    {
        return true;
    }
    
    // loads layer
    // sets height, width
    // build tmap
    protected void init()
    {
        mLayer = Layer.loadAsCompositeTile(data.getCompositeFile(), data.getCompositeClass(), data.getCompositeName());
        
        mMap = new TMap(mLayer);
        maxWO = mMap.getMapWidth();
        maxHO = mMap.getMapHeight();
        mMapPanel= new MapPanel(mMap);
    }
    
    public BufferedImage getImage(int width,int height)
    {
        if (mMapPanel==null) return null;
        return mMapPanel.getScaleImage(width, height);
    }
    
    BufferedImage percentCache = null;
    int lastPercent = -1;
    public BufferedImage getImage(int percentScale)
    {
        if (mMapPanel==null) return null;
        if (lastPercent !=percentScale)
        {
            percentCache = null;
        }
        lastPercent=percentScale;
        if (percentCache == null)
        {
            mMapPanel.setScalingPercent(percentScale);
            percentCache = mMapPanel.getScaleImage(mMapPanel.scaleIt(maxWO), mMapPanel.scaleIt(maxHO));
        }
        
        return percentCache;
    }
    
    public int getCurrentOffsetX()
    {
        return 0;
    }

    public int getCurrentOffsetY()
    {
        return 0;
    }

    
}
