/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package moe.nekojimi.charactermaker.steps;

import java.lang.reflect.InvocationTargetException;
import moe.nekojimi.charactermaker.Main;
import org.apache.commons.beanutils.PropertyUtils;


public class ChangePropertyStep extends ChangeValueStep
{

	private final String propName;

	public ChangePropertyStep(int change, String name, String propName)
	{
		super(change, name);
		this.propName = propName;
	}

	@Override
	protected int read()
	{
		try
		{
			return (int) PropertyUtils.getSimpleProperty(Main.character, propName);
		} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex)
		{
//			Logger.getLogger(ChangePropertyStep.class.getName()).log(Level.SEVERE, null, ex);
			throw new RuntimeException(ex);
		}
	}

	@Override
	protected void write(int val)
	{
		try
		{
			PropertyUtils.setSimpleProperty(Main.character, propName, val);
		} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex)
		{
//			Logger.getLogger(ChangePropertyStep.class.getName()).log(Level.SEVERE, null, ex);
			throw new RuntimeException(ex);
		}
	}

}