Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Commands/CreateAndAddUnitCommand.cs @ 232:f5009a00a50d
Re #236: Handle null game system in race
* Fix error message text
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 24 Dec 2009 14:57:32 +0000 |
parents | 391446c9b250 |
children | 650bbe79b884 |
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; |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
17 private string description; |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
18 private string undoDescription; |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
19 |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
20 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
|
21 { |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
22 addedUnitType = toAdd; |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
23 armyCat = armyCatTo; |
82 | 24 } |
25 | |
26 public override bool CanExecute() | |
27 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
28 return (addedUnitType!=null && armyCat!=null); |
82 | 29 } |
30 | |
31 public override string Description | |
32 { | |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
33 get |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
34 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
35 if (description == null) |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
36 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
37 description = Translation.GetTranslation("createAndAddUnitCommandDescription", "add unit of {0} to the army", addedUnitType.Name); |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
38 } |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
39 |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
40 return description; |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
41 } |
82 | 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 { | |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
46 get |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
47 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
48 if (undoDescription == null) |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
49 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
50 undoDescription = Translation.GetTranslation("createAndAddUnitCommandUndoDescription", "remove unit of {0} from army", addedUnitType.Name); |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
51 } |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
52 |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
53 return undoDescription; |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
54 } |
82 | 55 } |
56 | |
57 public override bool Execute() | |
58 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
59 addedUnit = new Unit(addedUnitType, armyCat); |
82 | 60 this.Redo(); |
61 return true; | |
62 } | |
63 | |
64 public override void Redo() | |
65 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
66 armyCat.AddUnit(addedUnit); |
82 | 67 } |
68 | |
69 public override void Undo() | |
89 | 70 { |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
71 armyCat.RemoveUnit(addedUnit); |
82 | 72 } |
73 | |
74 public override string Name | |
75 { | |
76 get { return "Add new unit"; } | |
145 | 77 } |
78 | |
79 public Unit Unit | |
80 { | |
81 get { return addedUnit; } | |
82 | 82 } |
83 } | |
84 } |