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 wrap: on
line diff
--- a/API/Commands/CreateAndAddUnitCommand.cs	Sun Apr 15 20:52:32 2012 +0100
+++ b/API/Commands/CreateAndAddUnitCommand.cs	Mon Apr 16 20:14:23 2012 +0100
@@ -47,19 +47,20 @@
 		public override bool Execute()
 		{
 			addedUnit = new Unit(addedUnitType, armyCat);
-			addedUnit.ParentUnit = parentUnit;
-			this.Redo();
+			Redo();
 			return true;
 		}
 
 		public override void Redo()
 		{
+			addedUnit.ParentUnit = parentUnit;
 			armyCat.AddUnit(addedUnit);
 		}
 
 		public override void Undo()
 		{
 			armyCat.RemoveUnit(addedUnit);
+			addedUnit.ParentUnit = null;
 		}
 
 		public override string Name
--- a/API/Objects/Unit.cs	Sun Apr 15 20:52:32 2012 +0100
+++ b/API/Objects/Unit.cs	Mon Apr 16 20:14:23 2012 +0100
@@ -223,8 +223,13 @@
 			{
 				if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value))))
 				{
+					if (parentUnit != null)
+					{
+						parentUnit.RemoveContainedUnit(this);
+					}
+
 					parentUnit = value;
-					
+
 					if (value != null)
 					{
 						value.AddContainedUnit(this);