Skip to content

Instantly share code, notes, and snippets.

@jparreira
Created May 19, 2014 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jparreira/a362852173a33731fa7d to your computer and use it in GitHub Desktop.
Save jparreira/a362852173a33731fa7d to your computer and use it in GitHub Desktop.
Increment Player Score for Flying Brands
- (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