Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Objects/WarFoundryObject.cs @ 252:a54da5a8b5bb
Re #268: Restructure stats for re-use
* Add "Member Type" class
* Add member type setting and getting to Race
* Load member types from XML files
* Make unit type pull stat line from stats or first member type, or fall back to a blank stat line
* Change Stats object to initialise blank values
* Change schema
* Make stats optional
* Add member type list to race
* Add optional member type references to units
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 25 Apr 2010 15:07:08 +0000 |
parents | f58051572ec7 |
children |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
1 // This file (WarFoundryObject.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:
91
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. |
15 | 4 |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
5 using System; |
82 | 6 using IBBoard.WarFoundry.API.Factories; |
7 | |
8 namespace IBBoard.WarFoundry.API.Objects | |
9 { | |
10 /// <summary> | |
11 /// Summary description for WarFoundryObject. | |
12 /// </summary> | |
13 public abstract class WarFoundryObject : IWarFoundryObject | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
14 { |
82 | 15 protected string id; |
16 protected string name; | |
0 | 17 public event StringValChangedDelegate NameChanged; |
18 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
19 protected WarFoundryObject() |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
20 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
21 } |
0 | 22 |
23 protected WarFoundryObject(string objName) : this() | |
24 { | |
25 Name = objName; | |
26 } | |
27 | |
28 protected WarFoundryObject(string objId, string objName) : this(objName) | |
29 { | |
30 ID = objId; | |
82 | 31 } |
32 | |
33 public virtual string ID | |
34 { | |
0 | 35 get |
36 { | |
124
d59aa4e46761
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
37 if (id == null || id == "") |
0 | 38 { |
39 id = GenerateID(); | |
40 } | |
41 | |
42 return id; | |
43 } | |
82 | 44 |
124
d59aa4e46761
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
45 set |
d59aa4e46761
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
46 { |
d59aa4e46761
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
47 string newId = (value == null ? "" : value.Trim()); |
d59aa4e46761
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
48 id = (newId == "" ? GenerateID() : newId); |
d59aa4e46761
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
49 } |
82 | 50 } |
51 | |
52 public virtual string Name | |
53 { | |
54 get | |
55 { | |
56 if (HasDefaultName()) | |
57 { | |
58 return DefaultName(); | |
59 } | |
60 else | |
61 { | |
62 return name; | |
63 } | |
64 } | |
65 set | |
66 { | |
67 string oldValue = name; | |
68 name = value; | |
69 | |
70 if (name!=oldValue) | |
71 { | |
72 OnNameChanged(oldValue, name); | |
73 } | |
74 } | |
75 } | |
76 | |
137
f58051572ec7
Fixes #128: Don't save out default names
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
77 public bool HasDefaultName() |
82 | 78 { |
79 return (name == null || name == ""); | |
80 } | |
81 | |
82 protected void OnNameChanged(string oldValue, string newValue) | |
83 { | |
84 if (NameChanged!=null) | |
85 { | |
86 NameChanged(this, oldValue, newValue); | |
87 } | |
88 } | |
89 | |
90 protected virtual string DefaultName() | |
91 { | |
92 return "-"; | |
93 } | |
94 | |
95 protected string GenerateID() | |
96 { | |
91
571d8ddc7d9a
Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
97 return Name + UnixTimestamp.GetTimestamp(DateTime.Now) + "." + DateTime.Now.Millisecond; |
82 | 98 } |
99 } | |
100 } |