Exemplo n.º 1
0
vid
	NSPathDirectoryEnumerator::nextObject()
{
	self->directoryIndex++;
	NSDictionary* dict = (NSDictionary*)self->directory->nextObject();
	if(nil == dict)
	{
		return nil;
	}else{
		self->currentObject = dict;
		return dict->objectForKey(NSFileEntry);
	}
}
Exemplo n.º 2
0
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts)
{
	CCDictMaker *pMaker = (CCDictMaker*)(ctx);
	std::string sName((char*)name);
	if( sName == "dict" )
	{
		NSDictionary<std::string, NSObject*> *pNewDict = new NSDictionary<std::string, NSObject*>();
		if(! pMaker->m_pRootDict)
		{
			pMaker->m_pRootDict = pNewDict;
			pNewDict->autorelease();
		}
		else
		{
			NSAssert(pMaker->m_pCurDict && !pMaker->m_sCurKey.empty(), "");
			pMaker->m_pCurDict->setObject(pNewDict, pMaker->m_sCurKey);
			pNewDict->release();
			pMaker->m_sCurKey.clear();
		}
		pMaker->m_pCurDict = pNewDict;
		pMaker->m_tDictStack.push(pMaker->m_pCurDict);
		pMaker->m_tState = SAX_DICT;
	}
	else if(sName == "key")
	{
		pMaker->m_tState = SAX_KEY;
	}
	else if(sName == "integer")
	{
		pMaker->m_tState = SAX_INT;
	}
	else if(sName == "real")
	{
		pMaker->m_tState = SAX_REAL;
	}
	else if(sName == "string")
	{
		pMaker->m_tState = SAX_STRING;
	}
	else
	{
		pMaker->m_tState = SAX_NONE;
	}
}
Exemplo n.º 3
0
NSPathDirectoryEnumerator*
	NSPathDirectoryEnumerator::initWithPath(NSString * path)
{
		self->directoryIndex = 0;
		self->directory = NSMutableArray::alloc()->init();
		struct dirent *directoryEntry;
	    DIR *directoryRef;
		directoryRef = opendir(path->cStringUsingEncoding(NSASCIIStringEncoding));
		while((directoryEntry = readdir(directoryRef)))
		{
			if(directoryEntry->d_name[0] == '.')
			{
				continue;
			}
			NSString* fileType ;
			if(S_ISREG(directoryEntry->d_type))
			{
				fileType = NSFileTypeRegular;
			}else if(S_ISDIR(directoryEntry->d_type))
			{
				fileType = NSFileTypeDirectory;
			}else if(S_ISCHR(directoryEntry->d_type))
			{
				fileType = NSFileTypeCharacterSpecial;
			}else if(S_ISBLK(directoryEntry->d_type))
			{
				fileType = NSFileTypeBlockSpecial;
			}else if(S_ISSOCK(directoryEntry->d_type))
			{
				fileType = NSFileTypeSocket;
			}
			NSDictionary* attributefile = NSDictionary::alloc()->initWithObjectsAndKeys(
				fileType ,NSFileType,NSSTR(directoryEntry->d_name),NSFileEntry,nil);
			self->directory->addObject(attributefile);
			attributefile->release();
		}
		closedir(directoryRef);
	return self;
}
Exemplo n.º 4
0
JSClassRef EJBindingBase::getJSClass (EJBindingBase* ej_obj){
	// Gather all class methods that return C callbacks for this class or it's parents
	NSDictionary * methods = new NSDictionary();
	NSDictionary * properties = new NSDictionary();

	string base_obj = ej_obj->toString();

	NSObjectFactory::fuc_map_type* base = NSObjectFactory::getFunctionMap();
	for(NSObjectFactory::fuc_map_type::iterator it = base->begin(); it != base->end(); it++)
	{
		string name = it->first;
		string base_obj_tmp = base_obj;
		if( name.find("_func_") != string::npos ) {
			int pos = name.find("_func_");
			int is_member_func = name.find(base_obj_tmp);
			bool n_pos = (is_member_func == string::npos);
			while(n_pos) {
				EJBindingBase* pClass = (EJBindingBase*)NSClassFromString(base_obj_tmp);
				base_obj_tmp = pClass->superclass();
				is_member_func = name.find(base_obj_tmp);
				if ((is_member_func != string::npos) || (base_obj_tmp.find("EJBindingBase") != string::npos))
				{
					n_pos = false;
				}
			}
			if (is_member_func != string::npos)
			{
			   	methods->setObject(NSStringMake(name.substr(pos + strlen("_func_"))), name);
			}
		}
		else if( name.find("_get_") != string::npos ) {
			int pos = name.find("_get_");
			int is_member_func = name.find(base_obj_tmp);
			bool n_pos = (is_member_func == string::npos);
			while(n_pos) {
				EJBindingBase* pClass = (EJBindingBase*)NSClassFromString(base_obj_tmp);
				base_obj_tmp = pClass->superclass();
				is_member_func = name.find(base_obj_tmp);
				if ((is_member_func != string::npos) || (base_obj_tmp.find("EJBindingBase") != string::npos))
				{
					n_pos = false;
				}
			}
			if (is_member_func != string::npos)
			{
				// We only look for getters - a property that has a setter, but no getter will be ignored
			  	properties->setObject(NSStringMake(name.substr(pos + strlen("_get_"))), name);
			}
		}
	} 
	
	
	// Set up the JSStaticValue struct array
	JSStaticValue * values = (JSStaticValue *)calloc( properties->count() + 1, sizeof(JSStaticValue) );
	
	int i = 0;
	NSDictElement* pElement = NULL;
	NSObject* pObject = NULL;

	NSDICT_FOREACH(properties, pElement)
	{
		pObject = pElement->getObject()->copy();
		string key_name = pElement->getStrKey();
	    NSString* name = (NSString*)pObject;

		char * nameData = NSDataFromString( name );
		
		char** p_name = const_cast<char**>(&values[i].name);
		*p_name = nameData;
		values[i].attributes = kJSPropertyAttributeDontDelete;
		SEL get = NSSelectorFromString(key_name);
		values[i].getProperty = (JSObjectGetPropertyCallback)get;
		
		// Property has a setter? Otherwise mark as read only
		int pos = key_name.find("_get_");
		key_name = key_name.replace(pos, strlen("_get_"), "_set_");
		SEL set = NSSelectorFromString(key_name);
		if( set ) {
			values[i].setProperty = (JSObjectSetPropertyCallback)set;
		}
		else {
			values[i].attributes |= kJSPropertyAttributeReadOnly;
		}

		i++;
	}
Exemplo n.º 5
0
void CCSpriteFrameCache::addSpriteFramesWithDictionary(NSDictionary<std::string, NSObject*> *dictionary, CCTexture2D *pobTexture)
{
	/*
	Supported Zwoptex Formats:
		enum {
			ZWTCoordinatesListXMLFormat_Legacy = 0
			ZWTCoordinatesListXMLFormat_v1_0,
		};
	*/

	NSDictionary<std::string, NSObject*> *metadataDict = (NSDictionary<std::string, NSObject*>*)dictionary->objectForKey(std::string("metadata"));
	NSDictionary<std::string, NSObject*> *framesDict = (NSDictionary<std::string, NSObject*>*)dictionary->objectForKey(std::string("frames"));
	int format = 0;

	// get the format
	if(metadataDict != NULL) 
	{
		format = atoi(valueForKey("format", metadataDict));
	}

	// check the format
	if(format < 0 || format > 1) 
	{
		NSAssert(0, "cocos2d: WARNING: format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:texture:");
		return;
	}

	framesDict->begin();
	std::string key = "";
	NSDictionary<std::string, NSObject*> *frameDict = NULL;
	while( frameDict = (NSDictionary<std::string, NSObject*>*)framesDict->next(&key) )
	{
		CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
		if (spriteFrame)
		{
			continue;
		}
		
		if(format == 0) 
		{
			float x = (float)atof(valueForKey("x", frameDict));
			float y = (float)atof(valueForKey("y", frameDict));
			float w = (float)atof(valueForKey("width", frameDict));
			float h = (float)atof(valueForKey("height", frameDict));
			float ox = (float)atof(valueForKey("offsetX", frameDict));
			float oy = (float)atof(valueForKey("offsetY", frameDict));
			int ow = atoi(valueForKey("originalWidth", frameDict));
			int oh = atoi(valueForKey("originalHeight", frameDict));
			// check ow/oh
			if(!ow || !oh)
			{
				CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
			}
			// abs ow/oh
			ow = abs(ow);
			oh = abs(oh);
			// create frame
			spriteFrame = CCSpriteFrame::frameWithTexture(pobTexture, CGRectMake(x, y, w, h), CGPointMake(ox, oy), CGSizeMake((float)ow, (float)oh));
		} 
		else if(format == 1) 
		{
			/** @todo
			CGRect frame = CGRectFromString([frameDict objectForKey:@"frame"]);
			CGPoint offset = CGPointFromString([frameDict objectForKey:@"offset"]);
			CGSize sourceSize = CGSizeFromString([frameDict objectForKey:@"sourceSize"]);
			
			// create frame
			spriteFrame = [CCSpriteFrame frameWithTexture:texture rect:frame offset:offset originalSize:sourceSize];
			*/
		}
		else
		{
			CCLOG("cocos2d: Unsupported Zwoptex version. Update cocos2d.");
		}
		// add sprite frame
		m_pSpriteFrames->setObject(spriteFrame, key);
	}
}