Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Commands/CreateAndAddUnitCommand.cs @ 471:0a2068897793
Re #359: Add "only contained" attribute to unit types
* Add "main units" methods to get only top-level units
* Add nesting to unit creation command
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 15 Apr 2012 20:52:32 +0100 |
parents | 3c4a6403a88c |
children | e6c93ceba119 |
comparison
equal
deleted
inserted
replaced
470:426b8c5e283c | 471:0a2068897793 |
---|---|
12 public class CreateAndAddUnitCommand : Command | 12 public class CreateAndAddUnitCommand : Command |
13 { | 13 { |
14 private UnitType addedUnitType; | 14 private UnitType addedUnitType; |
15 private ArmyCategory armyCat; | 15 private ArmyCategory armyCat; |
16 private Unit addedUnit; | 16 private Unit addedUnit; |
17 private Unit parentUnit; | |
17 | 18 |
18 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo) | 19 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo, Unit parentUnit = null) |
19 { | 20 { |
20 addedUnitType = toAdd; | 21 addedUnitType = toAdd; |
21 armyCat = armyCatTo; | 22 armyCat = armyCatTo; |
23 this.parentUnit = parentUnit; | |
22 } | 24 } |
23 | 25 |
24 public override bool CanExecute() | 26 public override bool CanExecute() |
25 { | 27 { |
26 return (addedUnitType != null && armyCat != null); | 28 return (addedUnitType != null && armyCat != null); |
43 } | 45 } |
44 | 46 |
45 public override bool Execute() | 47 public override bool Execute() |
46 { | 48 { |
47 addedUnit = new Unit(addedUnitType, armyCat); | 49 addedUnit = new Unit(addedUnitType, armyCat); |
50 addedUnit.ParentUnit = parentUnit; | |
48 this.Redo(); | 51 this.Redo(); |
49 return true; | 52 return true; |
50 } | 53 } |
51 | 54 |
52 public override void Redo() | 55 public override void Redo() |