Exemplo n.º 1
0
void ItemLocation::FromItemJson(const rapidjson::Value &root) {
    if (root.HasMember("_type")) {
        type_ = static_cast<ItemLocationType>(root["_type"].GetInt());
        if (type_ == ItemLocationType::STASH) {
            tab_label_ = root["_tab_label"].GetString();
            tab_id_ = root["_tab"].GetInt();
        } else {
            character_ = root["_character"].GetString();
        }
        socketed_ = false;
        if (root.HasMember("_socketed"))
            socketed_ = root["_socketed"].GetBool();
        // socketed items have x/y pointing to parent
        if (socketed_) {
            x_ = root["_x"].GetInt();
            y_ = root["_y"].GetInt();
        }
    }
    if (root.HasMember("x") && root.HasMember("y")) {
        x_ = root["x"].GetInt();
        y_ = root["y"].GetInt();
    }
    w_ = root["w"].GetInt();
    h_ = root["h"].GetInt();
    if (root.HasMember("inventoryId"))
        inventory_id_ = root["inventoryId"].GetString();
}
Exemplo n.º 2
0
Post processRawPost(const rapidjson::Value& raw_post) {
  const char* ITEM_ID = "id";
  const char* ITEM_USER_ID = "userId";
  const char* ITEM_TITLE = "title";
  const char* ITEM_BODY = "body";

  Post post;

  if (raw_post.IsObject()) {  // could also be an Array
    assert("No item: id" && raw_post.HasMember(ITEM_ID));
    assert("Not an integer: id" && raw_post[ITEM_ID].IsInt());
    post.id = raw_post[ITEM_ID].GetInt();

    assert("No item: user_id" && raw_post.HasMember(ITEM_USER_ID));
    assert("Not an integer: user_id" && raw_post[ITEM_USER_ID].IsInt());
    post.user_id = raw_post[ITEM_USER_ID].GetInt();

    assert("No item: title" && raw_post.HasMember(ITEM_TITLE));
    assert("Not a string: title" && raw_post[ITEM_TITLE].IsString());
    post.title = std::string(raw_post[ITEM_TITLE].GetString());

    assert("No item: body" && raw_post.HasMember(ITEM_BODY));
    assert("Not a string: body" && raw_post[ITEM_BODY].IsString());
    post.body = std::string(raw_post[ITEM_BODY].GetString());
  } else {
    ERR("Invalid json object");
  }

  return post;
}
Exemplo n.º 3
0
bool
Element::loadFromJsonValue(rapidjson::Value& json_value)
{
  if (!json_value.IsObject()) {
    return false;
  }
  // parse the data and set the Elements
  if (json_value.HasMember("id")) {
    const rapidjson::Value& idVal = json_value["id"];
    id_.fromStr(idVal.GetString());
  }

  tag_ids_.clear();
  if (json_value.HasMember("tag_ids")) {
    const rapidjson::Value& tag_ids = json_value["tag_ids"];
    if (!tag_ids.IsArray()) {
      LOG_ERROR("tag_ids field is not an array, wrong format?");
      return false;
    }
    for (unsigned int i = 0; i < tag_ids.Size(); ++i) {
      if (!tag_ids[i].IsString()) {
        LOG_ERROR("Wrong format, expected string but it is not");
        return false;
      }
      tag_ids_.insert(core::UID(tag_ids[i].GetString()));
    }
  }

  return true;
}
Exemplo n.º 4
0
void Item::CalculateHash(const rapidjson::Value &json) {
    std::string unique_old(name_ + "~" + typeLine_ + "~");
    std::string unique_new(std::string(json["name"].GetString()) + "~" + json["typeLine"].GetString() + "~");

    std::string unique_common;

    if (json.HasMember("explicitMods"))
        for (auto &mod : json["explicitMods"])
            unique_common += std::string(mod.GetString()) + "~";

    if (json.HasMember("implicitMods"))
        for (auto &mod : json["implicitMods"])
            unique_common += std::string(mod.GetString()) + "~";

    unique_common += item_unique_properties(json, "properties") + "~";
    unique_common += item_unique_properties(json, "additionalProperties") + "~";

    if (json.HasMember("sockets"))
        for (auto &socket : json["sockets"])
            unique_common += std::to_string(socket["group"].GetInt()) + "~" + socket["attr"].GetString() + "~";

    unique_old += unique_common;
    unique_new += unique_common;

    old_hash_ = Util::Md5(unique_old);
    unique_new += "~" + location_.GetUniqueHash();
    hash_ = Util::Md5(unique_new);
}
Exemplo n.º 5
0
void JSONDataParser::_parseEventData(const rapidjson::Value& rawData, std::vector<EventData*>& events, BoneData * bone, SlotData * slot) const
{
    if (rawData.HasMember(SOUND))
    {
        const auto eventData = BaseObject::borrowObject<EventData>();
        eventData->type = EventType::Sound;
        eventData->name = rawData[SOUND].GetString();
        eventData->bone = bone;
        eventData->slot = slot;
        events.push_back(eventData);
    }

    if (rawData.HasMember(EVENT))
    {
        const auto eventData = BaseObject::borrowObject<EventData>();
        eventData->type = EventType::Frame;
        eventData->name = rawData[EVENT].GetString();
        eventData->bone = bone;
        eventData->slot = slot;

        if (rawData.HasMember(DATA))
        {
            // eventData->data = rawData[DATA]; // TODO
        }

        events.push_back(eventData);
    }
}
Exemplo n.º 6
0
void Screen::fromJson(rapidjson::Value& value) {
	auto visibleSize = cocos2d::Director::getInstance()->getVisibleSize();

	if (value.HasMember("positioning")) {
		std::string _positioning = toLowerCase(value["positioning"].GetString());

		if (_positioning == "block") {
			this->positioning = Screen::PositionTypes::BLOCK;
		}
		else if (_positioning == "overlay") {
			this->positioning = Screen::PositionTypes::OVERLAY;
		}
		else if (_positioning == "fixed") {
			this->positioning = Screen::PositionTypes::FIXED;
		}
	}

	if (value.HasMember("position")) {
		assert(value["position"].IsArray());
		this->position.x = visibleSize.width * value["position"][0].GetInt();
		this->position.y = visibleSize.height - visibleSize.height * value["position"][1].GetInt();
	}

	if (value.HasMember("size")) {
		assert(value["size"].IsArray());
		//Optimize This: Not really needed but this is gross
		this->size.width = visibleSize.width * value["size"][0].GetDouble();
		this->size.height = visibleSize.height * value["size"][1].GetDouble();
	}
}
Exemplo n.º 7
0
std::string PersonManager::handleDressFigure(const rapidjson::Value& json)
{
	std::string operation = json["OPERATION"].GetString();

	if (json.HasMember("WHO") == false || json.HasMember("FIGURES") == false)
	{
		return "missing WHO or FIGURES";
	}

	std::string who = json["WHO"].GetString();
	const rapidjson::Value& figures = json["FIGURES"];
	assert(figures.IsArray());

	if (who != "me" && who != "spouse")
	{
		return "invalid value of WHO";
	}

	Person* person = (who == "me" ? mMe : mSpouse);

	for (rapidjson::SizeType i = 0; i < figures.Size(); ++i)
	{
		const rapidjson::Value& item = figures[i];

		assert(item.HasMember("TYPE"));
		assert(item.HasMember("NAME"));
		std::string type = item["TYPE"].GetString();
		std::string id = item["NAME"].GetString();

		FigureKey figureKey(person->isMale(), type, id);
		FigureManager::getInstance()->dressItem(figureKey);
	}

	return SUCC;
}
Exemplo n.º 8
0
Manifest::Asset Manifest::parseAsset(const std::string &path, const rapidjson::Value &json)
{
    Asset asset;
    asset.path = path;
	
    if ( json.HasMember(KEY_MD5) && json[KEY_MD5].IsString() )
    {
        asset.md5 = json[KEY_MD5].GetString();
    }
    else asset.md5 = "";
    
    if ( json.HasMember(KEY_PATH) && json[KEY_PATH].IsString() )
    {
        asset.path = json[KEY_PATH].GetString();
    }
    
    if ( json.HasMember(KEY_COMPRESSED) && json[KEY_COMPRESSED].IsBool() )
    {
        asset.compressed = json[KEY_COMPRESSED].GetBool();
    }
    else asset.compressed = false;
    
    if ( json.HasMember(KEY_DOWNLOAD_STATE) && json[KEY_DOWNLOAD_STATE].IsInt() )
    {
        asset.downloadState = (DownloadState)(json[KEY_DOWNLOAD_STATE].GetInt());
    }
    else asset.downloadState = DownloadState::UNSTARTED;
    
    return asset;
}
Exemplo n.º 9
0
RenderOptions RenderOptions::Load(const rapidjson::Value& value) {
    RenderOptions options;
    
    if (value.HasMember("maxThreadsCount")) {
        options.maxThreadsCount = value["maxThreadsCount"].GetInt();
    }
    if (value.HasMember("antialiasingSampling")) {
        options.antialiasingSampling = SamplingConfig::Load(value["antialiasingSampling"]);
    }
    if (value.HasMember("maxRayDepth")) {
        options.maxRayDepth = value["maxRayDepth"].GetInt();
    }
    if (value.HasMember("surfaceIntegrator")) {
        options.surfaceIntegrator = SurfaceIntegrator::Load(value["surfaceIntegrator"]);
        if (!options.surfaceIntegrator) {
            std::cerr << "RenderOptions error: error while loading surface integrator" << std::endl;
        }
    } else {
        std::cerr << "RenderOptions error: no surface integrator given" << std::endl;
    }
    if (value.HasMember("volumeIntegrator")) {
        options.volumeIntegrator = VolumeIntegrator::Load(value["volumeIntegrator"]);
        if (!options.volumeIntegrator) {
            std::cerr << "RenderOptions error: error while loading volume integrator" << std::endl;
        }
    } else {
        std::cerr << "RenderOptions error: no volume integrator given" << std::endl;
    }
    
    return options;
}
Exemplo n.º 10
0
EffectData::EffectData(EffectType t, const rapidjson::Value &json)
    : type{t},
    anim{},
    animFrames{},
    sound{},
    dur{Duration::INSTANT},
    text{}
{
    if (json.HasMember("anim")) {
        anim = sdlLoadImage(json["anim"].GetString());
    }
    if (json.HasMember("anim-frames")) {
        animFrames = jsonListUnsigned(json["anim-frames"]);
    }
    if (json.HasMember("sound")) {
        sound = sdlLoadSound(json["sound"].GetString());
    }
    if (json.HasMember("duration")) {
        const auto &durType = json["duration"].GetString();
        auto iter = allDurations.find(to_upper(durType));
        if (iter != std::end(allDurations)) {
            dur = iter->second;
        }
        else {
            std::cerr << "Warning: unrecognized duration type for effect " <<
                " type " << static_cast<int>(type) << '\n';
        }
    }
    if (json.HasMember("text")) {
        text = json["text"].GetString();
    }
}
Exemplo n.º 11
0
void BQ::RigidBodyPattern::parse(const rapidjson::Value & json)
{
    mass = json.HasMember("mass") ? json["mass"].GetFloat() : 1;
    restitution = json.HasMember("restitution") ? json["restitution"].GetFloat() : 1;
    friction = json.HasMember("friction") ? json["friction"].GetFloat() : 0;
    momentum.x = json.HasMember("momentum_x") ? json["momentum_x"].GetFloat() : 0;
    momentum.y = json.HasMember("momentum_y") ? json["momentum_y"].GetFloat() : 0;
}
Exemplo n.º 12
0
bool is_as_msg(const rapidjson::Value & val)
{
	RAPIDJSON_ASSERT(val.HasMember("category"));
	RAPIDJSON_ASSERT(val.HasMember("msgid"));
	RAPIDJSON_ASSERT(val.FindMember("msgid")->value.IsArray());
	if (val.FindMember("msgid")->value.Size() > 0) {
		return true;
	}
	return false;
}
Exemplo n.º 13
0
std::string ChatOnBedRoom::handlePlatformMessage(const rapidjson::Value& content)
{
    std::string operation = content[minius::Protocol::OPERATION.c_str()].GetString();
    
    if (operation == "loadModule")
    {
        std::string result = SUCC;
        if (content.HasMember("INIT_DATA"))
        {
            const rapidjson::Value& initData = content["INIT_DATA"];
            for (rapidjson::SizeType i = 0; i < initData.Size(); ++i)
            {
                std::string resultTemp = this->handlePlatformMessage(initData[i]);
                //assert(resultTemp == SUCC);
                /*
                 if (resultTemp != SUCC)
                 result = resultTemp;*/
            }
        }
        return result;
    }
    else if (operation == "setComponentAttrs")
    {
        if (content.HasMember("COMPONENT") == false || content.HasMember("ATTRS") == false)
        {
            return "missing COMPONENT or ATTRS";
        }
        
        std::string componentName = content["COMPONENT"].GetString();
        minius::Component* pComponent = dynamic_cast<minius::Component*>(this->getChildByName(componentName));
        if (pComponent == nullptr)
        {
            return std::string("invalid COMPONENT: ") + componentName;
        }
        
        bool status = pComponent->setAttrs(content["ATTRS"]);
        return SUCC;
    }
    else if (operation == "chatAction")
    {
        std::string type = content["TYPE"].GetString();
        std::string sponsor = content["WHO"].GetString();
        if (sponsor == "me") {
            this->playActionWithIsMeSponsor(true, type);
        }
        else {
            this->playActionWithIsMeSponsor(false, type);
        }
        return SUCC;
    }
    else
    {
        return std::string("invalid OPERATION: ") + operation;
    }
}
Exemplo n.º 14
0
bool Client::parseJob(const rapidjson::Value &params, int *code)
{
    if (!params.IsObject()) {
        *code = 2;
        return false;
    }

#   ifdef XMRIG_PROXY_PROJECT
    Job job(m_id, m_url.variant());
    job.setClientId(m_rpcId);
    job.setCoin(m_url.coin());
#   else
    Job job(m_id, m_nicehash, m_url.algo(), m_url.variant());
#   endif

    if (!job.setId(params["job_id"].GetString())) {
        *code = 3;
        return false;
    }

    if (!job.setBlob(params["blob"].GetString())) {
        *code = 4;
        return false;
    }

    if (!job.setTarget(params["target"].GetString())) {
        *code = 5;
        return false;
    }

    if (params.HasMember("coin")) {
        job.setCoin(params["coin"].GetString());
    }

    if (params.HasMember("variant")) {
        job.setVariant(params["variant"].GetInt());
    }

    if (m_job != job) {
        m_jobs++;
        m_job = std::move(job);
        return true;
    }

    if (m_jobs == 0) { // https://github.com/xmrig/xmrig/issues/459
        return false;
    }

    if (!m_quiet) {
        LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
    }

    close();
    return false;
}
Exemplo n.º 15
0
void
SkillInfo::from_json_value(const rapidjson::Value& d)
{
	if (d.HasMember("kind") && d["kind"].IsString()) {
		kind_ = d["kind"].GetString();
	}
	if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
		apiVersion_ = d["apiVersion"].GetString();
	}
	if (d.HasMember("name") && d["name"].IsString()) {
		name_ = d["name"].GetString();
	}

}
Exemplo n.º 16
0
void
BlackboardGraph::from_json_value(const rapidjson::Value& d)
{
	if (d.HasMember("kind") && d["kind"].IsString()) {
		kind_ = d["kind"].GetString();
	}
	if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
		apiVersion_ = d["apiVersion"].GetString();
	}
	if (d.HasMember("dotgraph") && d["dotgraph"].IsString()) {
		dotgraph_ = d["dotgraph"].GetString();
	}

}
Exemplo n.º 17
0
static bool is_enum_flag(const rapidjson::Value & val)
{
	RAPIDJSON_ASSERT(val.HasMember("category"));
	RAPIDJSON_ASSERT(val.FindMember("category")->value.IsString());
	RAPIDJSON_ASSERT(val.FindMember("category")->value == "enum");
	RAPIDJSON_ASSERT(val.HasMember("attr"));
	const rapidjson::Value & attrs = val.FindMember("attr")->value;
	for (const auto & itr : attrs.GetArray()) {
		if (itr == "flag") {
			return true;
		}
	}
	return false;
}
Exemplo n.º 18
0
bool webserver::initialize(const rapidjson::Value &config)
{
	if (!config.HasMember("remotes"))
		return false;

	if (!config.HasMember("groups"))
		return false;

	std::vector<std::string> remotes;
	std::vector<int> groups;
	std::string logfile = "/dev/stderr";
	int loglevel = DNET_LOG_INFO;

	if (config.HasMember("logfile"))
		logfile = config["logfile"].GetString();

	if (config.HasMember("loglevel"))
		loglevel = config["loglevel"].GetInt();

	auto &remotesArray = config["remotes"];
	std::transform(remotesArray.Begin(), remotesArray.End(),
		std::back_inserter(remotes),
		std::bind(&rapidjson::Value::GetString, std::placeholders::_1));

	auto &groupsArray = config["groups"];
	std::transform(groupsArray.Begin(), groupsArray.End(),
		std::back_inserter(groups),
		std::bind(&rapidjson::Value::GetInt, std::placeholders::_1));

	uint32_t min_writes = groups.size();
	if (config.HasMember("min_writes"))
		min_writes = config["min_writes"].GetInt();

	provider_ = std::make_shared<provider>(remotes,
	                                       groups ,
	                                       min_writes,
	                                       logfile,
	                                       loglevel);

	on<on_root>("/");
	on<on_add_log>("/add_log");
	on<on_add_activity>("/add_activity");
	on<on_add_log_with_activity>("/add_log_with_activity");
	on<on_get_active_users>("/get_active_users");
	on<on_get_user_logs>("/get_user_logs");

	return true;
}
Exemplo n.º 19
0
	bool dto_complex::parse( const rapidjson::Value& json )
	{
		if( json.IsObject() && json.HasMember( key() ) && json[key()].IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json[key()] ) && !optional() )
				{
					return false;
				}
			}
			
			return true;
		}
		else if( json.IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json ) && !optional()  )
				{
					return false;
				}
			}
			
			return true;
		}

		set_present( false );
		return optional();
	}
Exemplo n.º 20
0
static void convert_struct(rapidjson::Document & doc, rapidjson::Value & val, const std::size_t lvl)
{
	RAPIDJSON_ASSERT(val.HasMember("name"));
	const char * ename = val.FindMember("name")->value.GetString();
	convert_nested_struct(doc, val, std::string(ename), lvl);
	convert_struct_by_name(doc, val, std::string("struct ") + std::string(ename), lvl);
}
Exemplo n.º 21
0
std::string PersonManager::handleUpdateSpouseScene(const rapidjson::Value& json)
{
	std::string operation = json["OPERATION"].GetString();

	if (json.HasMember("SCENE") == false)
	{
		return "missing SCENE";
	}

	std::string scene = json["SCENE"].GetString();

	if (scene == mSpouseScene.getValue())
		return SUCC;

	//if spouse's scene is in conflict with spouse's action, change spouse's action to STAND
	if (scene == SCENE_LIVINGROOM)
	{
		if (mSpouseAction.getAction() == Person::Action::SLEEP)
			mSpouseAction.setAction(Person::Action::STAND);
	}
	else if (scene == SCENE_BEDROOM)
	{
		if (mSpouseAction.getAction() == Person::Action::EAT 
			|| mSpouseAction.getAction() == Person::Action::READ)
			mSpouseAction.setAction(Person::Action::STAND);
	}

	mSpouseScene.setValue(scene);
	mSpouseScene.notify();

	return SUCC;
}
Exemplo n.º 22
0
std::string PersonManager::handleExpandPersonMenu(const rapidjson::Value& json)
{
	std::string operation = json["OPERATION"].GetString();

	if (json.HasMember("WHO") == false)
	{
		return "missing WHO";
	}

	std::string who = json["WHO"].GetString();

	if (who != "me" && who != "spouse")
	{
		return "invalid value of WHO";
	}

	if (who == "me")
	{
		mExpandMeMenu.notify();
	}
	else
	{
		mExpandSpouseMenu.notify();
	}

	return SUCC;
}
Exemplo n.º 23
0
BBOX rapidjson_get_bbox(const rapidjson::Value& v, std::string field,
                        BBOX default_value)
{
    const char* f = field.c_str();
    BBOX ret = default_value;
    
    if ( v.HasMember(f) && v[f].IsArray() )
    {
        int index = 0;
        int* p[4] = {&ret.first.first, &ret.first.second,
                     &ret.second.first, &ret.second.second};
        
        for (rapidjson::SizeType i = 0; i < v[f].Size(); i++){
            const rapidjson::Value& v_json = v[f][i];

            for (rapidjson::SizeType j = 0; j < v_json.Size(); j++){
                const rapidjson::Value& vv_json = v_json[j];

                if ( vv_json.IsInt() ){
                    *p[index] = vv_json.GetInt();
                }
                index++;
            }
        }
    }
    
    return ret;
}
	void load(glm::uvec2 &value, rapidjson::Value &json, rapidjson::Document &document)
	{
		if (!json.HasMember("uvec2"))
			return;
		value.x = json["uvec2"][(rapidjson::SizeType)(0)].GetUint();
		value.y = json["uvec2"][(rapidjson::SizeType)(1)].GetUint();
	}
Exemplo n.º 25
0
NS_CC_BEGIN

void getChildMap(std::map<int, std::vector<int> >& map, SkinData* skinData, const rapidjson::Value& val)
{
    if (!skinData)
        return;

    if (!val.HasMember("children"))
        return;

    std::string parent_name = val["id"].GetString();
    int parent_name_index = skinData->getBoneNameIndex(parent_name);

    const rapidjson::Value& children = val["children"];
    for (rapidjson::SizeType i = 0; i < children.Size(); i++)
    {
        const rapidjson::Value& child = children[i];
        std::string child_name = child["id"].GetString();

        int child_name_index = skinData->getBoneNameIndex(child_name);
        if (child_name_index >= 0)
        {
            map[parent_name_index].push_back(child_name_index);

            getChildMap(map, skinData, child);
        }
    }
}
Exemplo n.º 26
0
std::shared_ptr<VolumeIntegrator> VolumeIntegrator::Load(const rapidjson::Value& value) {
    std::shared_ptr<VolumeIntegrator> integrator;
    
    std::string type;
    
    if (value.IsString()) {
        type = value.GetString();
    } else if (value.IsObject() && value.HasMember("type")) {
        type = value["type"].GetString();
    } else {
        std::cerr << "VolumeIntegrator error: no type given" << std::endl;
        return integrator;
    }
    
    std::transform(type.begin(), type.end(), type.begin(), ::tolower);
    
    if (type == "singlescattering") {
        integrator = SingleScatteringIntegrator::Load(value);
    } else {
        std::cerr << "VolumeIntegrator error: unknown type \"" << type << "\"" << std::endl;
        return integrator;
    }
    
    return integrator;
}
Exemplo n.º 27
0
std::string PersonManager::handlePerformAction(const rapidjson::Value& json)
{
	std::string operation = json["OPERATION"].GetString();

	if (json.HasMember("WHO") == false || json.HasMember("ACTION") == false)
	{
		return "missing WHO or ACTION";
	}

	std::string who = json["WHO"].GetString();
	std::string actionName = json["ACTION"].GetString();

	if (who != "me" && who != "spouse")
	{
		return "invalid value of WHO";
	}

	Person::Action action = Person::parseProtocolNameToAction(actionName);
	if (action == Person::Action::INVALID_ACTION)
	{
		return "invalid value of ACTION";
	}

	if (Person::isCoupleAction(action))
	{
		mCoupleAction.addAction((who == "me"), action);
		mCoupleAction.notify();
		return SUCC;
	}

	if (who == "me")
	{
		if (action == mMeAction.getAction())
			return SUCC;
		mMeAction.setAction(action);
		mMeAction.notify();
	}
	else
	{
		if (action == mSpouseAction.getAction())
			return SUCC;
		mSpouseAction.setAction(action);
		mSpouseAction.notify();
	}

	return SUCC;
}
Exemplo n.º 28
0
void GX::AnimationCom::initWithMap(rapidjson::Value& value)
{
    if (value.HasMember("filename")&& value.HasMember("animations")&&value["animations"].Size()) {
        filename=value["filename"].GetString();
        
        int count=value["animations"].Size();
        for (int i=0; i<count; i++) {
            rapidjson::Value& entity=value["animations"][i];
            
            if (entity.HasMember("name")) {
                AnimationDefinition definition;
                definition.name=entity["name"].GetString();
                
                if (entity.HasMember("position")) {
                    definition.position=cocos2d::PointFromString(entity["position"].GetString());
                }
                
                if(entity.HasMember("anchorPoint")){
                    definition.anchorPoint=cocos2d::PointFromString(entity["anchorPoint"].GetString());
                }

                if(entity.HasMember("scale")){
                    definition.scale=cocos2d::PointFromString(entity["scale"].GetString());
                }

                if(entity.HasMember("localZOrder")){
                    definition.localZOrder=entity["localZOrder"].GetInt();
                }
                
                if(entity.HasMember("loops")){
                    definition.loops=entity["loops"].GetInt();
                }
                
                if(entity.HasMember("autoPlay")){
                    definition.autoPlay=entity["autoPlay"].GetBool();
                }
                
                if(entity.HasMember("delayPerUnit")){
                    definition.delayPerUnit=(float)entity["delayPerUnit"].GetDouble();
                }
                
                animations.insert(std::make_pair(definition.name, definition));
            }
        }
    }
}
Exemplo n.º 29
0
void JsonValidator::validateMetaData(rapidjson::Value& metaDocument, QString path) {
	QMap<QString, int>::iterator i;
	QMap<QString, int> map = JsonValidator::NON_TEMPORAL_TAGS;

	for (i = map.begin(); i != map.end(); ++i) {
		if (!metaDocument.HasMember(i.key().toStdString().c_str())) {
			throw JsonReaderParseException(
			    path,
			    QString("Error in the meta header: The tag \"%1\" does not exist.").arg(i.key())
			);
		}

		if (JsonValidator::getType(metaDocument[i.key().toStdString().c_str()]) != i.value()) {
			throw JsonReaderParseException(
			    path,
			    QString("Error in the meta header: The tag \"%1\" should be of type %2 but is "
			            "of type %3.").arg(i.key(), JsonValidator::TYPE_NAMES.value(i.value()),
			                               JsonValidator::TYPE_NAMES.value(
			                                   JsonValidator::getType(metaDocument[i.key().toStdString().c_str()])
			                               ))
			);
		}
	}

	// This check can only be done this late since we only know by now that the temporal tag exists
	if (metaDocument["temporal"].GetBool()) {
		if (!metaDocument.HasMember("timeResolution")) {
			throw JsonReaderParseException(
			    path,
			    QString("Error in the meta header: The tag \"timeResolution\" does not exist "
			            "but is mandatory for temporal data.")
			);
		}

		if (JsonValidator::getType(metaDocument["timeResolution"]) != kJsonTypeInteger) {
			throw JsonReaderParseException(
			    path,
			    QString("Error in the meta header: The tag \"timeResolution\" should be of type "
			            "Integer but is of type %1.")
			    .arg(JsonValidator::TYPE_NAMES.value(
			             JsonValidator::getType(metaDocument[i.key().toStdString().c_str()])
			         ))
			);
		}
	}
}
Exemplo n.º 30
0
		bool contains_valid_tag(const rapidjson::Value& node, const JsonTag & tag)
		{
			if (!node.HasMember(tag.name) ||
				node[tag.name].GetType() != tag.type)
				return false;

			return true;
		}