Created
March 30, 2012 11:38
-
-
Save adamlwgriffiths/2250978 to your computer and use it in GitHub Desktop.
Hacks to get CocosBuilder working with Cocos1.x
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
<snip> | |
#import "Cocos+DefaultInits.h" | |
-(void) tryToRunFirstScene | |
{ | |
CCDirector* director = [CCDirector sharedDirector]; | |
// swizzle in our CCMenu fix for CCBuilder | |
{ | |
MethodSwizzle( [CCLabelTTF class], @selector(init), @selector(initWithoutParams) ); | |
MethodSwizzle( [CCMenu class], @selector(init), @selector(initWithoutParams) ); | |
} | |
// try to run first scene | |
if (director.isSceneStackEmpty) | |
{ | |
<snip> |
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
// | |
// CCNode+KVC.h | |
// | |
// Created by Adam Griffiths on 30/03/12. | |
// Copyright (c) 2012 Twisted Pair Development. All rights reserved. | |
// | |
@interface CCNode (KVC) | |
- (void)setValue:(id)value forKey:(NSString *)key; | |
@end |
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
// | |
// CCNode+KVC.m | |
// | |
// Created by Adam Griffiths on 30/03/12. | |
// Copyright (c) 2012 Twisted Pair Development. All rights reserved. | |
// | |
#import "CCNode+KVC.h" | |
@implementation CCNode (KVC) | |
- (void)setValue:(id)value forKey:(NSString *)key | |
{ | |
@try | |
{ | |
NSLog( @"[%@] INFO: Setting value for key %@", [self class], key ); | |
[super setValue:value forKey:key]; | |
} | |
@catch (NSException *e)//(NSUnknownKeyException *e) | |
{ | |
@try | |
{ | |
NSLog( @"[%@] WARNING: Key %@ not valid, trying %@_", [self class], key, key ); | |
[super setValue:value forKey:[NSString stringWithFormat:@"%@_", key]]; | |
NSLog( @"Success" ); | |
} | |
@catch (NSException *e) | |
{ | |
// we can't fix this | |
NSLog( @"[%@] ERROR: Key %@ failed!", [self class], key ); | |
} | |
} | |
} | |
@end |
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
// | |
// Cocos+DefaultInits.h | |
// | |
// Created by Adam Griffiths on 30/03/12. | |
// Copyright (c) 2012 Twisted Pair Development. All rights reserved. | |
// | |
@interface CCMenu (Constructor) | |
- (id)initWithoutParams; | |
@end | |
@interface CCLabelTTF (Constructor) | |
- (id)initWithoutParams; | |
@end |
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
// | |
// Cocos+DefaultInits.m | |
// | |
// Created by Adam Griffiths on 30/03/12. | |
// Copyright (c) 2012 Twisted Pair Development. All rights reserved. | |
// | |
#import "Cocos+DefaultInits.h" | |
@implementation CCMenu (Constructor) | |
- (id)initWithoutParams | |
{ | |
return [self initWithItems:nil vaList:nil]; | |
} | |
@end | |
@implementation CCLabelTTF (Constructor) | |
- (id)initWithoutParams | |
{ | |
self = [self initWithString:@"OH NO" fontName:@"arial" fontSize:12]; | |
return self; | |
} | |
@end |
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
// | |
// SelectorSwizzle.c | |
// | |
#import "SelectorSwizzle.h" | |
#import </usr/include/objc/objc-class.h> | |
void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel) | |
{ | |
Method orig_method = nil, alt_method = nil; | |
// First, look for the methods | |
orig_method = class_getInstanceMethod(aClass, orig_sel); | |
alt_method = class_getInstanceMethod(aClass, alt_sel); | |
// If both are found, swizzle them | |
if ((orig_method != nil) && (alt_method != nil)) | |
{ | |
char *temp1; | |
IMP temp2; | |
temp1 = orig_method->method_types; | |
orig_method->method_types = alt_method->method_types; | |
alt_method->method_types = temp1; | |
temp2 = orig_method->method_imp; | |
orig_method->method_imp = alt_method->method_imp; | |
alt_method->method_imp = temp2; | |
} | |
} |
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
// | |
// SelectorSwizzle.h | |
// | |
#import </usr/include/objc/objc-class.h> | |
void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment