Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Commands/CreateAndAddUnitCommand.cs @ 105:f5aec697b8ea
Re #53: Make WarFoundry XML saver
* Make XMLSaver implement Saver interface
* Strip out old code
* Start to code converting of objects to XML files
* Add class to store strings in to Zip files
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 17 Aug 2009 19:08:44 +0000 |
parents | 2f3cafb69799 |
children | b4d1ed685490 |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
1 // This file (CreateAndAddUnitCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
15 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
82 | 4 |
5 using System; | |
0 | 6 using IBBoard.Commands; |
7 using IBBoard.Lang; | |
82 | 8 using IBBoard.WarFoundry.API.Objects; |
9 | |
10 namespace IBBoard.WarFoundry.API.Commands | |
11 { | |
12 public class CreateAndAddUnitCommand : Command | |
13 { | |
14 private UnitType addedUnitType; | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
15 private ArmyCategory armyCat; |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
16 private Unit addedUnit; |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
17 |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
18 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo) |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
19 { |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
20 addedUnitType = toAdd; |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
21 armyCat = armyCatTo; |
82 | 22 } |
23 | |
24 [Obsolete("Use two parameter constructor instead")] | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
25 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, catTo) |
82 | 26 { |
27 } | |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
28 |
82 | 29 [Obsolete("Use two parameter constructor instead")] |
30 public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo) | |
31 { | |
32 } | |
33 | |
34 public override bool CanExecute() | |
35 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
36 return (addedUnitType!=null && armyCat!=null); |
82 | 37 } |
38 | |
39 public override string Description | |
40 { | |
41 get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; } | |
42 } | |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
43 |
82 | 44 public override string UndoDescription |
45 { | |
46 get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; } | |
47 } | |
48 | |
49 public override bool Execute() | |
50 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
51 addedUnit = new Unit(addedUnitType, armyCat); |
82 | 52 this.Redo(); |
53 return true; | |
54 } | |
55 | |
56 public override void Redo() | |
57 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
58 armyCat.AddUnit(addedUnit); |
82 | 59 } |
60 | |
61 public override void Undo() | |
89 | 62 { |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
63 armyCat.RemoveUnit(addedUnit); |
82 | 64 } |
65 | |
66 | |
67 public override string Name | |
68 { | |
69 get { return "Add new unit"; } | |
70 } | |
71 } | |
72 } |