|
From: Geisschaes <gei...@us...> - 2005-05-29 19:16:38
|
Update of /cvsroot/macattrick/macattrick In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11037 Modified Files: Player.h Player.m PlayerList.h PlayerList.m Properties.h Properties.m Log Message: loadFormerPlayerStates added to playerlist, but no testing yet. Properties provides a list of former data directories Index: Properties.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/Properties.m,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Properties.m 29 May 2005 16:23:54 -0000 1.15 --- Properties.m 29 May 2005 19:15:59 -0000 1.16 *************** *** 46,49 **** --- 46,67 ---- } + +(NSArray*) formerDatesPathes { + NSArray *directoryContents = [[NSFileManager defaultManager] directoryContentsAtPath:[self libraryPath]]; + NSMutableArray *formerDates = [NSMutableArray array]; + NSString *current = nil; + NSEnumerator *en = [directoryContents objectEnumerator]; + while(current = [en nextObject]) { + if([current length] == 8) { + NSString *path = [[NSString alloc] initWithFormat:@"%@/%@", [self libraryPath], current]; + BOOL isDir = TRUE; + if([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && isDir) { + NSLog(path); + [formerDates addObject:path]; + } + } + } + return formerDates; + } + +(NSString*) playersFile { NSString *path = [self libraryPath]; *************** *** 132,136 **** +(NSString*) dateFormat { ! return @"%Y-%m-%d"; } --- 150,154 ---- +(NSString*) dateFormat { ! return @"%Y%m%d"; } Index: Player.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/Player.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Player.h 29 May 2005 16:23:54 -0000 1.19 --- Player.h 29 May 2005 19:15:49 -0000 1.20 *************** *** 99,102 **** --- 99,104 ---- -(Position*) bestPosition; + - (PlayerState *) currentState; + /*! @method addState Index: Player.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/Player.m,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Player.m 29 May 2005 16:23:54 -0000 1.23 --- Player.m 29 May 2005 19:15:59 -0000 1.24 *************** *** 74,77 **** --- 74,78 ---- + - (PlayerState *) currentState { return currentState; } - (void) addState: (PlayerState*)state forDate: (NSString*) date { Index: Properties.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/Properties.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Properties.h 29 May 2005 16:23:54 -0000 1.9 --- Properties.h 29 May 2005 19:15:59 -0000 1.10 *************** *** 131,134 **** --- 131,136 ---- +(NSString*) worldDetailsFileInPath: (NSString*)path; + +(NSArray*) formerDatesPathes; + /*! @method currentVersion *************** *** 157,161 **** @method dateFormat @abstract get the format for macattrick dates ! @discussion used to store the former data, usually @"%Y-%m-%d" */ +(NSString*) dateFormat; --- 159,163 ---- @method dateFormat @abstract get the format for macattrick dates ! @discussion used to store the former data, usually @"%Y%m%d" */ +(NSString*) dateFormat; Index: PlayerList.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/PlayerList.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PlayerList.h 28 Nov 2004 14:07:02 -0000 1.5 --- PlayerList.h 29 May 2005 19:15:59 -0000 1.6 *************** *** 58,61 **** --- 58,62 ---- - (PlayerList*) init; + - (void) loadFormerPlayerStates; /*! Index: PlayerList.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/PlayerList.m,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PlayerList.m 28 Nov 2004 14:07:02 -0000 1.5 --- PlayerList.m 29 May 2005 19:15:59 -0000 1.6 *************** *** 29,32 **** --- 29,35 ---- #import "PlayerList.h" + @interface PlayerList (Private) + - (void) loadStatesFromFormerPlayerList: (PlayerList*) playerList date: (NSString*) date; + @end @implementation PlayerList *************** *** 48,51 **** --- 51,86 ---- } + - (void) loadFormerPlayerStates { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSArray *directories = [Properties formerDatesPathes]; + NSString *currentPath = nil; + NSEnumerator *en = [directories objectEnumerator]; + while(currentPath = [en nextObject]) { + NSString *filename = [Properties playersFileInPath:currentPath]; + if([[NSFileManager defaultManager] fileExistsAtPath:filename]) { + NSString *date = [currentPath lastPathComponent]; + PlayerList *formerPlayerList = [[PlayerList alloc] initFromXML:[NSURL URLWithString:filename]]; + if(formerPlayerList) { + [self loadStatesFromFormerPlayerList:formerPlayerList date:date]; + [formerPlayerList release]; + } + } + } + [pool release]; + } + + + - (void) loadStatesFromFormerPlayerList: (PlayerList*) formerPlayerList date: (NSString*) date{ + NSEnumerator *en = [[self playerList] objectEnumerator]; + Player *currentPlayer = nil; + while(currentPlayer = [en nextObject]) { + int playerID = [currentPlayer playerID]; + Player *formerPlayer = [formerPlayerList playerWithID:playerID]; + if(formerPlayer) { + [currentPlayer addState:[formerPlayer currentState] forDate:date]; + } + } + } + - (PlayerList*) init{ NSURL *url = [[NSURL alloc] initFileURLWithPath: [Properties playersFile]]; |