annotate api/Commands/SetUnitSizeCommand.cs @ 263:7933d852181e

Re #289: Double-check extensibility where sets of values are allowed * Remove ArmourType and all usage as it needs rebuilding from scratch to be extensible and isn't widely used yet
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Jun 2010 12:43:28 +0000
parents 391446c9b250
children 650bbe79b884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1 // This file (SetUnitSizeCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
2 //
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 82
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
4
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
5 using System;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.Commands;
215
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
7 using IBBoard.Lang;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
8 using IBBoard.WarFoundry.API.Objects;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
9
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
10 namespace IBBoard.WarFoundry.API.Commands
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
11 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
12 /// <summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
13 /// Summary description for SetNameCommand.
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
14 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
15 public class SetUnitSizeCommand : Command
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
16 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
17 private Unit unit;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
18 private int newSize, oldSize;
215
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
19 private string description;
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
20 private string undoDescription;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
21
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
22 public SetUnitSizeCommand(Unit toResize, int size)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
23 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
24 unit = toResize;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
25 newSize = size;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
26 oldSize = unit.Size;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
27 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
28
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
29 public override bool CanExecute()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
30 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
31 return (unit!=null && newSize >0 && oldSize > 0);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
32 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
33
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
34 public override string Description
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
35 {
215
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
36 get
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
37 {
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
38 if (description == null)
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
39 {
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
40 description = Translation.GetTranslation("setUnitSizeCommandDescription", "set size of {0} to {1}", unit.Name, newSize);
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
41 }
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
42
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
43 return description;
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
44 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
45 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
46
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
47 public override string UndoDescription
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
48 {
215
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
49 get
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
50 {
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
51 if (undoDescription == null)
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
52 {
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
53 undoDescription = Translation.GetTranslation("setUnitSizeCommandUndoDescription", "set size of {0} to {1}", unit.Name, oldSize);
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
54 }
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
55
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
56 return undoDescription;
391446c9b250 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
57 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
58 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
59
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
60 public override bool Execute()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
61 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
62 this.Redo();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
63 return true;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
64 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
65
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
66 public override void Redo()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
67 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
68 unit.Size = newSize;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
69 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
70
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
71 public override void Undo()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
72 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
73 unit.Size = oldSize;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
74 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
75
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
76 public override string Name
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
77 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
78 get { return "Change unit size"; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
79 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
80 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
81 }