Example #1
0
std::string SQLite::convertConditionMap(const cocos2d::ValueMap &conditionMap)
{
    std::string conditionStr;
    
    int count = conditionMap.size();
    
    if (count > 0) {
        
        conditionStr.append(" WHERE ");
        
        int i = 0;
        for (auto iter = conditionMap.cbegin(); iter != conditionMap.cend(); ++iter)
        {
            std::string columnName = iter->first;
            std::string columnValue = iter->second.asString();
            
            conditionStr.append(columnName);
            conditionStr.append("='");
            conditionStr.append(columnValue);
            conditionStr.append("'");
            
            if (i != count-1) {
                conditionStr.append(" AND ");
            }
            i++;
            
        }
        
    }
    return conditionStr;
}
Example #2
0
// 以下为更新接口
bool SQLite::updateTable(const std::string &tableName, const cocos2d::ValueMap &keyValueMap, const cocos2d::ValueMap &conditionMap)
{
    std::string sql = "UPDATE ";
    sql.append(tableName);
    sql.append(" SET ");
    
    int count = keyValueMap.size();
    
    int i = 0;
    for (auto iter = keyValueMap.cbegin(); iter != keyValueMap.cend(); ++iter)
    {
        std::string key = iter->first;
        std::string value = iter->second.asString();
        
        sql.append(key);
        sql.append("='");
        sql.append(value);
        sql.append("'");
        if (i != count-1) {
            sql.append(",");
        }
        
        i++;
    }
    
    sql.append(this->convertConditionMap(conditionMap));
    
    return this->executeUpdate(sql);
}
Example #3
0
bool Vandal::init(cocos2d::ValueMap map)
{
    _frameName = map.at("frame").asString();
    _position = Vec2(map.at("x").asInt(), (1136 - map.at("y").asInt())) / 2;
    
    return true;
}
Example #4
0
bool CrazyScratch::init( UnitNode* owner, const cocos2d::ValueMap& data, const cocos2d::ValueMap& params ) {
    if( !SkillNode::init( owner ) ) {
        return false;
    }
    
    int level = data.at( "level" ).asInt();
    _damage = data.at( "damage" ).asValueVector().at( level - 1 ).asFloat();
    _duration = data.at( "duration" ).asFloat();
    _interval = data.at( "interval" ).asFloat();
    _elapse = _interval;
    _range = data.at( "range" ).asFloat();
    _count = data.at( "count" ).asInt();
    _origin_pos = _owner->getPosition();
    _last_pos = _origin_pos;
    
    Point dir = _owner->getUnitDirection();
    if( dir.y > 0 ) {
        _skeleton = ArmatureManager::getInstance()->createArmature( "characters/kyle/kyle_b" );
    }
    else {
        _skeleton = ArmatureManager::getInstance()->createArmature( "characters/kyle/kyle_f" );
    }
    if( dir.x > 0 ) {
        _skeleton->getSkeleton()->flipX = 1;
    }
    else {
        _skeleton->getSkeleton()->flipX = 0;
    }
    
    _owner->getBattleLayer()->addToEffectLayer( _skeleton, _last_pos, _owner->getBattleLayer()->zorderForPositionOnObjectLayer( _last_pos ) );
    _skeleton->setAnimation( 0, "Cast_1", true );
    _skeleton->setBlendFunc( BlendFunc::ADDITIVE );
    return true;
}
Example #5
0
bool SQLite::insertIntoTable(const std::string &tableName, const cocos2d::ValueMap &keyValueMap)
{
    std::string sql = "INSERT INTO ";
    sql.append(tableName);
    std::string keyStr = "(";
    std::string valueStr = "(";
    
    int count = keyValueMap.size();
    
    int i = 0;
    for (auto iter = keyValueMap.cbegin(); iter != keyValueMap.cend(); ++iter)
    {
        std::string key = iter->first;
        std::string value = iter->second.asString();
        keyStr.append(key);
        valueStr.append("'");
        valueStr.append(value);
        valueStr.append("'");
        if (i != count-1) {
            keyStr.append(",");
            valueStr.append(",");
        }
        i++;
    }
    
    keyStr.append(")");
    valueStr.append(")");
    sql.append(keyStr);
    sql.append(" VALUES ");
    sql.append(valueStr);
    
    return this->executeUpdate(sql);
}
Example #6
0
bool ShadowAssault::init( UnitNode* owner, const cocos2d::ValueMap& data, const cocos2d::ValueMap& params ) {
    if( !SkillNode::init( owner ) ) {
        return false;
    }
    int level = data.at( "level" ).asInt();
    _damage = data.at( "damage" ).asValueVector().at( level - 1 ).asFloat();
    
    return true;
}
 void GameBuyStoreMannager::buyPropsWithTokens(cocos2d::ValueMap data)
 {
     if (data.at(STORE_COST_KEY).asInt() <= UserDataManager::getInstance()->getPropsNumbleWithKey(data.at(STORE_COST_TYPE_KEY).asString()))
     {
         for (auto var : data.at(ITEM_PROPS_DATA_KEY).asValueMap())
         {
             UserDataManager::getInstance()->addPropsNumbleWithKey(var.first, var.second.asInt());
         }
         UserDataManager::getInstance()->cutPropsNumbleWithKey(data.at(STORE_COST_TYPE_KEY).asString(), data.at(STORE_COST_KEY).asInt());
     }
 }
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;
}
Example #9
0
bool DreadLord::init( UnitNode* owner, const cocos2d::ValueMap& data, const cocos2d::ValueMap& params ) {
    if( !SkillNode::init( owner ) ) {
        return false;
    }
    
    int level = data.at( "level" ).asInt();
    _extra_atk = data.at( "atk" ).asValueVector().at( level - 1 ).asFloat();
    _extra_dod = data.at( "dod" ).asValueVector().at( level - 1 ).asFloat();
    _duration = data.at( "duration" ).asFloat();
    _elapse = 0;
    
    return true;
}
Example #10
0
void Coin::config( const cocos2d::ValueMap& cfg )
{
	int coin = cfg.at("coin").asInt();
	m_coin = coin;
	initWithFile( cstr("coin%d.png", coin) );
	MapObj::config(cfg);
}
Example #11
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);

        }
    }
    
}
 void GameBuyStoreMannager::buyProps(cocos2d::ValueMap data)
 {
     this->setBuyPropsKeyAndNumble(data);
     int target = data.at(TARGET_ID_KEY).asInt();
     GameJNIHelper::getInstance()->payWithTargetID(target);
     //this->setCurrentPropsTarget(target);
     cocos2d::Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(EVENT_BUY_PROPS_PAY_SUCCESS);
 }
Example #13
0
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;
}
Example #15
0
void ShopDialogEntry::setItemInfo(cocos2d::ValueMap itemInfo)
{
    _itemInfo = itemInfo;
    
    int intType = _itemInfo.at("type").asInt();
    std::string type = intType == 1 ? "Sprayer" : "Brush";
    
    _labelName->setString(_itemInfo.at("name").asString());
    _labelType->setString(type);
    _labelPrice->setString(StringUtils::format("%d", _itemInfo.at("price").asInt()));
    
    std::string itemPrefix = intType == 1 ? "equipments/spray-%d.png" : "equipments/brush-%d.png";
    _spriteItem->setSpriteFrame(StringUtils::format(itemPrefix.c_str(), itemInfo.at("id").asInt()));
}
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();
        }
    }
}
Example #17
0
bool BonesRain::init( UnitNode* owner, const cocos2d::ValueMap& data, const cocos2d::ValueMap& params ) {
    if( !SkillNode::init( owner ) ) {
        return false;
    }
    
    int level = data.at( "level" ).asInt();
    _damage = data.at( "damage" ).asValueVector().at( level - 1 ).asFloat();
    _radius = data.at( "radius" ).asFloat();
    _interval = data.at( "interval" ).asFloat();
    _elapse = _interval;
    _count = data.at( "count" ).asInt();
    _current_count = 0;
    _dir = Point( params.at( "dir_x" ).asFloat(), params.at( "dir_y" ).asFloat() );
    _init_pos = _owner->getPosition();
    
    return true;
}
Example #18
0
bool MissileShowers::init( UnitNode* owner, const cocos2d::ValueMap& data, const cocos2d::ValueMap& params ) {
    if( !SkillNode::init( owner ) ) {
        return false;
    }
    
    int level = data.at( "level" ).asInt();
    _damage = data.at( "damage" ).asValueVector().at( level - 1 ).asFloat();
    _range = data.at( "range" ).asFloat();
    _radius = data.at( "radius" ).asFloat();
    _count = data.at( "count" ).asValueVector().at( level - 1 ).asInt();
    _interval = data.at( "interval" ).asFloat();
    _current_count = 0;
    
    return true;
}
Example #19
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);
    }
  
    
}
Example #20
0
void UIStoryLayer::setStoryData( const cocos2d::ValueMap& data ) {
    _story_name = data.at( "name" ).asString();
    _story_data = data.at( "story_data" ).asValueVector();
    this->reset();
    this->gotoNextLine();
}