/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package csa.tiletools.sprites;

import csa.tiletools.tiles.*;
import java.util.Vector;

/**
 *
 * @author malban
 */
public class SpriteAttribute 
{
    public static final String INT = "Integer";
    public static final String BOOL = "Boolean";
    public static final String STRING = "String";
    public String name="";
    public String type = "";
    boolean boolValue = false;
    public String stringValue = "";
    public int intValue = 0;
    
    @Override public String toString()
    {
        return "("+type+")"+name+":"+sVal();
    }
        
    public String sVal()
    {
        if (type.equals(INT)) return ""+intValue;
        if (type.equals(BOOL)) return ""+boolValue;
        return stringValue;
    }

    void setSVal(String s, String t)
    {
        if (t.equals(INT))
        {
            int I = 0;
            try
            {
                I = Integer.parseInt(s);
            }
            catch (Throwable e){}
            intValue = I;
        }
        else if (t.equals(BOOL))
        {
            boolean b = false;
            try
            {
                b = Boolean.parseBoolean(s);
            }
            catch (Throwable e){}
            boolValue = b;
        }
        else
        {
            stringValue = s;
        }
    }

    public static void fillSprite(Vector <SpriteAttribute> data, SpriteData tdata)
    {
        tdata.mAtrributeName = new Vector<String>();
        tdata.mAttributeType = new Vector<String>();
        tdata.mAttributeValue = new Vector<String>();
        for (int i = 0; i < data.size(); i++) 
        {
            SpriteAttribute tileAttribute = data.elementAt(i);
            tdata.mAtrributeName.addElement(tileAttribute.name);
            tdata.mAttributeType.addElement(tileAttribute.type);
            tdata.mAttributeValue.addElement(tileAttribute.sVal());
        }
    }

    public static Vector <SpriteAttribute> getVector(SpriteData tdata)
    {
        Vector <SpriteAttribute> data  = new Vector<SpriteAttribute>();

        for (int i = 0; i < tdata.mAtrributeName.size(); i++)
        {
            SpriteAttribute d = new SpriteAttribute();

            d.name = tdata.mAtrributeName.elementAt(i);
            d.type = tdata.mAttributeType.elementAt(i);
            d.setSVal(tdata.mAttributeValue.elementAt(i),  d.type);
            data.add(d);
        }
        return data;
    }
    
}
