88 |
* Add a player to the team. |
* Add a player to the team. |
89 |
* The player must exist and mustn't be already in the team |
* The player must exist and mustn't be already in the team |
90 |
* already contains the player. |
* already contains the player. |
91 |
* Post an notification named "updateTeam" containing the current object. |
* Post an notification named "updateTeam" containing the current game and |
92 |
|
* the current object. |
93 |
*/ |
*/ |
94 |
- (void) addPlayer: (HgPlayer *)player |
- (void) addPlayer: (HgPlayer *)player |
95 |
{ |
{ |
99 |
|
|
100 |
[_players addObject: player]; |
[_players addObject: player]; |
101 |
|
|
102 |
[[NSNotificationCenter defaultCenter] |
[[NSNotificationCenter defaultCenter] postNotificationName: @"updateTeam" |
103 |
postNotificationName:@"updateTeam" object:self]; |
object: _game |
104 |
|
userInfo: [NSDictionary dictionaryWithObject: self |
105 |
|
forKey: @"HgTeam"]]; |
106 |
} |
} |
107 |
|
|
108 |
/** |
/** |
109 |
* Remove a player to the team. |
* Remove a player to the team. |
110 |
* The player must be in the team. |
* The player must be in the team. |
111 |
* Post an notification named "updateTeam" containing the current object. |
* Post an notification named "updateTeam" containing the current game and |
112 |
|
* the current object. |
113 |
*/ |
*/ |
114 |
- (void) removePlayer: (HgPlayer *)player |
- (void) removePlayer: (HgPlayer *)player |
115 |
{ |
{ |
118 |
|
|
119 |
[_players removeObject: player]; |
[_players removeObject: player]; |
120 |
|
|
121 |
[[NSNotificationCenter defaultCenter] |
[[NSNotificationCenter defaultCenter] postNotificationName: @"updateTeam" |
122 |
postNotificationName:@"updateTeam" object:self]; |
object: _game |
123 |
|
userInfo: [NSDictionary dictionaryWithObject: self |
124 |
|
forKey: @"HgTeam"]]; |
125 |
} |
} |
126 |
|
|
127 |
/** |
/** |
133 |
} |
} |
134 |
|
|
135 |
|
|
136 |
|
@end |
137 |
|
|
138 |
|
@implementation HgTeam (NSCoding) |
139 |
|
|
140 |
/** |
/** |
141 |
* encode the HgTeam object to send it across the network |
* NSCoding method to encode and decode objects |
142 |
*/ |
*/ |
143 |
- (void)encodeWithCoder: (NSCoder *)encoder |
- (void)encodeWithCoder: (NSCoder *)encoder |
144 |
{ |
{ |
148 |
[encoder encodeObject: _players]; |
[encoder encodeObject: _players]; |
149 |
} |
} |
150 |
|
|
|
/** |
|
|
* decode the HgTeam object to read it |
|
|
*/ |
|
151 |
- (id)initWithCoder: (NSCoder *)decoder |
- (id)initWithCoder: (NSCoder *)decoder |
152 |
{ |
{ |
153 |
[decoder decodeValueOfObjCType: "I" at: &_identifier]; |
[decoder decodeValueOfObjCType: "I" at: &_identifier]; |
154 |
NSNumber *numIdent = [NSNumber numberWithInt: _identifier]; |
NSNumber *numIdent = [NSNumber numberWithInt: _identifier]; |
155 |
|
|
156 |
HgTeam *teamObject = [[_game teams] objectForKey: numIdent]; |
HgGame *currentGame = [HgGame currentGame]; |
157 |
|
HgTeam *teamObject = [[currentGame teams] objectForKey: numIdent]; |
158 |
|
|
159 |
if (teamObject != nil) |
if (teamObject != nil) |
160 |
{ |
{ |