package csa.tiletools.particle;

import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
import java.util.*;
public class  ParticleDataXMLHandler extends DefaultHandler
{
	private HashMap<String, ParticleData> mParticleData;
	private ParticleData mCurrentData = null;
	private String mCurrentElement = null;
	private String mGenerateEachTick = "";
	private String mFade = "";
	private String mRotate = "";
	private String mEmitterName = "";
	private String mEmitterID = "";
	private String mPositionX = "";
	private String mPositionY = "";
	private String mWidth = "";
	private String mHeight = "";
	private String mLife = "";
	private String mLifeReduce = "";
	private String mEmitPositionX = "";
	private String mEmitPositionY = "";
	private String mEmitPositionXRandom = "";
	private String mEmitPositionYRandom = "";
	private String mUseTint = "";
	private String mstartColor = "";
	private String mendColor = "";
	private String mcolorAdditive = "";
	private String mParticleImageName = "";
	private String mParticleEmitterName = "";
	private String mStartVelocity1 = "";
	private String mStartVelocity2 = "";
	private String mStartAngle1 = "";
	private String mAccelerationX = "";
	private String mAccelerationY = "";
	private String mtangentialAcceleration = "";
	private String mradialAcceleration = "";
	private String mStartAngle2 = "";
	public HashMap<String, ParticleData> getLastHashMap()
	{
		return mParticleData;
	}
	@Override public void startDocument() throws SAXException
	{
		mCurrentData = new ParticleData();
		mParticleData = new HashMap<String, ParticleData>();
	}
	@Override public void endDocument () throws SAXException
	{
	}
	@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
	{
		mCurrentElement = qName;
		if (qName.equalsIgnoreCase("ParticleData"))
		{
			mCurrentData = new ParticleData();
			mGenerateEachTick = "";
			mFade = "";
			mRotate = "";
			mEmitterName = "";
			mEmitterID = "";
			mPositionX = "";
			mPositionY = "";
			mWidth = "";
			mHeight = "";
			mLife = "";
			mLifeReduce = "";
			mEmitPositionX = "";
			mEmitPositionY = "";
			mEmitPositionXRandom = "";
			mEmitPositionYRandom = "";
			mUseTint = "";
			mstartColor = "";
			mendColor = "";
			mcolorAdditive = "";
			mParticleImageName = "";
			mParticleEmitterName = "";
			mStartVelocity1 = "";
			mStartVelocity2 = "";
			mStartAngle1 = "";
			mAccelerationX = "";
			mAccelerationY = "";
			mtangentialAcceleration = "";
			mradialAcceleration = "";
			mStartAngle2 = "";
		}
	}
	@Override public void characters(char[] ch, int start, int length)
	{
		String s = new String( ch, start, length );
		if (mCurrentElement == null) return;
		if (mCurrentElement.equalsIgnoreCase("Class")) mCurrentData.mClass += s;
		if (mCurrentElement.equalsIgnoreCase("Name")) mCurrentData.mName += s;
		if (mCurrentElement.equalsIgnoreCase("GenerateEachTick")) mGenerateEachTick += s;
		if (mCurrentElement.equalsIgnoreCase("Fade")) mFade += s;
		if (mCurrentElement.equalsIgnoreCase("Rotate")) mRotate += s;
		if (mCurrentElement.equalsIgnoreCase("EmitterName")) mEmitterName += s;
		if (mCurrentElement.equalsIgnoreCase("EmitterID")) mEmitterID += s;
		if (mCurrentElement.equalsIgnoreCase("PositionX")) mPositionX += s;
		if (mCurrentElement.equalsIgnoreCase("PositionY")) mPositionY += s;
		if (mCurrentElement.equalsIgnoreCase("Width")) mWidth += s;
		if (mCurrentElement.equalsIgnoreCase("Height")) mHeight += s;
		if (mCurrentElement.equalsIgnoreCase("Life")) mLife += s;
		if (mCurrentElement.equalsIgnoreCase("LifeReduce")) mLifeReduce += s;
		if (mCurrentElement.equalsIgnoreCase("EmitPositionX")) mEmitPositionX += s;
		if (mCurrentElement.equalsIgnoreCase("EmitPositionY")) mEmitPositionY += s;
		if (mCurrentElement.equalsIgnoreCase("EmitPositionXRandom")) mEmitPositionXRandom += s;
		if (mCurrentElement.equalsIgnoreCase("EmitPositionYRandom")) mEmitPositionYRandom += s;
		if (mCurrentElement.equalsIgnoreCase("UseTint")) mUseTint += s;
		if (mCurrentElement.equalsIgnoreCase("startColor")) mstartColor += s;
		if (mCurrentElement.equalsIgnoreCase("endColor")) mendColor += s;
		if (mCurrentElement.equalsIgnoreCase("colorAdditive")) mcolorAdditive += s;
		if (mCurrentElement.equalsIgnoreCase("ParticleImageName")) mParticleImageName += s;
		if (mCurrentElement.equalsIgnoreCase("ParticleEmitterName")) mParticleEmitterName += s;
		if (mCurrentElement.equalsIgnoreCase("StartVelocity1")) mStartVelocity1 += s;
		if (mCurrentElement.equalsIgnoreCase("StartVelocity2")) mStartVelocity2 += s;
		if (mCurrentElement.equalsIgnoreCase("StartAngle1")) mStartAngle1 += s;
		if (mCurrentElement.equalsIgnoreCase("AccelerationX")) mAccelerationX += s;
		if (mCurrentElement.equalsIgnoreCase("AccelerationY")) mAccelerationY += s;
		if (mCurrentElement.equalsIgnoreCase("tangentialAcceleration")) mtangentialAcceleration += s;
		if (mCurrentElement.equalsIgnoreCase("radialAcceleration")) mradialAcceleration += s;
		if (mCurrentElement.equalsIgnoreCase("StartAngle2")) mStartAngle2 += s;
	}
	@Override public void endElement(String uri, String localName, String qName) throws SAXException
	{
		if ("ParticleData".equalsIgnoreCase(qName))
		{
			if (mCurrentData != null)
			{
				try{
				mCurrentData.mGenerateEachTick = Integer.parseInt(mGenerateEachTick);
				}catch (Throwable e){}
				mGenerateEachTick = "";
				try{
				mCurrentData.mFade = Float.parseFloat(mFade);
				}catch (Throwable e){}
				mFade = "";
				try{
				mCurrentData.mRotate = Float.parseFloat(mRotate);
				}catch (Throwable e){}
				mRotate = "";
				mCurrentData.mEmitterName = mEmitterName;
				mEmitterName = "";
				try{
				mCurrentData.mEmitterID = Integer.parseInt(mEmitterID);
				}catch (Throwable e){}
				mEmitterID = "";
				try{
				mCurrentData.mPositionX = Integer.parseInt(mPositionX);
				}catch (Throwable e){}
				mPositionX = "";
				try{
				mCurrentData.mPositionY = Integer.parseInt(mPositionY);
				}catch (Throwable e){}
				mPositionY = "";
				try{
				mCurrentData.mWidth = Integer.parseInt(mWidth);
				}catch (Throwable e){}
				mWidth = "";
				try{
				mCurrentData.mHeight = Integer.parseInt(mHeight);
				}catch (Throwable e){}
				mHeight = "";
				try{
				mCurrentData.mLife = Integer.parseInt(mLife);
				}catch (Throwable e){}
				mLife = "";
				try{
				mCurrentData.mLifeReduce = Float.parseFloat(mLifeReduce);
				}catch (Throwable e){}
				mLifeReduce = "";
				try{
				mCurrentData.mEmitPositionX = Integer.parseInt(mEmitPositionX);
				}catch (Throwable e){}
				mEmitPositionX = "";
				try{
				mCurrentData.mEmitPositionY = Integer.parseInt(mEmitPositionY);
				}catch (Throwable e){}
				mEmitPositionY = "";
				try{
				mCurrentData.mEmitPositionXRandom = Boolean.parseBoolean(mEmitPositionXRandom);
				}catch (Throwable e){}
				mEmitPositionXRandom = "";
				try{
				mCurrentData.mEmitPositionYRandom = Boolean.parseBoolean(mEmitPositionYRandom);
				}catch (Throwable e){}
				mEmitPositionYRandom = "";
				try{
				mCurrentData.mUseTint = Boolean.parseBoolean(mUseTint);
				}catch (Throwable e){}
				mUseTint = "";
				try{
				mCurrentData.mstartColor = Integer.parseInt(mstartColor);
				}catch (Throwable e){}
				mstartColor = "";
				try{
				mCurrentData.mendColor = Integer.parseInt(mendColor);
				}catch (Throwable e){}
				mendColor = "";
				try{
				mCurrentData.mcolorAdditive = Boolean.parseBoolean(mcolorAdditive);
				}catch (Throwable e){}
				mcolorAdditive = "";
				mCurrentData.mParticleImageName = mParticleImageName;
				mParticleImageName = "";
				mCurrentData.mParticleEmitterName = mParticleEmitterName;
				mParticleEmitterName = "";
				try{
				mCurrentData.mStartVelocity1 = Float.parseFloat(mStartVelocity1);
				}catch (Throwable e){}
				mStartVelocity1 = "";
				try{
				mCurrentData.mStartVelocity2 = Float.parseFloat(mStartVelocity2);
				}catch (Throwable e){}
				mStartVelocity2 = "";
				try{
				mCurrentData.mStartAngle1 = Integer.parseInt(mStartAngle1);
				}catch (Throwable e){}
				mStartAngle1 = "";
				try{
				mCurrentData.mAccelerationX = Float.parseFloat(mAccelerationX);
				}catch (Throwable e){}
				mAccelerationX = "";
				try{
				mCurrentData.mAccelerationY = Float.parseFloat(mAccelerationY);
				}catch (Throwable e){}
				mAccelerationY = "";
				try{
				mCurrentData.mtangentialAcceleration = Float.parseFloat(mtangentialAcceleration);
				}catch (Throwable e){}
				mtangentialAcceleration = "";
				try{
				mCurrentData.mradialAcceleration = Float.parseFloat(mradialAcceleration);
				}catch (Throwable e){}
				mradialAcceleration = "";
				try{
				mCurrentData.mStartAngle2 = Integer.parseInt(mStartAngle2);
				}catch (Throwable e){}
				mStartAngle2 = "";
				mParticleData.put(mCurrentData.mName, mCurrentData);
				mCurrentData = null;
			}
		}
		mCurrentElement = null;
	}
}
