Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Prefixed category convenience selectors on the GameKit framework, also adding blocks instead of delegate calls.

License

Notifications You must be signed in to change notification settings

seivan-archives/SHGameCenter

Repository files navigation

SHGameCenter

Version Platform License

Prefixed category convenience selectors on the GameKit framework, also adding blocks instead of delegate calls.

SHGameCenter adds class or instance observers on GKTurnBasedMatch for handling matches. Also authenticate state observers. It deals with caching images as well as display names. Takes of everything!

This pod is part of many components covering to plug the holes missing from Foundation, UIKit, CoreLocation, GameKit, MapKit and other aspects of an iOS application's architecture.

##Dependency Status

Library Tests Version Platform
SHFastEnumerationProtocols Build Status Version Platform

##Setup ###Install

pod 'SHGameCenter'

###Use

#import "SHGameCenter.h"

GKLocalPlayer

###Api

#pragma mark - Authentication
//handles on foreground notifications
+(void)SH_authenticateWithLoginViewControllerBlock:(SHGameViewControllerBlock)theLoginViewControllerBlock
                                     didLoginBlock:(SHGameCompletionBlock)theLoginBlock
                                    didLogoutBlock:(SHGameCompletionBlock)theLogoutBlock
                                    withErrorBlock:(SHGameErrorBlock)theErrorBlock;

#pragma mark - Properties
#pragma mark - Player Getters
+(GKLocalPlayer *)SH_me;
+(void)SH_requestFriendsWithBlock:(SHGameListsBlock)theBlock;

###Usage

  __weak SHSessionViewController * blockSelf = self;
  [GKLocalPlayer SH_authenticateWithLoginViewControllerBlock:^(UIViewController *viewController) {
    [blockSelf presentViewController:viewController animated:YES completion:nil];
  } didLoginBlock:^{
    [blockSelf performSegueWithIdentifier:@"SHLoggedIn" sender:self];
  } didLogoutBlock:^{
    [blockSelf dismissViewControllerAnimated:NO completion:nil];
  } withErrorBlock:^(NSError *error) {
    [blockSelf showAlertWithError:error];
  }];

GKPlayer

###Api

#pragma mark - Getter
@property(nonatomic,readonly) UIImage * SH_photo;

##GKTurnBasedMatch

###Api

#pragma mark - Participant Getters
@property(nonatomic,readonly) GKTurnBasedParticipant  * SH_meAsParticipant;
@property(nonatomic,readonly) NSArray                 * SH_participantsWithoutMe;
@property(nonatomic,readonly) NSArray                 * SH_participantsWithoutCurrent;
@property(nonatomic,readonly) NSArray                 * SH_participantsNextOrder;
@property(nonatomic,readonly) NSArray                 * SH_playerIdentifiers;


#pragma mark - Conditions
@property(nonatomic,readonly) BOOL SH_isMyTurn;
//Participants who are neither active nor invited - e.g done, declined and etc
@property(nonatomic,readonly) BOOL SH_hasIncompleteParticipants;

@property(nonatomic,readonly) BOOL SH_isMatchStatusOpen;
@property(nonatomic,readonly) BOOL SH_isMatchStatusMatching;
@property(nonatomic,readonly) BOOL SH_isMatchStatusEnded;
@property(nonatomic,readonly) BOOL SH_isMatchStatusUnknown;



#pragma mark - Observer
-(void)SH_setObserver:(id)theObserver
  matchEventTurnBlock:(SHGameMatchEventTurnBlock)theMatchEventTurnBlock
 matchEventEndedBlock:(SHGameMatchEventEndedBlock)theMatchEventEndedBlock;

+(void)SH_setObserver:(id)theObserver
matchEventTurnBlock:(SHGameMatchEventTurnBlock)theMatchEventTurnBlock
matchEventEndedBlock:(SHGameMatchEventEndedBlock)theMatchEventEndedBlock
matchEventInvitesBlock:(SHGameMatchEventInvitesBlock)theMatchEventInvitesBlock;



#pragma mark - Preloaders

+(void)SH_requestMatchesWithBlock:(SHGameListsBlock)theMatchesBlock
              andFriendsWithBlock:(SHGameListsBlock)theFriendsBlock
              withCompletionBlock:(SHGameCompletionBlock)theCompletionBlock;


#pragma mark - Player
-(void)SH_requestPlayersWithBlock:(SHGameListsBlock)theBlock;


#pragma mark - Equal
-(BOOL)SH_isEqualToMatch:(id)object;


#pragma mark - Match Getters
+(void)SH_requestMatchesWithBlock:(SHGameListsBlock)theBlock;




#pragma mark - Match Setters
-(void)SH_resignWithBlock:(SHGameMatchBlock)theBlock;

-(void)SH_deleteWithBlock:(SHGameMatchBlock)theBlock;

###Usage

Instance

  __weak TELMatchShowViewController *blockSelf = self;
  [self.match SH_setObserver:self matchEventTurnBlock:^(GKTurnBasedMatch *match, BOOL didBecomeActive) {
    [blockSelf handleTurnEventForMatch:match didBecomeActive:didBecomeActive];
    
  } matchEventEndedBlock:^(GKTurnBasedMatch *match) {
    blockSelf.txtView.text = @"ENDED";
  }];

Class

  [GKTurnBasedMatch SH_setObserver:self matchEventTurnBlock:^(GKTurnBasedMatch *match, BOOL didBecomeActive) {
    
    
    NSLog(@"Match: %@ - active: %d", match, didBecomeActive);

  } matchEventEndedBlock:^(GKTurnBasedMatch *match) {
    NSLog(@"Match: %@ - ended", match);
  } matchEventInvitesBlock:^(NSArray *playersToInvite) {
    NSLog(@"Players: %@ - ended", playersToInvite);
  }];

##GKTurnBasedParticipant

###Api

enum {
  SHTurnBasedMatchOutcomeNone         = 0,        // Participants who are not done with a match have this state
  SHTurnBasedMatchOutcomeQuit         = 1,        // Participant quit
  SHTurnBasedMatchOutcomeWon          = 2,        // Participant won
  SHTurnBasedMatchOutcomeLost         = 3,        // Participant lost
  SHTurnBasedMatchOutcomeTied         = 4,        // Participant tied
  SHTurnBasedMatchOutcomeTimeExpired  = 5,        // Game ended due to time running out
  SHTurnBasedMatchOutcomeFirst        = 6,
  SHTurnBasedMatchOutcomeSecond       = 7,
  SHTurnBasedMatchOutcomeThird        = 8,
  SHTurnBasedMatchOutcomeFourth       = 9,
  SHTurnBasedMatchOutcomeFifth        = 10,
  SHTurnBasedMatchOutcomeSixth        = 11,
  SHTurnBasedMatchOutcomeSeventh      = 12,
  SHTurnBasedMatchOutcomeEighth       = 13,
  SHTurnBasedMatchOutcomeNinth        = 14,
  SHTurnBasedMatchOutcomeTenth        = 16,
  SHTurnBasedMatchOutcomeEleventh     = 17,
  SHTurnBasedMatchOutcomeTwelvth      = 18,

  
  SHTurnBasedMatchOutcomeCustomRange = 0x00FF0000 // game result range available for custom app use
  
};
typedef NSInteger SHTurnBasedMatchOutcome;


#pragma mark -
#pragma mark Getter
@property(nonatomic,readonly) NSString * SH_alias;
@property(nonatomic,readonly) UIImage  * SH_photo;

#pragma mark -
#pragma mark Conditions
@property(nonatomic,readonly) BOOL SH_isMe;

#pragma mark -
#pragma mark GKTurnBasedParticipantStatus
@property(nonatomic,readonly) BOOL SH_isActiveOrInvited;
@property(nonatomic,readonly) BOOL SH_isInvited;
@property(nonatomic,readonly) BOOL SH_isActive;
@property(nonatomic,readonly) BOOL SH_isMatching;
@property(nonatomic,readonly) BOOL SH_isDone;

#pragma mark -
#pragma mark GKTurnBasedMatchOutcome
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeNone;
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeQuit;
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeWon;
@property(nonatomic,readonly) BOOL SH_hasMatchOutcomeWithPosition;

##Contact

If you end up using SHFoundationAdditions in a project, I'd love to hear about it.

email: seivan.heidari@icloud.com
twitter: @seivanheidari

##License

SHGameCenter is © 2013 Seivan and may be freely distributed under the MIT license. See the LICENSE.md file.

About

Prefixed category convenience selectors on the GameKit framework, also adding blocks instead of delegate calls.

Resources

License

Stars

Watchers

Forks

Packages

No packages published