2012-07-21 12:23:40 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#import "CCApplication.h"
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#import "CCGeometry.h"
|
2012-07-22 02:46:42 +08:00
|
|
|
#include "CCDirector.h"
|
2012-07-21 12:23:40 +08:00
|
|
|
#import "CCDirectorCaller.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN;
|
|
|
|
|
|
|
|
CCApplication* CCApplication::sm_pSharedApplication = 0;
|
|
|
|
|
|
|
|
CCApplication::CCApplication()
|
|
|
|
{
|
2012-09-04 11:16:59 +08:00
|
|
|
CCAssert(! sm_pSharedApplication, "sm_pSharedApplication already exist");
|
2012-07-21 12:23:40 +08:00
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCApplication::~CCApplication()
|
|
|
|
{
|
2012-09-04 11:16:59 +08:00
|
|
|
CCAssert(this == sm_pSharedApplication, "sm_pSharedApplication != this");
|
2012-07-21 12:23:40 +08:00
|
|
|
sm_pSharedApplication = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCApplication::run()
|
|
|
|
{
|
|
|
|
if (/*initInstance() &&*/ applicationDidFinishLaunching())
|
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
|
|
|
|
}
|
|
|
|
|
2012-08-16 10:21:15 +08:00
|
|
|
TargetPlatform CCApplication::getTargetPlatform()
|
2012-07-21 12:23:40 +08:00
|
|
|
{
|
2012-08-16 10:21:15 +08:00
|
|
|
return kTargetMacOS;
|
2012-08-09 14:34:20 +08:00
|
|
|
}
|
|
|
|
|
2012-07-21 12:23:40 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-21 15:28:43 +08:00
|
|
|
CCApplication* CCApplication::sharedApplication()
|
2012-07-21 12:23:40 +08:00
|
|
|
{
|
2012-09-04 11:16:59 +08:00
|
|
|
CCAssert(sm_pSharedApplication, "sm_pSharedApplication not set");
|
2012-08-21 15:28:43 +08:00
|
|
|
return sm_pSharedApplication;
|
2012-07-21 12:23:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ccLanguageType CCApplication::getCurrentLanguage()
|
|
|
|
{
|
|
|
|
// get the current language and country config
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString *currentLanguage = [languages objectAtIndex:0];
|
|
|
|
|
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString * languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
|
|
|
|
|
|
|
ccLanguageType ret = kLanguageEnglish;
|
|
|
|
if ([languageCode isEqualToString:@"zh"])
|
|
|
|
{
|
|
|
|
ret = kLanguageChinese;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"en"])
|
|
|
|
{
|
|
|
|
ret = kLanguageEnglish;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END;
|