const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { // if have set the zip file path,return the relative path of zip file if (strlen(s_pszZipFilePath) != 0) { return getDiffResolutionPath(pszRelativePath); } // get the user data path and append relative path to it if (strlen(s_pszResourcePath) == 0) { const char* pAppDataPath = CCApplication::sharedApplication().getAppDataPath(); strcpy(s_pszResourcePath, pAppDataPath); } CCString * pRet = new CCString(); pRet->autorelease(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':') || (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/')) { pRet->m_sString = pszRelativePath; } else { pRet->m_sString = s_pszResourcePath; pRet->m_sString += pszRelativePath; } return getDiffResolutionPath(pRet->m_sString.c_str()); }
const char* BSStringByAppending(const char *pStr, const char *pAppend) { char buff[255] = {0}; sprintf(buff, "%s%s", pStr, pAppend); CCString* str = new CCString(buff); str->autorelease(); return str->getCString(); }
const char* BSStringFromInteger(int pVal) { char buff[12] = {0}; sprintf(buff, "%i", pVal); CCString* str = new CCString(buff); str->autorelease(); return str->getCString(); }
bool DragLayer::init() { if (!CCLayerColor::init()) { return false; } //循环生成tableView数据 CCString *str = NULL; for (int i = 0; i < 40; i++) { str = new CCString("cellBg.jpg"); m_data->addObject(str); str->autorelease(); } //添加tableView到主界面上 CCSprite* cellBg = CCSprite::create("cellBg.jpg"); m_cellSize = CCSizeMake(cellBg->getContentSize().width, cellBg->getContentSize().height); SNSTableView *tableView = SNSTableView::create(CCRectMake(0, 20, m_cellSize.width * 2, m_cellSize.height * 4), TableViewTypeHorizontal); tableView->setDelegate(this); tableView->setDatasource(this); tableView->setPageEnable(true); this->addChild(tableView); //添加碰撞块 m_destinationLayer = CCLayerColor::create(ccc4(255, 255, 255, 255)); m_destinationLayer->setContentSize(CCSizeMake(93, 130)); m_destinationLayer->setPosition(ccp(360, 200)); m_destinationLayer->setAnchorPoint(ccp(0.5f, 0.5f)); this->addChild(m_destinationLayer); this->setTouchEnabled(true); return true; }
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { IwAssert(GAME, pszRelativePath); CCString * pRet = new CCString(); pRet->autorelease(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { pRet->m_sString = pszRelativePath; } else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/') { char szDriver[3] = {s_pszResourcePath[0], s_pszResourcePath[1], 0}; pRet->m_sString = szDriver; pRet->m_sString += pszRelativePath; } else { pRet->m_sString = s_pszResourcePath; pRet->m_sString += pszRelativePath; } return pRet->m_sString.c_str(); }
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile) { std::string relativeFile = pszRelativeFile; CCString *pRet = new CCString(); pRet->autorelease(); pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1); pRet->m_sString += pszFilename; return pRet->m_sString.c_str(); }
/* * 文字列を設定。 */ void UICacheList::setString( string key, string name, string str ) { UICache* cache = getCache( key ); CCString* cstr = new CCString( str.c_str() ); cstr->autorelease(); cache->setStringObject( name, cstr ); }
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile) { _CheckPath(); // std::string relativeFile = fullPathFromRelativePath(pszRelativeFile); std::string relativeFile = pszRelativeFile; CCString *pRet = new CCString(); pRet->autorelease(); pRet->m_sString = relativeFile.substr(0, relativeFile.find_last_of("/\\") + 1); pRet->m_sString += pszFilename; return pRet->m_sString.c_str(); }
const char* CCBMFontConfiguration::description(void) { char* pBuf = new char[100]; sprintf(pBuf, "<CCBMFontConfiguration = %08X | Glphys:%d Kernings:%d | Image = %s>", this, HASH_COUNT(m_pFontDefDictionary), HASH_COUNT(m_pKerningDictionary), m_sAtlasName.c_str()); CCString* pRet = new CCString(pBuf); pRet->autorelease(); CC_SAFE_DELETE_ARRAY(pBuf); return pRet->m_sString.c_str(); }
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType) { _CheckPath(); CCString * pRet = new CCString(); pRet->autorelease(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { // path start with "x:", is absolute path pRet->m_sString = pszRelativePath; } else if (strlen(pszRelativePath) > 0 && ('/' == pszRelativePath[0] || '\\' == pszRelativePath[0])) { // path start with '/' or '\', is absolute path without driver name char szDriver[3] = {s_pszResourcePath[0], s_pszResourcePath[1], 0}; pRet->m_sString = szDriver; pRet->m_sString += pszRelativePath; } else { pRet->m_sString = s_pszResourcePath; pRet->m_sString += pszRelativePath; } //#if (CC_IS_RETINA_DISPLAY_SUPPORTED) // if (CC_CONTENT_SCALE_FACTOR() != 1.0f) // { // std::string hiRes = pRet->m_sString.c_str(); // std::string::size_type pos = hiRes.find_last_of("/\\"); // std::string::size_type dotPos = hiRes.find_last_of("."); // // if (std::string::npos != dotPos && dotPos > pos) // { // hiRes.insert(dotPos, CC_RETINA_DISPLAY_FILENAME_SUFFIX); // } // else // { // hiRes.append(CC_RETINA_DISPLAY_FILENAME_SUFFIX); // } // DWORD attrib = GetFileAttributesA(hiRes.c_str()); // // if (attrib != INVALID_FILE_ATTRIBUTES && ! (FILE_ATTRIBUTE_DIRECTORY & attrib)) // { // pRet->m_sString.swap(hiRes); // } // } //#endif if (pResolutionType) { *pResolutionType = kCCResolutioniPhone; } return pRet->m_sString.c_str(); }
const char* getLocalLanguage() { JniMethodInfo minfo; CCAssert(JniHelper::getStaticMethodInfo(minfo, "org/cocos2dx/lib/Cocos2dxHelper", "getCurrentLanguage", "()Ljava/lang/String;"), "Function doesn't exist"); jstring str = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID); minfo.env->DeleteLocalRef(minfo.classID); CCString *ret = new CCString(JniHelper::jstring2string(str).c_str()); ret->autorelease(); minfo.env->DeleteLocalRef(str); return ret->m_sString.c_str(); }
const char* getDiffResolutionPath(const char *pszPath) { CCString *pRet = new CCString(pszPath); pRet->autorelease(); do { TApplication* pApp = TApplication::GetCurrentApplication(); CC_BREAK_IF(!pApp); // get the Resolution int nScreenWidth = pApp->GetScreenWidth(); int nScreenHeight = pApp->GetScreenHeight(); // it's default resolution, do nothing CC_BREAK_IF(nScreenWidth == 320 && nScreenHeight == 480); if (nScreenWidth == 480 && nScreenHeight == 800) { // it's WVGA CC_BREAK_IF(pRet->m_sString.find("@WVGA") != -1); std::string filePathWithoutExtension = pszPath; std::string extension = ""; std::string filePath = pszPath; int nExPos = filePath.find_last_of("."); if (nExPos != -1) { filePathWithoutExtension = filePath.substr(0, nExPos); extension = filePath.substr(nExPos); } // new path, add "@WVGA" before the extension pRet->m_sString = filePathWithoutExtension + "@WVGA" + extension; // not find the resource of new path,use the original path if (! isResourceExist(pRet->m_sString.c_str())) { pRet->m_sString = filePath; } } else { // not support resolution CCAssert(0, "it's not supportted resolution."); } } while (0); return pRet->m_sString.c_str(); }
const char* getCurrentLanguageJNI() { JniMethodInfo t; if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getCurrentLanguage", "()Ljava/lang/String;")) { jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID); t.env->DeleteLocalRef(t.classID); CCString *ret = new CCString(JniHelper::jstring2string(str).c_str()); ret->autorelease(); t.env->DeleteLocalRef(str); return ret->m_sString.c_str(); } return 0; }
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { // It works like this: if the relative path already includes the resource path // it will be returned as it is const std::string relPath = pszRelativePath; if (relPath.find(s_strResourcePath) == std::string::npos) { CCString *pRet = new CCString(); pRet->autorelease(); pRet->m_sString = s_strResourcePath + pszRelativePath; return pRet->m_sString.c_str(); } else { return pszRelativePath; } }
void CCGreeRequestDialog::handleDialogCompleted(int count, const char** users){ CCGreeRequestDialogDelegate *delegate = CCGreePlatform::getRequestDialogDelegate(); if(delegate != NULL){ CCArray *userStringArray = new CCArray(); if(users != NULL){ for(int i = 0; i < count; i++){ CCString *str = new CCString(users[i]); str->autorelease(); userStringArray->addObject(str); } } delegate->requestDialogCompleted(this, userStringArray); delegate->requestDialogClosed(this); } }
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { _CheckPath(); CCString * pRet = new CCString(); pRet->autorelease(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { pRet->m_sString = pszRelativePath; } else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/') { char szDriver[3] = {s_pszResourcePath[0], s_pszResourcePath[1], 0}; pRet->m_sString = szDriver; pRet->m_sString += pszRelativePath; } else { pRet->m_sString = s_pszResourcePath; pRet->m_sString += pszRelativePath; } #if (CC_IS_RETINA_DISPLAY_SUPPORTED) if (CC_CONTENT_SCALE_FACTOR() != 1.0f) { std::string hiRes = pRet->m_sString.c_str(); std::string::size_type pos = hiRes.find_last_of("/\\"); std::string::size_type dotPos = hiRes.find_last_of("."); if (std::string::npos != dotPos && dotPos > pos) { hiRes.insert(dotPos, CC_RETINA_DISPLAY_FILENAME_SUFFIX); } else { hiRes.append(CC_RETINA_DISPLAY_FILENAME_SUFFIX); } DWORD attrib = GetFileAttributesA(hiRes.c_str()); if (attrib != INVALID_FILE_ATTRIBUTES && ! (FILE_ATTRIBUTE_DIRECTORY & attrib)) { pRet->m_sString.swap(hiRes); } } #endif return pRet->m_sString.c_str(); }
////////////////////////////////////////////////////////////////////////// // handle get current language ////////////////////////////////////////////////////////////////////////// const char* getCurrentLanguageJNI() { JniMethodInfo t; if (JniHelper::getStaticMethodInfo(t , "org/cocos2dx/lib/Cocos2dxActivity" , "getCurrentLanguage" , "()Ljava/lang/String;")) { jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID); t.env->DeleteLocalRef(t.classID); CCString *ret = new CCString(JniHelper::jstring2string(str).c_str()); ret->autorelease(); t.env->DeleteLocalRef(str); LOGD("language name %s", ret.c_str()); return ret->m_sString.c_str(); } return 0; }
void CCButton::setTitleForState(const char * mTitle,CCControlState mState) { if (mTitle == NULL) { return; } CCLabelTTF * mTepNode = (CCLabelTTF *) (this->getChildByTag(CCButtonTitleTag)); if (mTepNode != NULL) { mTepNode->setString(mTitle); } else { CCSize mContentSize = this->getContentSize(); mTepNode = CCLabelTTF::labelWithString(mTitle, "Arial", 14); mTepNode->setTag(CCButtonTitleTag); this->setPosition(ccp(mContentSize.width/2.0,mContentSize.height/2.0)); this->addChild(mTepNode, CCButtonZorder2); } CCSize mContentSize = mTepNode->getContentSize(); mContentSize.width += 8; mContentSize.height += 6; this->setContentSize(mContentSize); CCString * mTepNodeInList = (CCString *) (this->titleCCStrings->objectForKey((int)mState)); if (mTepNodeInList != NULL) { std::string mTepString = mTepNodeInList->toStdString(); std::string mTepCompareString(mTitle); if (mTepString.compare(mTepCompareString) == 0) { return; } this->titleCCStrings->removeObjectForKey((int)mState); } //save string CCString * mNormalCCString = new CCString(mTitle); mNormalCCString->autorelease(); this->titleCCStrings->setObject(mNormalCCString,mState); }
CCString* CCString::create(const std::string& str) { CCString* pRet = new CCString(str); pRet->autorelease(); return pRet; }
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType) { _CheckPath(); CCString * pRet = new CCString(); pRet->autorelease(); if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':')) { // path start with "x:", is absolute path pRet->m_sString = pszRelativePath; } else if (strlen(pszRelativePath) > 0 && ('/' == pszRelativePath[0] || '\\' == pszRelativePath[0])) { // path start with '/' or '\', is absolute path without driver name char szDriver[3] = {s_pszResourcePath[0], s_pszResourcePath[1], 0}; pRet->m_sString = szDriver; pRet->m_sString += pszRelativePath; } else { pRet->m_sString = s_pszResourcePath; pRet->m_sString += pszRelativePath; } // is ipad? CCSize winSize = CCDirector::sharedDirector()->getWinSize(); bool isIpad = (winSize.width == 1024 || winSize.height == 768); std::string hiRes = pRet->m_sString.c_str(); std::string::size_type pos = hiRes.find_last_of("/\\"); std::string::size_type dotPos = hiRes.find_last_of("."); *pResolutionType = kCCResolutioniPhone; if (isIpad) { if (CC_CONTENT_SCALE_FACTOR() == 1.0f) { // ipad if (std::string::npos != dotPos && dotPos > pos) { hiRes.insert(dotPos, CC_IPAD_FILENAME_SUFFIX); } else { hiRes.append(CC_IPAD_FILENAME_SUFFIX); } *pResolutionType = kCCResolutioniPad; } else { // ipad retina if (std::string::npos != dotPos && dotPos > pos) { hiRes.insert(dotPos, CC_IPAD_DISPLAY_RETINA_SUPPFIX); } else { hiRes.append(CC_IPAD_DISPLAY_RETINA_SUPPFIX); } *pResolutionType = kCCResolutioniPadRetinaDisplay; } } else { if (CC_CONTENT_SCALE_FACTOR() != 1.0f) { // iphone retina if (std::string::npos != dotPos && dotPos > pos) { hiRes.insert(dotPos, CC_RETINA_DISPLAY_FILENAME_SUFFIX); } else { hiRes.append(CC_RETINA_DISPLAY_FILENAME_SUFFIX); } *pResolutionType = kCCResolutioniPhoneRetinaDisplay; } } DWORD attrib = GetFileAttributesA(hiRes.c_str()); if (attrib != INVALID_FILE_ATTRIBUTES && ! (FILE_ATTRIBUTE_DIRECTORY & attrib)) { pRet->m_sString.swap(hiRes); } return pRet->m_sString.c_str(); }
// the XML parser calls here with all the elements void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts) { CC_UNUSED_PARAM(ctx); CCTMXMapInfo *pTMXMapInfo = this; std::string elementName = (char*)name; std::map<std::string, std::string> *attributeDict = new std::map<std::string, std::string>(); if (atts && atts[0]) { for(int i = 0; atts[i]; i += 2) { std::string key = (char*)atts[i]; std::string value = (char*)atts[i+1]; attributeDict->insert(pair<std::string, std::string>(key, value)); } } if (elementName == "map") { std::string version = valueForKey("version", attributeDict); if ( version != "1.0") { CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %s", version.c_str()); } std::string orientationStr = valueForKey("orientation", attributeDict); if (orientationStr == "orthogonal") pTMXMapInfo->setOrientation(CCTMXOrientationOrtho); else if (orientationStr == "isometric") pTMXMapInfo->setOrientation(CCTMXOrientationIso); else if(orientationStr == "hexagonal") pTMXMapInfo->setOrientation(CCTMXOrientationHex); else CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", pTMXMapInfo->getOrientation()); CCSize s; s.width = (float)atof(valueForKey("width", attributeDict)); s.height = (float)atof(valueForKey("height", attributeDict)); pTMXMapInfo->setMapSize(s); s.width = (float)atof(valueForKey("tilewidth", attributeDict)); s.height = (float)atof(valueForKey("tileheight", attributeDict)); pTMXMapInfo->setTileSize(s); // The parent element is now "map" pTMXMapInfo->setParentElement(TMXPropertyMap); } else if (elementName == "tileset") { // If this is an external tileset then start parsing that std::string externalTilesetFilename = valueForKey("source", attributeDict); if (externalTilesetFilename != "") { // Tileset file will be relative to the map file. So we need to convert it to an absolute path if (m_sTMXFileName.find_last_of("/") != string::npos) { string dir = m_sTMXFileName.substr(0, m_sTMXFileName.find_last_of("/") + 1); externalTilesetFilename = dir + externalTilesetFilename; } else { externalTilesetFilename = m_sResources + "/" + externalTilesetFilename; } externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathForFilename(externalTilesetFilename.c_str()); m_uCurrentFirstGID = (unsigned int)atoi(valueForKey("firstgid", attributeDict)); pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str()); } else { CCTMXTilesetInfo *tileset = new CCTMXTilesetInfo(); tileset->m_sName = valueForKey("name", attributeDict); if (m_uCurrentFirstGID == 0) { tileset->m_uFirstGid = (unsigned int)atoi(valueForKey("firstgid", attributeDict)); } else { tileset->m_uFirstGid = m_uCurrentFirstGID; m_uCurrentFirstGID = 0; } tileset->m_uSpacing = (unsigned int)atoi(valueForKey("spacing", attributeDict)); tileset->m_uMargin = (unsigned int)atoi(valueForKey("margin", attributeDict)); CCSize s; s.width = (float)atof(valueForKey("tilewidth", attributeDict)); s.height = (float)atof(valueForKey("tileheight", attributeDict)); tileset->m_tTileSize = s; pTMXMapInfo->getTilesets()->addObject(tileset); tileset->release(); } } else if (elementName == "tile") { CCTMXTilesetInfo* info = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject(); CCDictionary *dict = new CCDictionary(); pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict))); pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID()); CC_SAFE_RELEASE(dict); pTMXMapInfo->setParentElement(TMXPropertyTile); } else if (elementName == "layer") { CCTMXLayerInfo *layer = new CCTMXLayerInfo(); layer->m_sName = valueForKey("name", attributeDict); CCSize s; s.width = (float)atof(valueForKey("width", attributeDict)); s.height = (float)atof(valueForKey("height", attributeDict)); layer->m_tLayerSize = s; std::string visible = valueForKey("visible", attributeDict); layer->m_bVisible = !(visible == "0"); std::string opacity = valueForKey("opacity", attributeDict); if( opacity != "" ) { layer->m_cOpacity = (unsigned char)(255 * atof(opacity.c_str())); } else { layer->m_cOpacity = 255; } float x = (float)atof(valueForKey("x", attributeDict)); float y = (float)atof(valueForKey("y", attributeDict)); layer->m_tOffset = ccp(x,y); pTMXMapInfo->getLayers()->addObject(layer); layer->release(); // The parent element is now "layer" pTMXMapInfo->setParentElement(TMXPropertyLayer); } else if (elementName == "objectgroup") { CCTMXObjectGroup *objectGroup = new CCTMXObjectGroup(); objectGroup->setGroupName(valueForKey("name", attributeDict)); CCPoint positionOffset; positionOffset.x = (float)atof(valueForKey("x", attributeDict)) * pTMXMapInfo->getTileSize().width; positionOffset.y = (float)atof(valueForKey("y", attributeDict)) * pTMXMapInfo->getTileSize().height; objectGroup->setPositionOffset(positionOffset); pTMXMapInfo->getObjectGroups()->addObject(objectGroup); objectGroup->release(); // The parent element is now "objectgroup" pTMXMapInfo->setParentElement(TMXPropertyObjectGroup); } else if (elementName == "image") { CCTMXTilesetInfo* tileset = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject(); // build full path std::string imagename = valueForKey("source", attributeDict); if (m_sTMXFileName.find_last_of("/") != string::npos) { string dir = m_sTMXFileName.substr(0, m_sTMXFileName.find_last_of("/") + 1); tileset->m_sSourceImage = dir + imagename; } else { tileset->m_sSourceImage = m_sResources + (m_sResources.size() ? "/" : "") + imagename; } } else if (elementName == "data") { std::string encoding = valueForKey("encoding", attributeDict); std::string compression = valueForKey("compression", attributeDict); if( encoding == "base64" ) { int layerAttribs = pTMXMapInfo->getLayerAttribs(); pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64); pTMXMapInfo->setStoringCharacters(true); if( compression == "gzip" ) { layerAttribs = pTMXMapInfo->getLayerAttribs(); pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip); } else if (compression == "zlib") { layerAttribs = pTMXMapInfo->getLayerAttribs(); pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib); } CCAssert( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" ); } CCAssert( pTMXMapInfo->getLayerAttribs() != TMXLayerAttribNone, "TMX tile map: Only base64 and/or gzip/zlib maps are supported" ); } else if (elementName == "object") { char buffer[32] = {0}; CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject(); // The value for "type" was blank or not a valid class name // Create an instance of TMXObjectInfo to store the object and its properties CCDictionary *dict = new CCDictionary(); // Parse everything automatically const char* pArray[] = {"name", "type", "width", "height", "gid"}; for(size_t i = 0; i < sizeof(pArray)/sizeof(pArray[0]); ++i ) { const char* key = pArray[i]; CCString* obj = new CCString(valueForKey(key, attributeDict)); if( obj ) { obj->autorelease(); dict->setObject(obj, key); } } // But X and Y since they need special treatment // X const char* value = valueForKey("x", attributeDict); if (value) { int x = atoi(value) + (int)objectGroup->getPositionOffset().x; sprintf(buffer, "%d", x); CCString* pStr = new CCString(buffer); pStr->autorelease(); dict->setObject(pStr, "x"); } // Y value = valueForKey("y", attributeDict); if (value) { int y = atoi(value) + (int)objectGroup->getPositionOffset().y; // Correct y position. (Tiled uses Flipped, cocos2d uses Standard) y = (int)(m_tMapSize.height * m_tTileSize.height) - y - atoi(valueForKey("height", attributeDict)); sprintf(buffer, "%d", y); CCString* pStr = new CCString(buffer); pStr->autorelease(); dict->setObject(pStr, "y"); } // Add the object to the objectGroup objectGroup->getObjects()->addObject(dict); dict->release(); // The parent element is now "object" pTMXMapInfo->setParentElement(TMXPropertyObject); } else if (elementName == "property") { if ( pTMXMapInfo->getParentElement() == TMXPropertyNone ) { CCLOG( "TMX tile map: Parent element is unsupported. Cannot add property named '%s' with value '%s'", valueForKey("name", attributeDict), valueForKey("value",attributeDict) ); } else if ( pTMXMapInfo->getParentElement() == TMXPropertyMap ) { // The parent element is the map CCString *value = new CCString(valueForKey("value", attributeDict)); std::string key = valueForKey("name", attributeDict); pTMXMapInfo->getProperties()->setObject(value, key.c_str()); value->release(); } else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer ) { // The parent element is the last layer CCTMXLayerInfo* layer = (CCTMXLayerInfo*)pTMXMapInfo->getLayers()->lastObject(); CCString *value = new CCString(valueForKey("value", attributeDict)); std::string key = valueForKey("name", attributeDict); // Add the property to the layer layer->getProperties()->setObject(value, key.c_str()); value->release(); } else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup ) { // The parent element is the last object group CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject(); CCString *value = new CCString(valueForKey("value", attributeDict)); const char* key = valueForKey("name", attributeDict); objectGroup->getProperties()->setObject(value, key); value->release(); } else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject ) { // The parent element is the last object CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject(); CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject(); const char* propertyName = valueForKey("name", attributeDict); CCString *propertyValue = new CCString(valueForKey("value", attributeDict)); dict->setObject(propertyValue, propertyName); propertyValue->release(); } else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile ) { CCDictionary* dict = (CCDictionary*)pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID()); const char* propertyName = valueForKey("name", attributeDict); CCString *propertyValue = new CCString(valueForKey("value", attributeDict)); dict->setObject(propertyValue, propertyName); propertyValue->release(); } } else if (elementName == "polygon") { // find parent object's dict and add polygon-points to it CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject(); CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject(); // get points value string const char* value = valueForKey("points", attributeDict); if(value) { CCArray* pPointsArray = new CCArray; // parse points string into a space-separated set of points stringstream pointsStream(value); string pointPair; while(std::getline(pointsStream, pointPair, ' ')) { // parse each point combo into a comma-separated x,y point stringstream pointStream(pointPair); string xStr,yStr; char buffer[32] = {0}; CCDictionary* pPointDict = new CCDictionary; // set x if(std::getline(pointStream, xStr, ',')) { int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x; sprintf(buffer, "%d", x); CCString* pStr = new CCString(buffer); pStr->autorelease(); pPointDict->setObject(pStr, "x"); } // set y if(std::getline(pointStream, yStr, ',')) { int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y; sprintf(buffer, "%d", y); CCString* pStr = new CCString(buffer); pStr->autorelease(); pPointDict->setObject(pStr, "y"); } // add to points array pPointsArray->addObject(pPointDict); pPointDict->release(); } dict->setObject(pPointsArray, "points"); pPointsArray->release(); } } else if (elementName == "polyline") { // find parent object's dict and add polyline-points to it // CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject(); // CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject(); // TODO: dict->setObject:[attributeDict objectForKey:@"points"] forKey:@"polylinePoints"]; CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject(); CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject(); // get points value string const char* value = valueForKey("points", attributeDict); if(value) { CCArray* pPointsArray = new CCArray; // parse points string into a space-separated set of points stringstream pointsStream(value); string pointPair; while(std::getline(pointsStream, pointPair, ' ')) { // parse each point combo into a comma-separated x,y point stringstream pointStream(pointPair); string xStr,yStr; char buffer[32] = {0}; CCDictionary* pPointDict = new CCDictionary; // set x if(std::getline(pointStream, xStr, ',')) { int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x; sprintf(buffer, "%d", x); CCString* pStr = new CCString(buffer); pStr->autorelease(); pPointDict->setObject(pStr, "x"); } // set y if(std::getline(pointStream, yStr, ',')) { int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y; sprintf(buffer, "%d", y); CCString* pStr = new CCString(buffer); pStr->autorelease(); pPointDict->setObject(pStr, "y"); } // add to points array pPointsArray->addObject(pPointDict); pPointDict->release(); } dict->setObject(pPointsArray, "points"); pPointsArray->release(); } } if (attributeDict) { attributeDict->clear(); delete attributeDict; } }
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { CCString *pRet = new CCString(); pRet->autorelease(); pRet->m_sString = s_strResourcePath + pszRelativePath; return pRet->m_sString.c_str(); }
static CCString* newCCString(const char* string) { CCString* str = new CCString(string); str->autorelease(); return str; }
CCString* CCStoreScene::newCCString(const char* string) { CCString* str = new CCString(string); str->autorelease(); return str; }
CCString* CCString::stringWithString(const std::string& pStr) { CCString* pRet = new CCString(pStr); pRet->autorelease(); return pRet; }
CCString* CCString::stringWithCString(const char* pStr) { CCString* pRet = new CCString(pStr); pRet->autorelease(); return pRet; }