Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trompo Games #7

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
1 change: 1 addition & 0 deletions OpenKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "OpenKit-Prefix.pch";
ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
4 changes: 2 additions & 2 deletions OpenKit/KGModal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <UIKit/UIKit.h>

NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){
typedef NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){
KGModalBackgroundDisplayStyleGradient,
KGModalBackgroundDisplayStyleSolid
};
Expand Down Expand Up @@ -37,7 +37,7 @@ NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){

// The background display style, can be a transparent radial gradient or a transparent black
// Defaults to gradient, this looks better but takes a bit more time to display on the retina iPad
@property (nonatomic) enum KGModalBackgroundDisplayStyle backgroundDisplayStyle;
@property (nonatomic) KGModalBackgroundDisplayStyle backgroundDisplayStyle;

// Determins if the modal should rotate when the device rotates
// Defaults to YES, only applies to iOS5
Expand Down
9 changes: 8 additions & 1 deletion OpenKit/KGModal.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated{
containerView.modalBackgroundColor = self.modalBackgroundColor;
containerView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|
UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
#if !defined(ANDROID)
containerView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
#endif
contentView.frame = (CGRect){padding, padding, contentView.bounds.size};
[containerView addSubview:contentView];
[viewController.view addSubview:containerView];
Expand All @@ -118,7 +120,9 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated{
}];

containerView.alpha = 0;
#if !defined(ANDROID)
containerView.layer.shouldRasterize = YES;
#endif
containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4, 0.4);
[UIView animateWithDuration:kTransformPart1AnimationDuration animations:^{
containerView.alpha = 1;
Expand All @@ -128,7 +132,9 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated{
containerView.alpha = 1;
containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
} completion:^(BOOL finished2) {
#if !defined(ANDROID)
containerView.layer.shouldRasterize = NO;
#endif
}];
}];
}
Expand Down Expand Up @@ -167,8 +173,9 @@ - (void)hideAnimated:(BOOL)animated withCompletionBlock:(void(^)())completion{
[UIView animateWithDuration:kFadeInAnimationDuration animations:^{
self.viewController.styleView.alpha = 0;
}];

#if !defined(ANDROID)
self.containerView.layer.shouldRasterize = YES;
#endif
[UIView animateWithDuration:kTransformPart2AnimationDuration animations:^{
self.containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished){
Expand Down
4 changes: 4 additions & 0 deletions OpenKit/OKAchievementsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ -(id)init {
if(self) {
OKAchievementsListVC *achievementsVC = [[OKAchievementsListVC alloc] init];
NSArray *viewControllers = [NSArray arrayWithObject:achievementsVC];
#if defined(ANDROID)
[self setViewControllers:viewControllers];
#else
[self setViewControllers:viewControllers animated:NO];
#endif

UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Achievements" image:[UIImage imageNamed:@"achievements.png"] tag:2];
[self setTabBarItem:tabBarItem];
Expand Down
11 changes: 9 additions & 2 deletions OpenKit/OKBaseLoginViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@


@interface OKBaseLoginViewController : UIViewController


#if defined(ANDROID)
{
UIWindow *_window;
}

-(void) setWindow:(UIWindow *)window;
-(UIWindow*) window;
#else
@property (nonatomic, strong) UIWindow *window;
#endif
@property (nonatomic, strong) UIActivityIndicatorView *spinner;
@property (nonatomic, strong) UIView *loginView;
@property (nonatomic, strong) id<OKLoginViewDelegate> delegate;
Expand Down
11 changes: 11 additions & 0 deletions OpenKit/OKBaseLoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ @interface OKBaseLoginViewController ()
@implementation OKBaseLoginViewController

@synthesize loginView,spinner, fbLoginButton, gcLoginButton, delegate, loginString;
#if defined(ANDROID)
-(void) setWindow:(UIWindow *)window
{
_window = window;
}

-(UIWindow*) window
{
return _window;
}
#endif

-(id)initWithLoginString:(NSString*)aLoginString
{
Expand Down
2 changes: 2 additions & 0 deletions OpenKit/OKLeaderboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ typedef enum {
//Wrapper methods
-(void)getGlobalScoresWithPageNum:(int)pageNum withCompletionHandler:(void (^)(NSArray *scores, NSError *error))completionHandler;
-(void)getPlayerTopScoreWithCompletionHandler:(void (^)(id<OKScoreProtocol> score, NSError *error))completionHandler;
-(void)getPlayerGlobalTopScoreWithCompletionHandler:(void (^)(id<OKScoreProtocol> score))completionHandler;
-(void) getAllPlayerScoresWithCompletionHandler:(void (^)(NSArray *scores))completionHandler;

//GameCenter methods
-(void)getGameCenterFriendsScoreswithCompletionHandler:(void (^)(NSArray *scores, NSError *error))completionHandler;
Expand Down
69 changes: 67 additions & 2 deletions OpenKit/OKLeaderboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ - (id)initFromJSON:(NSDictionary*)jsonDict
{
if ((self = [super init])) {
NSString *sortTypeString = [OKHelper getNSStringSafeForKey:@"sort_type" fromJSONDictionary:jsonDict];

self.name = [OKHelper getNSStringSafeForKey:@"name" fromJSONDictionary:jsonDict];
self.OKLeaderboard_id = [[OKHelper getNSNumberSafeForKey:@"id" fromJSONDictionary:jsonDict] integerValue];
self.OKApp_id = [[OKHelper getNSNumberSafeForKey:@"app_id" fromJSONDictionary:jsonDict] integerValue];
self.sortType = ([sortTypeString isEqualToString:@"HighValue"]) ? OKLeaderboardSortTypeHighValue : OKLeaderboardSortTypeLowValue;
self.icon_url = [OKHelper getNSStringSafeForKey:@"icon_url" fromJSONDictionary:jsonDict];
self.playerCount = [[OKHelper getNSNumberSafeForKey:@"player_count" fromJSONDictionary:jsonDict] integerValue];
#if defined(ANDROID)
self.gamecenter_id = [OKHelper getNSStringSafeForKey:@"gpg_id" fromJSONDictionary:jsonDict];
#else
self.gamecenter_id = [OKHelper getNSStringSafeForKey:@"gamecenter_id" fromJSONDictionary:jsonDict];
#endif
}

return self;
Expand Down Expand Up @@ -65,6 +68,7 @@ + (void)getLeaderboardsWithCompletionHandler:(void (^)(NSArray* leaderboards, in

+ (void)getLeaderboardsWithTag:(NSString*)leaderbaordListTag WithCompletionHandler:(void (^)(NSArray* leaderboards, int playerCount, NSError* error))completionHandler
{

NSDictionary *requestParams = [NSDictionary dictionaryWithObject:leaderbaordListTag forKey:@"tag"];

// OK NETWORK REQUEST
Expand Down Expand Up @@ -168,7 +172,6 @@ -(void)getGameCenterFriendsScoreswithCompletionHandler:(void (^)(NSArray *scores
-(void)getScoresFromGameCenterWithRange:(NSRange)scoreRange withPlayerScope:(GKLeaderboardPlayerScope)playerScope withCompletionHandler:(void (^)(NSArray *scores, NSError *error))completionHandler
{
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];

if(![self gamecenter_id]) {
completionHandler(nil, [OKError noGameCenterIDError]);
return;
Expand Down Expand Up @@ -363,6 +366,68 @@ -(void)getPlayerTopScoreWithCompletionHandler:(void (^)(id<OKScoreProtocol> scor
}
}

-(void)getPlayerGlobalTopScoreWithCompletionHandler:(void (^)(id<OKScoreProtocol> score))completionHandler
{
// This function returns the global best score, preferring facebook -> game center -> cached //

NSMutableArray *scores = [NSMutableArray arrayWithCapacity:3];

// the order in which you add the scores affects the priority of the result when they have equal values //
[self getPlayerTopScoreForLeaderboardForTimeRange:OKLeaderboardTimeRangeAllTime withCompletionHandler:^(OKScore *okScore, NSError *okError) { // OK SCORE //
if (!okError && okScore)
{
[scores addObject:okScore];
}
[self getPlayerTopScoreFromGameCenterWithCompletionHandler:^(OKGKScoreWrapper *gcScore, NSError *gamecenterError) { // GAME CENTER //
if (!gamecenterError && gcScore)
{
[scores addObject:gcScore];
}

OKScore *topCachedScore = [self getPlayerTopScoreFromLocalCache]; // CACHED //
if (topCachedScore)
{
[scores addObject:topCachedScore];
}

// sort the scores and call the completion handler //
id<OKScoreProtocol> bestScore = nil;
NSArray *sorted = [self sortScoresBasedOnLeaderboardType:scores];
bestScore = [sorted firstObject];
completionHandler(bestScore);
}];
}];
}

-(void) getAllPlayerScoresWithCompletionHandler:(void (^)(NSArray *scores))completionHandler
{
// This function returns all the player scores so devs can check for discrepancies //

NSMutableArray *scores = [NSMutableArray arrayWithCapacity:3];

// the order in which you add the scores affects the priority of the result when they have equal values //
[self getPlayerTopScoreForLeaderboardForTimeRange:OKLeaderboardTimeRangeAllTime withCompletionHandler:^(OKScore *okScore, NSError *okError) { // OK SCORE //
if (!okError && okScore)
{
[scores addObject:okScore];
}
[self getPlayerTopScoreFromGameCenterWithCompletionHandler:^(OKGKScoreWrapper *gcScore, NSError *gamecenterError) { // GAME CENTER //
if (!gamecenterError && gcScore)
{
[scores addObject:gcScore];
}

OKScore *topCachedScore = [self getPlayerTopScoreFromLocalCache]; // CACHED //
if (topCachedScore)
{
[scores addObject:topCachedScore];
}

completionHandler(scores);
}];
}];
}

-(OKScore*)getPlayerTopScoreFromLocalCache
{
NSArray *cachedScores = [[OKScoreDB sharedCache] getCachedScoresForLeaderboardID:[self OKLeaderboard_id] andOnlyGetSubmittedScores:NO];
Expand Down
4 changes: 4 additions & 0 deletions OpenKit/OKLeaderboardsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ - (id)init {
self.modalPresentationStyle = UIModalPresentationFormSheet;
OKLeaderboardsListViewController *list = [[OKLeaderboardsListViewController alloc]initWithDefaultLeaderboardID:defaultLeaderboardID];
NSArray *viewControllers = [NSArray arrayWithObject:list];
#if defined(ANDROID)
[self setViewControllers:viewControllers];
#else
[self setViewControllers:viewControllers animated:NO];
#endif

UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Leaderboards" image:[UIImage imageNamed:@"leaderboards.png"] tag:1];
[self setTabBarItem:tabBarItem];
Expand Down
2 changes: 1 addition & 1 deletion OpenKit/OKLocalCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern dispatch_queue_t __OKCacheQueue;

// You can use this for insert/update/delete without access block. Selects should
// go through access block so FMResultSet access is contained.
- (BOOL)update:(NSString *)sql, ...;
- (BOOL)update:(NSString *)sql, ... NS_REQUIRES_NIL_TERMINATION;

// Get the autoincrement primary key int ID of the last inserted row
-(int)lastInsertRowID;
Expand Down
15 changes: 11 additions & 4 deletions OpenKit/OKLocalCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,23 @@ -(void)access:(void(^)(FMDatabase *))block
}
}

- (BOOL)update:(NSString *)sql, ...
- (BOOL)update:(NSString *)sql, ... NS_REQUIRES_NIL_TERMINATION
{
va_list args;
va_start(args, sql);

NSMutableArray *argArray = [NSMutableArray array];
id obj = nil;
while((obj = va_arg(args, id)))
{
[argArray addObject:obj];
}
va_end(args);

__block BOOL success;
[self access:^(FMDatabase *db) {
OKLogInfo(@"Performing cache update: %@", sql);
success = [db executeUpdate:sql error:nil withArgumentsInArray:nil orDictionary:nil orVAList:args];
success = [db executeUpdate:sql error:nil withArgumentsInArray:argArray orDictionary:nil orVAList:nil];
OKLogInfo(@"...%@", (success ? @"success" : @"FAIL"));

// We have to cache the last inserted row ID because
Expand All @@ -63,7 +71,6 @@ - (BOOL)update:(NSString *)sql, ...
lastInsertRowID = [db lastInsertRowId];
}
}];
va_end(args);

return success;
}
Expand Down Expand Up @@ -139,7 +146,7 @@ -(void)sanity
- (BOOL)insertToken:(NSString *)tokenStr
{
NSDate *now = [NSDate date];
return [self update:@"insert into tokens (token, submitted, created_at) values (?, ?, ?) ", tokenStr, [NSNumber numberWithInt:0], now];
return [self update:@"insert into tokens (token, submitted, created_at) values (?, ?, ?) ", tokenStr, [NSNumber numberWithInt:0], now, nil];
}


Expand Down
6 changes: 4 additions & 2 deletions OpenKit/OKManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "OKSessionDb.h"
#import "OKMacros.h"

#define OK_DEFAULT_ENDPOINT @"http://api.openkit.io"
#define OK_DEFAULT_ENDPOINT @"http://api.gameeso.com"
#define OK_OPENKIT_SDK_VERSION = @"1.1";

static NSString *OK_USER_KEY = @"OKUserInfo";
Expand Down Expand Up @@ -205,12 +205,14 @@ + (void)handleWillTerminate
- (void)registerToken:(NSData *)deviceToken
{
OKLog(@"OKManager registerToken, data: %@", deviceToken);

const unsigned *tokenBytes = [deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
#if defined(ANDROID)
#undef ntohl
#endif

OKLogInfo(@"cache queue is %s", dispatch_queue_get_label(OK_CACHE_QUEUE()));
dispatch_async(OK_CACHE_QUEUE(), ^{
Expand Down
9 changes: 5 additions & 4 deletions OpenKit/OKScoreDB.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ -(void)insertScore:(OKScore*)score
[NSNumber numberWithLongLong:score.scoreValue],
[NSNumber numberWithInt:score.metadata],
score.displayString,
[NSNumber numberWithBool:score.submitted]];
[NSNumber numberWithBool:score.submitted],
nil];

if(inserted) {
int scoreID = [self lastInsertRowID];
Expand All @@ -83,7 +84,7 @@ -(void)deleteScore:(OKScore*)score

NSString *deleteSQL = @"DELETE FROM OKCACHE WHERE id=?";

BOOL deleted = [self update:deleteSQL,[NSNumber numberWithInt:[score OKScoreID]]];
BOOL deleted = [self update:deleteSQL,[NSNumber numberWithInt:[score OKScoreID]], nil];

if(deleted) {
OKLogInfo(@"Removed score: %@", score);
Expand All @@ -101,7 +102,7 @@ -(void)updateCachedScoreSubmitted:(OKScore*)score

NSString *updateString = @"UPDATE OKCACHE SET Submitted=1 WHERE id=?";

BOOL updated = [self update:updateString, [NSNumber numberWithInt:[score OKScoreID]]];
BOOL updated = [self update:updateString, [NSNumber numberWithInt:[score OKScoreID]], nil];

if(!updated) {
OKLog(@"Failed to update score row with error message %@", [self lastErrorMessage]);
Expand Down Expand Up @@ -210,7 +211,7 @@ -(void)clearCachedSubmittedScores

NSString *deleteSQL = @"DELETE FROM OKCACHE WHERE submitted=1";

BOOL success = [self update:deleteSQL];
BOOL success = [self update:deleteSQL, nil];

if(success) {
OKLogInfo(@"Cleared all cached submitted scores");
Expand Down
2 changes: 1 addition & 1 deletion OpenKit/OKSessionDb.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ - (OKSessionRow *)lastRow
- (OKSessionRow *)insertRow:(OKSessionTemplate *)t
{
NSDate *now = [NSDate date];
if (![self update:@"insert into sessions (uuid, fb_id, google_id, custom_id, ok_id, push_token, client_created_at) values (?, ?, ?, ?, ?, ?, ?) ", t.uuid, t.fbId, t.googleId, t.customId, t.okId, t.pushToken, now]) {
if (![self update:@"insert into sessions (uuid, fb_id, google_id, custom_id, ok_id, push_token, client_created_at) values (?, ?, ?, ?, ?, ?, ?) ", t.uuid, t.fbId, t.googleId, t.customId, t.okId, t.pushToken, now, nil]) {
OKLogErr(@"Could not create new session.");
return nil;
}
Expand Down
2 changes: 1 addition & 1 deletion OpenKit/Vendor/fmdb-fd95c38/FMDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#if TARGET_OS_IPHONE
// Compiling for iOS
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 || defined(ANDROID)
// iOS 6.0 or later
#define FMDBDispatchQueueRelease(__v)
#else
Expand Down
Loading