changeset 472:e6c93ceba119

Re #359: Add "only contained" attribute to unit types * Make sure we add and remove from the parent unit appropriately * Make sure that setting the unit's parent to null removes it from the parent
author IBBoard <dev@ibboard.co.uk>
date Mon, 16 Apr 2012 20:14:23 +0100
parents 0a2068897793
children 0d032c04210e
files API/Commands/CreateAndAddUnitCommand.cs API/Objects/Unit.cs
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/API/Commands/CreateAndAddUnitCommand.cs	Sun Apr 15 20:52:32 2012 +0100
     1.2 +++ b/API/Commands/CreateAndAddUnitCommand.cs	Mon Apr 16 20:14:23 2012 +0100
     1.3 @@ -47,19 +47,20 @@
     1.4  		public override bool Execute()
     1.5  		{
     1.6  			addedUnit = new Unit(addedUnitType, armyCat);
     1.7 -			addedUnit.ParentUnit = parentUnit;
     1.8 -			this.Redo();
     1.9 +			Redo();
    1.10  			return true;
    1.11  		}
    1.12  
    1.13  		public override void Redo()
    1.14  		{
    1.15 +			addedUnit.ParentUnit = parentUnit;
    1.16  			armyCat.AddUnit(addedUnit);
    1.17  		}
    1.18  
    1.19  		public override void Undo()
    1.20  		{
    1.21  			armyCat.RemoveUnit(addedUnit);
    1.22 +			addedUnit.ParentUnit = null;
    1.23  		}
    1.24  
    1.25  		public override string Name
     2.1 --- a/API/Objects/Unit.cs	Sun Apr 15 20:52:32 2012 +0100
     2.2 +++ b/API/Objects/Unit.cs	Mon Apr 16 20:14:23 2012 +0100
     2.3 @@ -223,8 +223,13 @@
     2.4  			{
     2.5  				if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value))))
     2.6  				{
     2.7 +					if (parentUnit != null)
     2.8 +					{
     2.9 +						parentUnit.RemoveContainedUnit(this);
    2.10 +					}
    2.11 +
    2.12  					parentUnit = value;
    2.13 -					
    2.14 +
    2.15  					if (value != null)
    2.16  					{
    2.17  						value.AddContainedUnit(this);