Skip to content

Commit 79dbd3f

Browse files
committed
Merge pull request #1218 from andykorth/CCDirector/UpdateTestBase
Update Test project to work with CCAppController changes
2 parents 0a5fce0 + 60df1c9 commit 79dbd3f

33 files changed

+1067
-621
lines changed

Android/AppActivity.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* SpriteBuilder: http://www.spritebuilder.org
3+
*
4+
* Copyright (c) 2014 Apportable Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
26+
#import "CCActivity.h"
27+
28+
BRIDGE_CLASS("com.apportable.GLActivity")
29+
@interface PROJECTIDENTIFIERActivity : CCActivity
30+
31+
@end

Android/AppActivity.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SpriteBuilder: http://www.spritebuilder.org
3+
*
4+
* Copyright (c) 2014 Apportable Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
26+
#import "PROJECTIDENTIFIERActivity.h"
27+
#import "PROJECTIDENTIFIERController.h"
28+
29+
#import <AndroidKit/AndroidKeyEvent.h>
30+
31+
@implementation PROJECTIDENTIFIERActivity
32+
33+
34+
- (BOOL)onKeyUp:(int32_t)keyCode keyEvent:(AndroidKeyEvent *)event
35+
{
36+
if (keyCode == AndroidKeyEventKeycodeBack)
37+
{
38+
[self finish];
39+
}
40+
return NO;
41+
}
42+
43+
- (void)run
44+
{
45+
[super run];
46+
47+
[PROJECTIDENTIFIERController setupApplication];
48+
}
49+
50+
@end

Mac/AppDelegate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#import <Cocoa/Cocoa.h>
2+
3+
@interface AppDelegate : NSObject <NSApplicationDelegate>
4+
5+
@end
6+

Mac/AppDelegate.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#import "AppDelegate.h"
2+
#import "CCPackageManager.h"
3+
#import "CCDirector_Private.h"
4+
#import "AppController.h"
5+
6+
@interface AppDelegate ()
7+
8+
@property (weak) IBOutlet NSWindow *window;
9+
@property (weak) IBOutlet CC_VIEW<CCView> *glView;
10+
@end
11+
12+
@implementation AppDelegate
13+
14+
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
15+
{
16+
AppController *controller = [AppController sharedController];
17+
controller.window = _window;
18+
controller.glView = _glView;
19+
[controller setupApplication];
20+
return;
21+
}
22+
23+
- (void)applicationWillTerminate:(NSNotification *)aNotification
24+
{
25+
[[CCPackageManager sharedManager] savePackages];
26+
}
27+
28+
@end

Mac/main.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2015 Apportable. All rights reserved.
2+
3+
#import <Cocoa/Cocoa.h>
4+
5+
int main(int argc, const char * argv[]) {
6+
return NSApplicationMain(argc, argv);
7+
}

UnitTests/CCTextureTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ - (void)setUp
1515
{
1616
[super setUp];
1717

18-
[(AppController *)[UIApplication sharedApplication].delegate configureCocos2d];
18+
// [(AppController *)[UIApplication sharedApplication].delegate configureCocos2d];
1919
}
2020

2121
-(void)testTextureCache

cocos2d-tests.xcodeproj/project.pbxproj

Lines changed: 59 additions & 35 deletions
Large diffs are not rendered by default.

cocos2d-ui-tests/ios/AppDelegate.h renamed to cocos2d-ui-tests/ios/AppController.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
#import <UIKit/UIKit.h>
26-
#import "cocos2d.h"
25+
#import "CCAppController.h"
2726

28-
@interface AppController : CCAppDelegate
29-
{
30-
}
27+
@interface AppController : CCAppController
3128

32-
- (void)configureCocos2d;
33-
34-
- (void)configureFileUtilsSearchPathAndRegisterSpriteSheets;
29+
+ (AppController*)sharedController;
30+
+ (void)setupApplication;
3531

3632
@end

cocos2d-ui-tests/ios/AppDelegate.m renamed to cocos2d-ui-tests/ios/AppController.m

Lines changed: 85 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,50 @@
2424

2525
#import "cocos2d.h"
2626

27-
#import "AppDelegate.h"
27+
#import "AppController.h"
2828
#import "MainMenu.h"
2929
#import "TestBase.h"
3030
#import "CCPackageConstants.h"
3131

3232
@implementation AppController
3333

34-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
35-
{
36-
[self configureCocos2d];
3734

38-
return YES;
35+
- (void)setupApplication
36+
{
37+
[self configureFileUtilsSearchPathAndRegisterSpriteSheets];
38+
[super setupApplication];
3939
}
4040

41-
- (void)configureCocos2d
41+
- (NSDictionary*)iosConfig
4242
{
43-
// Configure the file utils to work with SpriteBuilder, but use a custom resource path (Resources-shared instead of Published-iOS)
44-
[CCBReader configureCCFileUtils];
45-
46-
[self configureFileUtilsSearchPathAndRegisterSpriteSheets];
43+
return @{
44+
CCSetupDepthFormat: @GL_DEPTH24_STENCIL8,
45+
CCSetupTabletScale2X: @YES,
46+
CCSetupShowDebugStats: @(getenv("SHOW_DEBUG_STATS") != nil),
47+
};
48+
}
4749

48-
[self setupCocos2dWithOptions:@{
49-
CCSetupDepthFormat: @GL_DEPTH24_STENCIL8,
50-
// CCSetupScreenMode: CCScreenModeFixed,
51-
// CCSetupScreenOrientation: CCScreenOrientationPortrait,
52-
CCSetupTabletScale2X: @YES,
53-
CCSetupShowDebugStats: @(getenv("SHOW_DEBUG_STATS") != nil),
54-
}];
50+
- (NSDictionary*)macConfig
51+
{
52+
NSMutableDictionary *config = [NSMutableDictionary dictionary];
53+
config[CCMacDefaultWindowSize] = [NSValue valueWithCGSize:[self defaultWindowSize]];
54+
config[CCSetupDepthFormat] = @GL_DEPTH24_STENCIL8;
55+
config[CCSetupTabletScale2X] = @YES;
56+
config[CCSetupShowDebugStats] = @(getenv("SHOW_DEBUG_STATS") != nil);
57+
58+
return config;
5559
}
5660

5761
- (void)configureFileUtilsSearchPathAndRegisterSpriteSheets
5862
{
5963
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:PACKAGE_STORAGE_USERDEFAULTS_KEY];
6064
[[NSUserDefaults standardUserDefaults] synchronize];
6165

66+
// The testbed uses a different directory dictionary than is created by the default CCFileUtils constructor- it uses the file utils one
67+
[CCBReader configureCCFileUtils];
6268
CCFileUtils* sharedFileUtils = [CCFileUtils sharedFileUtils];
6369

70+
// Testbed needs special directory search paths:
6471
sharedFileUtils.searchPath = @[
6572
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"],
6673
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Fonts"],
@@ -74,60 +81,69 @@ - (void)configureFileUtilsSearchPathAndRegisterSpriteSheets
7481
[[CCSpriteFrameCache sharedSpriteFrameCache] registerSpriteFramesFile:@"TilesAtlassed.plist"];
7582
}
7683

77-
- (CCScene*) startScene
84+
- (CCScene*) createFirstScene
85+
{
86+
const char *testName = getenv("Test");
87+
88+
if(testName){
89+
return [TestBase sceneWithTestName:[NSString stringWithCString:testName encoding:NSUTF8StringEncoding]];
90+
} else {
91+
return [MainMenu scene];
92+
}
93+
}
94+
95+
96+
#pragma mark Android
97+
98+
#if __CC_PLATFORM_ANDROID
99+
100+
/*
101+
Add any android specific overrides here
102+
*/
103+
104+
#endif
105+
106+
107+
#pragma mark Mac
108+
109+
#if __CC_PLATFORM_MAC
110+
111+
/*
112+
Add any Mac specific overrides here
113+
*/
114+
-(CGSize)defaultWindowSize
115+
{
116+
return CGSizeMake(960.0f, 640.0f);
117+
}
118+
119+
#endif
120+
121+
#pragma mark Singleton Methods
122+
123+
static AppController *__sharedController;
124+
125+
/*
126+
These methods are used in the framework to reference this controller.
127+
*/
128+
+ (AppController*)sharedController
129+
{
130+
static dispatch_once_t onceToken;
131+
dispatch_once(&onceToken, ^
132+
{
133+
__sharedController = [[AppController alloc] init];
134+
});
135+
136+
return __sharedController;
137+
}
138+
139+
+ (void)setupApplication
78140
{
79-
const char *testName = getenv("Test");
80-
81-
if(testName){
82-
return [TestBase sceneWithTestName:[NSString stringWithCString:testName encoding:NSUTF8StringEncoding]];
83-
} else {
84-
return [MainMenu scene];
85-
}
141+
static dispatch_once_t setupToken;
142+
dispatch_once(&setupToken, ^
143+
{
144+
[[AppController sharedController] setupApplication];
145+
});
86146
}
87147

88-
//// I'm going to leave this in for testing the fixed size screen mode in the future.
89-
//- (CCScene*) startScene
90-
//{
91-
//// return [MainMenu scene];
92-
// CCScene *scene = [CCScene node];
93-
//
94-
//// // Landscape
95-
//// {
96-
//// // iPad
97-
//// CCNode *node = [CCNodeColor nodeWithColor:[CCColor greenColor] width:512 height:384];
98-
//// node.position = ccp(28, 0);
99-
//// [scene addChild:node];
100-
//// }{
101-
//// // iPhone5
102-
//// CCNode *node = [CCNodeColor nodeWithColor:[CCColor redColor] width:568 height:320];
103-
//// node.position = ccp(0, 32);
104-
//// [scene addChild:node];
105-
//// }{
106-
//// // iPhone
107-
//// CCNode *node = [CCNodeColor nodeWithColor:[CCColor blueColor] width:480 height:320];
108-
//// node.position = ccp(44, 32);
109-
//// [scene addChild:node];
110-
//// }
111-
//
112-
// // Portrait
113-
// {
114-
// // iPad
115-
// CCNode *node = [CCNodeColor nodeWithColor:[CCColor greenColor] width:384 height:512];
116-
// node.position = ccp(0, 28);
117-
// [scene addChild:node];
118-
// }{
119-
// // iPhone5
120-
// CCNode *node = [CCNodeColor nodeWithColor:[CCColor redColor] width:320 height:568];
121-
// node.position = ccp(32, 0);
122-
// [scene addChild:node];
123-
// }{
124-
// // iPhone
125-
// CCNode *node = [CCNodeColor nodeWithColor:[CCColor blueColor] width:320 height:480];
126-
// node.position = ccp(32, 44);
127-
// [scene addChild:node];
128-
// }
129-
//
130-
// return scene;
131-
//}
132148

133149
@end

cocos2d-ui-tests/ios/main.m

Lines changed: 0 additions & 17 deletions
This file was deleted.

cocos2d-ui-tests/osx/AppDelegate.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)