|
From: Geisschaes <gei...@us...> - 2005-07-19 17:59:09
|
Update of /cvsroot/macattrick/macattrick In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2071 Modified Files: MainController.m PlayerList.h PlayerList.m PlayerListsViewController.h PlayerListsViewController.m Properties.h Properties.m Team.m main.m Log Message: user defined lists are now saved in userDefinedPlayerLists.xml and loaded at startup Index: Properties.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/Properties.m,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Properties.m 30 May 2005 17:46:31 -0000 1.17 --- Properties.m 19 Jul 2005 17:58:57 -0000 1.18 *************** *** 63,66 **** --- 63,70 ---- } + +(NSString*) userDefinedPlayerListsFile { + NSString *path = [self libraryPath]; + return [path stringByAppendingString:@"/userDefinedPlayerLists.xml"]; + } +(NSString*) playersFile { NSString *path = [self libraryPath]; *************** *** 129,132 **** --- 133,137 ---- } + +(NSString*) file:(NSString*) file withPath: (NSString*)path { return [NSString stringWithFormat: @"%@/%@", path, file]; Index: main.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/main.m,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** main.m 27 Apr 2005 19:36:38 -0000 1.17 --- main.m 19 Jul 2005 17:58:57 -0000 1.18 *************** *** 32,36 **** #include <Security/Security.h> #include <CoreServices/CoreServices.h> ! int main(int argc, char *argv[]) --- 32,36 ---- #include <Security/Security.h> #include <CoreServices/CoreServices.h> ! #import "Team.h" int main(int argc, char *argv[]) *************** *** 45,48 **** return NSApplicationMain(argc, argv); - } --- 45,47 ---- Index: Properties.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/Properties.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Properties.h 29 May 2005 19:15:59 -0000 1.10 --- Properties.h 19 Jul 2005 17:58:57 -0000 1.11 *************** *** 45,49 **** */ +(NSString*) libraryPath; ! /*! @method currentEnvironmentPath --- 45,49 ---- */ +(NSString*) libraryPath; ! +(NSString*) userDefinedPlayerListsFile; /*! @method currentEnvironmentPath Index: PlayerList.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/PlayerList.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PlayerList.h 18 Jul 2005 19:12:37 -0000 1.10 --- PlayerList.h 19 Jul 2005 17:58:57 -0000 1.11 *************** *** 130,134 **** */ - (double) averageAge; ! - (BOOL) addPlayersWithIDs: (NSArray*) ids; - (BOOL) removePlayersWithIDs: (NSArray*) ids; --- 130,134 ---- */ - (double) averageAge; ! -(BOOL) addPlayerWithID: (int) aPlayerID; - (BOOL) addPlayersWithIDs: (NSArray*) ids; - (BOOL) removePlayersWithIDs: (NSArray*) ids; Index: MainController.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/MainController.m,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** MainController.m 12 Jun 2005 16:01:13 -0000 1.17 --- MainController.m 19 Jul 2005 17:58:57 -0000 1.18 *************** *** 72,75 **** --- 72,81 ---- } + + - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { + [[Team currentTeam] saveUserDefinedPlayerLists:[Properties userDefinedPlayerListsFile]]; + return 1; + } + - (IBAction) showPreferenceWindow:(id)sender { if(preferenceController == nil) { *************** *** 179,182 **** --- 185,189 ---- -(void) awakeFromNib { + [[NSApplication sharedApplication] setDelegate: self]; [self loadTransformers]; mainController = self; Index: PlayerListsViewController.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/PlayerListsViewController.m,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PlayerListsViewController.m 15 Jul 2005 18:29:31 -0000 1.2 --- PlayerListsViewController.m 19 Jul 2005 17:58:57 -0000 1.3 *************** *** 36,40 **** self = [super init]; if(self) { ! [self setPlayerLists: [[Team currentTeam] userDefinedPlayerLists]]; [NSBundle loadNibNamed:@"PlayerListsView" owner: self]; [tableView registerForDraggedTypes:[NSArray arrayWithObject:NSDragPboard]]; --- 36,40 ---- self = [super init]; if(self) { ! // [self setPlayerLists: [[Team currentTeam] userDefinedPlayerLists]]; [NSBundle loadNibNamed:@"PlayerListsView" owner: self]; [tableView registerForDraggedTypes:[NSArray arrayWithObject:NSDragPboard]]; *************** *** 51,59 **** } ! - (NSMutableArray *) playerLists { return playerLists; } - (void) setPlayerLists: (NSMutableArray *) newPlayerLists { ! [newPlayerLists retain]; ! [playerLists release]; ! playerLists = newPlayerLists; } --- 51,57 ---- } ! - (NSMutableArray *) playerLists { return [[Team currentTeam] userDefinedPlayerLists]; } - (void) setPlayerLists: (NSMutableArray *) newPlayerLists { ! [[Team currentTeam] setUserDefinedPlayerLists:newPlayerLists]; } *************** *** 82,86 **** - (BOOL)tableView:(NSTableView*)tv acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)op { NSArray *playerIDs = [[info draggingPasteboard] propertyListForType:NSDragPboard]; ! PlayerList *toDrop = [playerLists objectAtIndex:row]; [toDrop addPlayersWithIDs: playerIDs]; return YES; --- 80,84 ---- - (BOOL)tableView:(NSTableView*)tv acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)op { NSArray *playerIDs = [[info draggingPasteboard] propertyListForType:NSDragPboard]; ! PlayerList *toDrop = [[self playerLists] objectAtIndex:row]; [toDrop addPlayersWithIDs: playerIDs]; return YES; Index: PlayerList.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/PlayerList.m,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PlayerList.m 18 Jul 2005 19:12:37 -0000 1.12 --- PlayerList.m 19 Jul 2005 17:58:57 -0000 1.13 *************** *** 49,52 **** --- 49,61 ---- return self; } + -(PlayerList*) initWithListName:(NSString*) aListName { + self = [super init]; + if(self) { + playerList = [[NSMutableArray alloc] init]; + formerDates = [[NSMutableArray alloc] init]; + [self setListName:aListName]; + } + return self; + } - (PlayerList*) initFromLocalFile;{ NSURL *url = [[NSURL alloc] initFileURLWithPath: [Properties playersFile]]; *************** *** 142,145 **** --- 151,163 ---- } + -(BOOL) addPlayerWithID: (int) aPlayerID { + if([self playerWithID:aPlayerID] == nil) { + Player *p = [[[Team currentTeam] allPlayersList] playerWithID:aPlayerID]; + if(p) { + [playerList addObject:p] ; + } + } + + } - (BOOL) removePlayersWithIDs: (NSArray*) ids { PlayerList *mainList = [[Team currentTeam] allPlayersList]; Index: PlayerListsViewController.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/PlayerListsViewController.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PlayerListsViewController.h 3 Jul 2005 19:52:13 -0000 1.1 --- PlayerListsViewController.h 19 Jul 2005 17:58:57 -0000 1.2 *************** *** 30,34 **** @interface PlayerListsViewController : NSObject { ! NSMutableArray *playerLists; IBOutlet NSView *playerListsView; IBOutlet NSTableView *tableView; --- 30,34 ---- @interface PlayerListsViewController : NSObject { ! // NSMutableArray *playerLists; IBOutlet NSView *playerListsView; IBOutlet NSTableView *tableView; Index: Team.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/Team.m,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Team.m 19 Jul 2005 16:12:09 -0000 1.27 --- Team.m 19 Jul 2005 17:58:57 -0000 1.28 *************** *** 74,80 **** } [url release]; ! userDefinedPlayerLists = [[NSMutableArray alloc] init]; ! [userDefinedPlayerLists addObject: playerList]; ! [self setAllPlayersList:playerList]; } return self; --- 74,81 ---- } [url release]; ! ! [self setAllPlayersList:playerList]; ! [self loadUserDefinedPlayerLists: [Properties userDefinedPlayerListsFile]]; ! } return self; *************** *** 155,161 **** } - (BOOL) saveUserDefinedPlayerLists: (NSString*) filename { ! NSMutableDictionary *dic = [[NSMutableDictionary alloc] init]; NSEnumerator *en = [userDefinedPlayerLists objectEnumerator]; PlayerList *current = nil; --- 156,187 ---- } + - (BOOL) loadUserDefinedPlayerLists: (NSString*) filename { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSMutableArray *lists = [NSMutableArray array]; + [lists addObject:allPlayersList]; + if([[NSFileManager defaultManager] fileExistsAtPath:filename]) { + NSArray *savedLists = [NSArray arrayWithContentsOfFile:filename]; + NSEnumerator *en = [savedLists objectEnumerator]; + NSString *current = nil; + while(current = [en nextObject]) { + NSArray *items = [current componentsSeparatedByString:@"|"]; + NSEnumerator *en2 = [items objectEnumerator]; + NSString *currentID = [en2 nextObject]; + NSLog(currentID); + PlayerList *l = [[PlayerList alloc] initWithListName:currentID]; + while(currentID = [en2 nextObject]) { + [l addPlayerWithID:[currentID intValue]]; + } + [lists addObject:l]; + [l release]; + } + } + [self setUserDefinedPlayerLists:lists]; + [pool release]; + return YES; + } - (BOOL) saveUserDefinedPlayerLists: (NSString*) filename { ! NSMutableArray *array = [[NSMutableArray alloc] init]; NSEnumerator *en = [userDefinedPlayerLists objectEnumerator]; PlayerList *current = nil; *************** *** 163,174 **** while(current = [en nextObject]) { if(! (current == allPlayersList)) { ! NSString *ids = [current playerIDsAsString]; ! [dic setObject:ids forKey:[current listName]]; } } ! return ([dic writeToFile:filename atomically:YES] == 0); } - (Economy *) economy { return economy; } --- 189,202 ---- while(current = [en nextObject]) { if(! (current == allPlayersList)) { ! NSString *ids = [[NSString alloc] initWithFormat:@"%@|%@", [current listName], [current playerIDsAsString]]; ! [array addObject:ids]; ! [ids release]; } } ! return ([array writeToFile:filename atomically:YES] == 0); } + - (Economy *) economy { return economy; } |