mirror of https://github.com/axmolengine/axmol.git
169 lines
5.3 KiB
Plaintext
169 lines
5.3 KiB
Plaintext
/****************************************************************************
|
|
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>
|
|
#include <algorithm>
|
|
#include "platform/CCFileUtils.h"
|
|
#include "CCGeometry.h"
|
|
#include "CCDirector.h"
|
|
#import "CCDirectorCaller.h"
|
|
|
|
NS_CC_BEGIN
|
|
|
|
CCApplication* CCApplication::sm_pSharedApplication = 0;
|
|
|
|
CCApplication::CCApplication()
|
|
{
|
|
CCAssert(! sm_pSharedApplication, "sm_pSharedApplication already exist");
|
|
sm_pSharedApplication = this;
|
|
}
|
|
|
|
CCApplication::~CCApplication()
|
|
{
|
|
CCAssert(this == sm_pSharedApplication, "sm_pSharedApplication != this");
|
|
sm_pSharedApplication = 0;
|
|
}
|
|
|
|
int CCApplication::run()
|
|
{
|
|
if (/*initInstance() &&*/ applicationDidFinishLaunching())
|
|
{
|
|
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
|
{
|
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
|
|
}
|
|
|
|
TargetPlatform CCApplication::getTargetPlatform()
|
|
{
|
|
return kTargetMacOS;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// static member function
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
CCApplication* CCApplication::sharedApplication()
|
|
{
|
|
CCAssert(sm_pSharedApplication, "sm_pSharedApplication not set");
|
|
return sm_pSharedApplication;
|
|
}
|
|
|
|
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;
|
|
}
|
|
else if ([languageCode isEqualToString:@"fr"]){
|
|
ret = kLanguageFrench;
|
|
}
|
|
else if ([languageCode isEqualToString:@"it"]){
|
|
ret = kLanguageItalian;
|
|
}
|
|
else if ([languageCode isEqualToString:@"de"]){
|
|
ret = kLanguageGerman;
|
|
}
|
|
else if ([languageCode isEqualToString:@"es"]){
|
|
ret = kLanguageSpanish;
|
|
}
|
|
else if ([languageCode isEqualToString:@"ru"]){
|
|
ret = kLanguageRussian;
|
|
}
|
|
else if ([languageCode isEqualToString:@"ko"]){
|
|
ret = kLanguageKorean;
|
|
}
|
|
else if ([languageCode isEqualToString:@"ja"]){
|
|
ret = kLanguageJapanese;
|
|
}
|
|
else if ([languageCode isEqualToString:@"hu"]){
|
|
ret = kLanguageHungarian;
|
|
}
|
|
else if ([languageCode isEqualToString:@"pt"])
|
|
{
|
|
ret = kLanguagePortuguese;
|
|
}
|
|
else if ([languageCode isEqualToString:@"ar"])
|
|
{
|
|
ret = kLanguageArabic;
|
|
}
|
|
else if ([languageCode isEqualToString:@"nb"]){
|
|
ret = kLanguageNorwegian;
|
|
}
|
|
else if ([languageCode isEqualToString:@"pl"]){
|
|
ret = kLanguagePolish;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void CCApplication::setResourceRootPath(const std::string& rootResDir)
|
|
{
|
|
_resourceRootPath = rootResDir;
|
|
if (_resourceRootPath[_resourceRootPath.length() - 1] != '/')
|
|
{
|
|
_resourceRootPath += '/';
|
|
}
|
|
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
|
|
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
|
searchPaths.insert(searchPaths.begin(), _resourceRootPath);
|
|
pFileUtils->setSearchPaths(searchPaths);
|
|
}
|
|
|
|
const std::string& CCApplication::getResourceRootPath(void)
|
|
{
|
|
return _resourceRootPath;
|
|
}
|
|
|
|
void CCApplication::setStartupScriptFilename(const std::string& startupScriptFile)
|
|
{
|
|
_startupScriptFilename = startupScriptFile;
|
|
std::replace(_startupScriptFilename.begin(), _startupScriptFilename.end(), '\\', '/');
|
|
}
|
|
|
|
const std::string& CCApplication::getStartupScriptFilename(void)
|
|
{
|
|
return _startupScriptFilename;
|
|
}
|
|
|
|
NS_CC_END
|