Created
May 19, 2014 19:28
-
-
Save jparreira/a362852173a33731fa7d to your computer and use it in GitHub Desktop.
Increment Player Score for Flying Brands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) incrementPlayerScore:(NSDictionary *) playerScore WhitScore:(NSNumber *) score OnCompletion:(void (^)(BOOL finished)) completion { | |
NSNumber *totalScore = [NSNumber numberWithInt:([[playerScore objectForKey:SK_SCORES] intValue] + [score intValue])]; | |
ItemRef *itemRef = [[_storageRef table:TAB_SCORES] item:[playerScore objectForKey:PK_SCORES] secondaryKey:[playerScore objectForKey:SK_SCORES]]; | |
[itemRef del:^(ItemSnapshot *success) { | |
NSDictionary *newScore = [NSDictionary dictionaryWithObjectsAndKeys: | |
[playerScore objectForKey:PK_SCORES], PK_SCORES, | |
totalScore, SK_SCORES, | |
[playerScore objectForKey:PK_PLAYERS], @"nickName", | |
[playerScore objectForKey:SK_STATUS], @"gameId", nil]; | |
[[_storageRef table:TAB_SCORES] push:newScore | |
success:^(ItemSnapshot *item) { | |
ItemRef *itemRef = [[_storageRef table:TAB_STATUS] item:[playerScore objectForKey:PK_STATUS] | |
secondaryKey:[playerScore objectForKey:SK_STATUS]]; | |
[itemRef incr:@"score" withValue:[score intValue] success:^(ItemSnapshot *success) { | |
completion(YES); | |
} error:^(NSError *error) { | |
//NSLog(@"Error INCREMENTING SCORE on TAB_STATUS\nERROR: %@", [error description]); | |
}]; | |
} | |
error:^(NSError *error) { | |
//NSLog(@"Error Writing item\nERROR: %@", [error description]); | |
completion(NO); | |
}]; | |
} error:^(NSError *error) { | |
//NSLog(@"Error DELETING SCORE\nERROR: %@", [error description]); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment