bool CCTextureFontPageFile::load() { CCText textureFile( name ); textureFile += ".png"; CCResourceType resourceType = CCFileManager::FindFile( textureFile.buffer ); if( resourceType != Resource_Unknown ) { texturePageIndex = gEngine->textureManager->assignTextureIndex( textureFile.buffer, resourceType, true, true, true ); CCText csvFile = name; csvFile += ".csv"; // Load the descriptor file CCText textData; CCFileManager::GetFile( csvFile.buffer, textData, resourceType ); CCList<char> lettersSplit; textData.split( lettersSplit, "\n" ); CCText rawLetterData; CCList<char> letterDataSplit; for( int i=0; i<lettersSplit.length; ++i ) { const char *raw = lettersSplit.list[i]; rawLetterData.set( raw ); letterDataSplit.clear(); rawLetterData.split( letterDataSplit, "," ); ASSERT( letterDataSplit.length == 4 ); Letter &letter = letters[i]; const char *x1 = letterDataSplit.list[0]; const char *y1 = letterDataSplit.list[1]; const char *x2 = letterDataSplit.list[2]; const char *y2 = letterDataSplit.list[3]; letter.start.x = (float)atof( x1 ); letter.start.y = (float)atof( y1 ); letter.end.x = (float)atof( x2 ); letter.end.y = (float)atof( y2 ); // 16.0f because there's 16 tiles per font page letter.size.width = ( letter.end.x - letter.start.x ) * 16.0f; letter.size.height = ( letter.end.y - letter.start.y ) * 16.0f; } return true; } return false; }
void CCVector3::set(const char *text) { CCText data = text; CCPtrList<char> split; data.split( split, "," ); CCASSERT( split.length == 3 ); if( split.length == 3 ) { x = (float)atof( split.list[0] ); y = (float)atof( split.list[1] ); z = (float)atof( split.list[2] ); if( x != x ) { CCASSERT( false ); x = 0.0f; } if( y != y ) { y = 0.0f; } if( z != z ) { z = 0.0f; } } }
void CCText::SetLastWord(const char *inBuffer, CCText &outText) { CCText nameData = inBuffer; CCList<char> *nameDataSplit = nameData.split( " " ); ASSERT( nameDataSplit->length > 0 ); outText = nameDataSplit->list[nameDataSplit->length-1]; DELETE_POINTER( nameDataSplit ); }
void CCText::splitAfter(CCText source, const char *after) { CCList<char> *list1 = source.split( after, true ); if( list1->length > 1 ) { set( list1->list[1] ); for( int i=2; i<list1->length; ++i ) { *this += after; *this += list1->list[i]; } } DELETE_POINTER( list1 ); }
const bool CCTextureFontPageFile::load(const char *name, const CCResourceType resourceType, const bool generateMipMap) { CCText textureFilename( name ); textureFilename += ".png"; texturePageIndex = gEngine->textureManager->assignTextureIndex( textureFilename.buffer, resourceType, true, generateMipMap ); CCText filename( name ); filename += ".data"; // Load the descriptor file char *fileData = NULL; CCFileManager::getPackagedFile( filename.buffer, &fileData ); CCText textData( fileData ); FREE_POINTER( fileData ); CCList<char> *lettersSplit = textData.split( "\n" ); CCText rawLetterData; for( int i=0; i<lettersSplit->length; ++i ) { const char *raw = lettersSplit->list[i]; rawLetterData.set( raw ); CCList<char> *letterDataSplit = rawLetterData.split( "," ); ASSERT( letterDataSplit->length == 4 ); Letters &letter = letters[i]; letter.start.x = (float)atof( letterDataSplit->list[0] ); letter.start.y = (float)atof( letterDataSplit->list[1] ); letter.end.x = (float)atof( letterDataSplit->list[2] ); letter.end.y = (float)atof( letterDataSplit->list[3] ); // 16.0f because there's 16 tiles per font page letter.size.width = ( letter.end.x - letter.start.x ) * 16.0f; letter.size.height = ( letter.end.y - letter.start.y ) * 16.0f; DELETE_POINTER( letterDataSplit ); } DELETE_POINTER( lettersSplit ); return true; }
void CCText::splitBefore(CCText source, const char *before) { CCList<char> *list1 = source.split( before, true ); set( list1->list[0] ); DELETE_POINTER( list1 ); }