mrb_value ccvaluemap_to_rubyval(mrb_state* mrb, const cocos2d::ValueMap& inValue)
{
    mrb_value rhash = mrb_hash_new(mrb);
    for (auto iter = inValue.begin(); iter != inValue.end(); ++iter) {
        std::string key = iter->first;
        const Value& obj = iter->second;
        
        mrb_value hkey = mrb_str_new_cstr(mrb, key.c_str());
        mrb_value hval = ccvalue_to_rubyval(mrb, obj);
        mrb_hash_set(mrb, rhash, hkey, hval);
    }
    return rhash;
}
예제 #2
0
void Json_Parser::write_a_map(cocos2d::ValueMap &temp,rapidjson::Value &val2,rapidjson::Document::AllocatorType&allocator){
    
    rapidjson::Value object2(rapidjson::kObjectType);
    
    auto it=temp.begin();
    for (;it!=temp.end();it++) {
        rapidjson::Value v;
        rapidjson::Value v2;
        v.SetString(it->first.c_str(),allocator);
        
        if(it->second.getType()==Value::Type::DOUBLE){
            v2.SetDouble(it->second.asDouble());
            val2.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::STRING){
            v2.SetString(it->second.asString().c_str(),allocator);
            val2.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::BOOLEAN){
            v2.SetBool(it->second.asBool());
            val2.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::INTEGER){
            v2.SetInt(it->second.asInt());
            val2.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::NONE){
            v2.SetNull();
            val2.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::MAP){
            ValueMap chmap=it->second.asValueMap();
            v2.SetObject();
                write_a_map(chmap,v2,allocator);
            val2.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::VECTOR){
            
            ValueVector chvec=it->second.asValueVector();
            v2.SetArray();
                write_a_array(chvec, v2, allocator);
            val2.AddMember(v,v2,allocator);

        }
    }
    
}
예제 #3
0
파일: Resource.cpp 프로젝트: RayRiver/misc
void Resource::addResourceReference(const cocos2d::ValueMap& files)
{
    if (files.size()<1)
        return;
    
    for (auto iter=files.begin(); iter!=files.end(); iter++) {
        auto fullpath=cocos2d::FileUtils::getInstance()->fullPathForFilename(iter->first);
        if (!fullpath.empty()) {
            auto find=_resourceReferences.find(fullpath);
            if (find!=_resourceReferences.end()) {
                find->second++;
            }
            else {
                _resourceReferences.insert(std::make_pair(fullpath, 1));
                _resourceNotLoadded.push_back(fullpath);
                _resourceTypes.insert(std::make_pair(fullpath, iter->second.asString()));
            }
        }
    }
}
///@attention DrawPolygon関数は時計回りしか受け付けない
PossesAndUvs 
GamePlaying::GetPolygonVerticesInfo(cocos2d::ValueMap& map){
	PossesAndUvs posuvs=PossesAndUvs();
	auto v = map.find("points");
	std::vector<Vec2>& posses=posuvs.posses;
	if(v==map.end()){
		return posuvs;
	}else{
		
		for(auto& mm : v->second.asValueVector()){
			//残念ながらTileMapEditorのy軸は上下さかさまである…
			posses.push_back(Vec2(mm.asValueMap()["x"].asInt(),-mm.asValueMap()["y"].asInt()));
		}
	}

	//中心点(平均点)の計算
	Vec2 center=Vec2();
	for(auto& p : posses){
		center+=p;
	}
	//反時計回りなら反転
	center=center/posses.size();
	if((posses[0]-center).cross(posses[1]-center)>0){
		std::reverse(posses.begin(),posses.end());
	}
	//中心合わす
	posuvs.center = center;
	for(auto& vert : posses){
		vert-=center;
	}

	std::vector<Vec2>& uvs=posuvs.uvs;
	uvs.push_back(Vec2(0,0));
	uvs.push_back(Vec2(1,0));
	uvs.push_back(Vec2(1,1));
	uvs.push_back(Vec2(0,1));
	return posuvs;
}
static void dictionary_Value(CCDictionary * aDict, const cocos2d::ValueMap & value)
{
    cocos2d::ValueMap::const_iterator beg = value.begin();
    cocos2d::ValueMap::const_iterator end = value.end();
    for (; beg != end; ++beg)
    {
        const std::string & key = (*beg).first;
        const cocos2d::Value & v = (*beg).second;
        if (v.getType() == Value::Type::MAP)
        {
            CCDictionary * d = new CCDictionary();
            d->init();
            dictionary_Value(d, v.asValueMap());
            aDict->setObject(d, key);
            d->release();
        }
        else if (v.getType() == Value::Type::VECTOR)
        {
            CCArray * a = new CCArray();
            a->init();
            array_Value(a, v.asValueVector());
            aDict->setObject(a, key);
            a->release();
        }
        else
        {
            CCString * str = new CCString();
            if (v.getType() == Value::Type::DOUBLE)
                str->initWithFormat("%f", v.asDouble());
            else
                str->initWithFormat("%s", v.asString().c_str());
            aDict->setObject(str, key);
            str->release();
        }
    }
}
예제 #6
0
//写入文件系列
//将ValueMap写入一个一个Json文件
void Json_Parser::write_a_map(cocos2d::ValueMap &map_temp,const char*filepath){
    rapidjson::Document doc;
    doc.SetObject();
    rapidjson::Document::AllocatorType&allocator=doc.GetAllocator();
    
    rapidjson::Value object(rapidjson::kObjectType);
    rapidjson::Value array(rapidjson::kArrayType);
    
    auto it=map_temp.begin();
    for (;it!=map_temp.end();it++) {
        rapidjson::Value v;
        rapidjson::Value v2;
        v.SetString(it->first.c_str(),allocator);
        
        if(it->second.getType()==Value::Type::DOUBLE){
        v2.SetDouble(it->second.asDouble());
        object.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::STRING){
            v2.SetString(it->second.asString().c_str(),allocator);
            object.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::BOOLEAN){
            v2.SetBool(it->second.asBool());
            object.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::INTEGER){
            v2.SetInt(it->second.asInt());
            object.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::NONE){
            v2.SetNull();
            object.AddMember(v,v2,allocator);
        }
        else if(it->second.getType()==Value::Type::MAP){
            ValueMap chmap=it->second.asValueMap();
            v2.SetObject();
                write_a_map(chmap,v2,allocator);

            object.AddMember(v,v2,allocator);
                    }
        else if(it->second.getType()==Value::Type::VECTOR){
            ValueVector chvec=it->second.asValueVector();
            v2.SetArray();
                write_a_array(chvec, v2, allocator);
            object.AddMember(v,v2,allocator);
        }

    }
    array.PushBack(object,allocator);
    
    
   
   
    doc.AddMember("record",array,allocator);
    
    rapidjson::StringBuffer buffer;
    rapidjson:: Writer<rapidjson::StringBuffer> writer(buffer);
    
    doc.Accept(writer);
    auto out=buffer.GetString();
    log("out:%s",out);
    FILE*file=fopen(filepath, "wb");
    if (file) {
        fputs(buffer.GetString(),file);
        fclose(file);
    }
  
    
}