view api/Commands/SetUnitSizeCommand.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 306558904c2a
line wrap: on
line source

using System;
using IBBoard.Commands;
using IBBoard.WarFoundry.API.Objects;

namespace IBBoard.WarFoundry.API.Commands
{
	/// <summary>
	/// Summary description for SetNameCommand.
	/// </summary>
	public class SetUnitSizeCommand : Command
	{
		private Unit unit;
		private int newSize, oldSize;

		public SetUnitSizeCommand(Unit toResize, int size)
		{
			unit = toResize;
			newSize = size;
			oldSize = unit.Size;
		}

		public override bool CanExecute()
		{
			return (unit!=null && newSize >0 && oldSize > 0);
		}

		public override string Description
		{
			get { return "Change size of "+unit.Name; }
		}

		public override string UndoDescription
		{
			get { return "Revert size of "+unit.Name; }
		}

		public override bool Execute()
		{
			this.Redo();
			return true;
		}

		public override void Redo()
		{
			unit.Size = newSize;
		}

		public override void Undo()
		{
			unit.Size = oldSize;
		}

		public override string Name
		{
			get { return "Change unit size"; }
		}
	}
}