bool SpriteData::importData(Json::Value root) { mSpriteHash.clear(); if (root.empty()) { return false; } else { mResourceDirPath = QString::fromStdString(root["resourceDirPath"].asString()); Json::Value sprites = root["sprites"]; for(Json::Value::iterator iter = sprites.begin() ; sprites.end() != iter ; iter++) { QString keyName = QString::fromStdString(iter.key().asString()); Json::Value data = *iter; SpriteDef sDef; sDef.mGridX = data["gridX"].asInt(); sDef.mGridY = data["gridY"].asInt(); sDef.mCenterX = data["centerX"].asInt(); sDef.mCenterY = data["centerY"].asInt(); sDef.mImageID = keyName; mSpriteHash.insert(keyName, sDef); } return true; } }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, BASIC_ATTR_CFG_PATH, root) != 0) return -1; this->basic_attr_cfg_info_ = new basic_attr_cfg_info[CHAR_CAREER_CNT + 1](); for (Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int career = ::atoi(iter.key().asCString()); if (!util::is_career_ok(career)) return -1; basic_attr_cfg_info &baci = this->basic_attr_cfg_info_[career]; baci.attr_val_[ATTR_T_HP] = ((*iter)["sheng_ming"]).asInt(); baci.attr_val_[ATTR_T_MP] = ((*iter)["fa_li"]).asInt(); baci.attr_val_[ATTR_T_GONG_JI] = ((*iter)["gong_ji"]).asInt(); baci.attr_val_[ATTR_T_FANG_YU] = ((*iter)["fang_yu"]).asInt(); baci.attr_val_[ATTR_T_MING_ZHONG] = ((*iter)["ming_zhong"]).asInt(); baci.attr_val_[ATTR_T_SHAN_BI] = ((*iter)["shan_bi"]).asInt(); baci.attr_val_[ATTR_T_BAO_JI] = ((*iter)["bao_ji"]).asInt(); baci.attr_val_[ATTR_T_KANG_BAO] = ((*iter)["kang_bao"]).asInt(); baci.attr_val_[ATTR_T_SHANG_MIAN] = ((*iter)["shang_mian"]).asInt(); } return 0; }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, CHENG_JIU_CFG_PATH, root) != 0) return -1; for (Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int cj_id = ::atoi(iter.key().asCString()); cheng_jiu_obj *cjo = new cheng_jiu_obj(); this->cheng_jiu_obj_map_.insert(std::make_pair(cj_id, cjo)); cjo->show_lvl_ = (*iter)["show_lvl"].asInt(); cjo->value_ = (*iter)["param"].asInt(); cjo->title_ = (*iter)["title"].asInt(); cjo->next_cj_id_ = (*iter)["next_index"].asInt(); cjo->lucky_rate_ = (*iter)["lucky_rate"].asInt(); if ((cj_id / 1000) != (cjo->next_cj_id_ / 1000)) return -1; char bf[128] = {0}; ::strncpy(bf, (*iter)["award"].asCString(), sizeof(bf)); char *tok_p = NULL; char *token = NULL; for (token = ::strtok_r(bf, ";", &tok_p); token != NULL; token = ::strtok_r(NULL, ";", &tok_p)) { item_amount_bind_t v; int bind = 0; if (::sscanf(token, "%d,%d,%d", &v.cid_, &v.amount_, &bind) != 3) return -1; v.bind_ = bind; cjo->award_list_.push_back(v); } ::memset(bf, 0, sizeof(bf)); ::strncpy(bf, (*iter)["lucky_award"].asCString(), sizeof(bf)); tok_p = NULL; token = NULL; for (token = ::strtok_r(bf, ";", &tok_p); token != NULL; token = ::strtok_r(NULL, ";", &tok_p)) { item_amount_bind_t v; int bind = 0; if (::sscanf(token, "%d,%d,%d", &v.cid_, &v.amount_, &bind) != 3) return -1; v.bind_ = bind; cjo->lucky_award_.push_back(v); } } return 0; }
void AI_Machine::init(void) { const Json::Value &all_ai_json = CONFIG_INSTANCE->config_json()["ai"]["ai_behavior"]; if (all_ai_json == Json::Value::null) { LOG_ABORT("configure file error."); } for (Json::Value::iterator iter = all_ai_json.begin(); iter != all_ai_json.end(); ++iter) { int ai_id = atoi(iter.key().asCString()); AI_Data *ai_data = new AI_Data; Composite_Node *ai_behavior = new CompositeNode_Selector(); ai_data->ai_behavior = ai_behavior; behavior_init(*iter, ai_behavior); ai_data_map_.insert(std::make_pair(ai_id, ai_data)); } { Composite_Node* pselect_idle = new CompositeNode_Selector(); pselect_idle->add_child(CREATE_TERMINATE_NODE(Be_Idle)); blockhead_ai_ = pselect_idle; } { Composite_Node* psequence_ai_behavior = new CompositeNode_Sequence(); psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Co_Idle_Status)); psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Be_Idle)); //psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Co_Die_Status)); //psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Be_NPC_Recover)); normal_ai_ = psequence_ai_behavior; } }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, SKILL_CFG_PATH, root) != 0) return -1; for (int i = CAREER_LI_LIANG; i <= CAREER_ZHI_LI; ++i) this->career_skill_map_.insert(i, new ilist<int>()); for(Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int cid = ::atoi(iter.key().asCString()); if (!clsid::is_skill(cid)) { e_log->error("%d is not skill in %s!", cid, SKILL_CFG_PATH); return -1; } skill_cfg_obj *sco = new skill_cfg_obj(); this->skill_cfg_obj_map_.insert(std::make_pair(cid, sco)); if (this->load_json(*iter, sco, cid) != 0) return -1; if (clsid::is_char_skill(cid) && util::is_career_ok(sco->career_)) this->career_skill_map_.find(sco->career_)->push_back(cid); } return 0; }
void InfrastructureFactory::registerFloorTile( const std::string& path ) { std::string fullPath = path + "/" + TILE_SYSTEM_ROOT; std::ifstream definitionFile; definitionFile.exceptions( std::ios::failbit | std::ios::badbit ); definitionFile.open( fullPath ); Json::Reader reader; Json::Value definitionJSON; if( reader.parse( definitionFile, definitionJSON ) ) { for( Json::Value::iterator jsonIterator = definitionJSON.begin(); jsonIterator != definitionJSON.end(); ++jsonIterator ) { std::string key = jsonIterator.key().asString(); Json::Value tileDefinition = *jsonIterator; if( tileDefinition.isMember( "sound" ) && tileDefinition.isMember( "image" ) ) { tileRegistry[ key ] = std::make_shared< Tile >( key, path + "/" + getVariableOrValue( "sound", tileDefinition[ "sound" ].asString() ), path + "/" + getVariableOrValue( "image", tileDefinition[ "image" ].asString() ), tileDefinition[ "price" ].asDouble() ); Log::getInstance().debug( "InfrastructureFactory::registerFloorTile" , "Registered " + key + " at " + fullPath ); } else { Log::getInstance().error( "InfrastructureFactory::registerFloorTile", "Unable to create floor tile at path " + fullPath + ": missing fields." ); } } } else { Log::getInstance().error( "InfrastructureFactory::registerFloorTile", "Unable to parse JSON file " + fullPath ); } }
void SagoSpriteHolder::ReadSpriteFile(const std::string& filename) { string fullfile = "sprites/"+filename; string content = sago::GetFileContent(fullfile.c_str()); Json::Value root; // will contains the root value after parsing Json::Reader reader; bool parsingSuccessful = reader.parse( content, root ); if ( !parsingSuccessful ) { cerr << "Failed to parse: " << fullfile << "\n" << reader.getFormattedErrorMessages() << "\n"; return; } for (Json::Value::iterator it = root.begin(); it != root.end() ; ++it) { string spriteName = it.key().asString(); Json::Value value = (*it); string textureName = value.get("texture","fallback").asString(); int topx = value.get("topx",0).asInt(); int topy = value.get("topy",0).asInt(); int height = value.get("height",0).asInt(); int width = value.get("width",0).asInt(); int number_of_frames = value.get("number_of_frames",1).asInt(); int frame_time = value.get("frame_time",1).asInt(); int originx = value.get("originx",0).asInt(); int originy = value.get("originy",0).asInt(); if (number_of_frames < 1) { number_of_frames = 1; } if (frame_time < 1) { frame_time = 1; } std::shared_ptr<sago::SagoSprite> ptr(new SagoSprite(*(data->tex),textureName, {topx,topy,width,height},number_of_frames,frame_time)); ptr->SetOrigin({originx,originy, 0, 0}); this->data->sprites[std::string(spriteName)] = ptr; } }
Bool HawkJson::Parse(const Char* pData, Int32 iSize) { Json::Reader jReader; Json::Value sRoot; if (jReader.parse(pData, sRoot,false)) { for(Json::Value::iterator it = sRoot.begin(); it != sRoot.end(); it++) { const Json::Value& sJsonKey = it.key(); if (sJsonKey.isNull()) return false; AString sKey = sJsonKey.asString(); const Json::Value& sJsonVal = sRoot[sKey.c_str()]; if (sJsonVal.isNull()) return false; JsonVal* pVal = new JsonVal; if (ParseJsonVal(&sJsonVal, pVal)) { m_sRoot[sKey] = pVal; } else { HAWK_DELETE(pVal); return false; } } return true; } return false; }
void InfrastructureFactory::registerWallpaper( const std::string& path ) { std::string fullPath = path + "/" + WALL_SYSTEM_ROOT; std::ifstream definitionFile; definitionFile.exceptions( std::ios::failbit | std::ios::badbit ); definitionFile.open( fullPath ); Json::Reader reader; Json::Value definitionJSON; if( reader.parse( definitionFile, definitionJSON ) ) { for( Json::Value::iterator jsonIterator = definitionJSON.begin(); jsonIterator != definitionJSON.end(); ++jsonIterator ) { std::string key = jsonIterator.key().asString(); if( key != "_grey" ) { Json::Value wallpaperDefinition = *jsonIterator; if( wallpaperDefinition.isMember( "image" ) ) { wallpaperRegistry[ key ] = std::make_shared< Wallpaper >( key, path + "/" + wallpaperDefinition[ "image" ].asString(), wallpaperDefinition[ "price" ].asDouble() ); Log::getInstance().debug( "InfrastructureFactory::registerWallpaper" , "Registered " + key + " at " + fullPath ); } else { Log::getInstance().error( "InfrastructureFactory::registerWallpaper", "Unable to create wallpaper at path " + fullPath + ": missing fields." ); } } else { Log::getInstance().warn( "InfrastructureFactory::registerWallpaper", "Cannot register wallpaper: \"_grey\" is a reserved id." ); } } } else { Log::getInstance().error( "InfrastructureFactory::wallpaper", "Unable to parse JSON file " + fullPath ); } }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, JING_JI_AWARD_CFG_PATH, root) != 0) return -1; for (Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int id = ::atoi(iter.key().asCString()); if (id >= MAX_AWARD_KIND_COUNT) return -1; jj_award_obj *jao = new jj_award_obj(); this->jj_award_obj_map_.insert(id, jao); jao->rank_min_ = (*iter)["rank_min"].asInt(); jao->rank_max_ = (*iter)["rank_max"].asInt(); jao->bind_diamond_ = (*iter)["bind_zuanshi"].asInt(); jao->coin_ = (*iter)["coin"].asInt(); jao->ji_fen_ = (*iter)["ji_fen"].asInt(); } return 0; }
bool CPhilipsHue::GetLights(const Json::Value &root) { if (root["lights"].empty()) return false; for (Json::Value::iterator iLight = root["lights"].begin(); iLight != root["lights"].end(); ++iLight) { Json::Value light = *iLight; if (light.isObject()) { std::string szLID = iLight.key().asString(); int lID = atoi(szLID.c_str()); _tHueLight tlight; tlight.level = 0; tlight.sat = 0; // Philips 0- 254, should be corrected to 0 - 255 ? tlight.hue = 0; // Philips 0 - 65535, should be converted to 0 - 255 ? tlight.on = light["state"]["on"].asBool(); bool bDoSend = true; _eHueLightType LType = HLTYPE_NORMAL; if (!light["state"]["bri"].empty()) { //Lamp with brightness control LType = HLTYPE_DIM; int tbri = light["state"]["bri"].asInt(); if ((tbri != 0) && (tbri != 255)) tbri += 1; //hue reports 255 as 254 tlight.level = int((100.0f / 255.0f)*float(tbri)); } if ((!light["state"]["sat"].empty()) && (!light["state"]["hue"].empty())) { //Lamp with hue/sat control LType = HLTYPE_RGBW; tlight.sat = light["state"]["sat"].asInt(); tlight.hue = light["state"]["hue"].asInt(); } if (m_lights.find(lID) != m_lights.end()) { _tHueLight alight = m_lights[lID]; if ( (alight.on == tlight.on) && (alight.level == tlight.level) && (alight.sat == tlight.sat) && (alight.hue == tlight.hue) ) { bDoSend = false; } } m_lights[lID] = tlight; if (bDoSend) { //_log.Log(LOG_STATUS, "HueBridge state change: tbri = %d, level = %d", tbri, tlight.level); InsertUpdateSwitch(lID, LType, tlight.on, tlight.level, tlight.sat, tlight.hue, light["name"].asString(), ""); } } } return true; }
Res ParseValueStringOrMap(const Context* ctx, Config* cfg, const Json::Value& val, const string& equals_string, const string& separator_string, string* out) { if (val.isString()) { *out = val.asString(); } else if (val.isArray()) { // Evaluate as a lisp expression. Res err = EvalToString(ctx, cfg, val, out); if (!err.Ok()) { err.AppendDetail("in ParseValueStringOrMap(): array eval of '" + val.toStyledString() + "'"); return err; } } else if (val.isObject()) { // Evaluate as a named-value map. bool done_first = false; out->clear(); for (Json::Value::iterator it = val.begin(); it != val.end(); ++it) { if (!it.key().isString()) { return Res(ERR_PARSE, "ParseValueStringOrMap(): key is not a string: '" + it.key().toStyledString()); } const Json::Value& map_val = *it; string result; Res err = EvalToString(ctx, cfg, map_val, &result); if (!err.Ok()) { err.AppendDetail("in ParseValueStringOrMap(): key '" + it.key().toStyledString() + "'"); return err; } if (done_first) { *out += separator_string; } *out += it.key().asString(); *out += equals_string; *out += result; done_first = true; } } return Res(OK); }
int load_json(Json::Value &root) { for (Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int id = ::atoi(iter.key().asCString()); _mst_spawn_info *p = new _mst_spawn_info(); p->idx_ = id; p->mst_cid_ = (*iter)["monster_cid"].asInt(); p->dir_ = (*iter)["toward"].asInt(); this->mst_spawn_info_map_.insert(p->idx_, p); } return 0; }
/** * Clumsily define the defaults application-wide in this constructor. * Is there a way to do this in bulk using C++11 uniform initialisation? */ ConfigManager::ConfigManager() { configRoot[ "fps_overview" ] = 30; configRoot[ "vsync_limiter_overview" ] = false; configRoot[ "min_log_level" ] = 0; configRoot[ "logfile_path" ] = "bluebear.log"; configRoot[ "logger_mode" ] = 0; configRoot[ "viewport_x" ] = 1024; configRoot[ "viewport_y" ] = 768; configRoot[ "current_locale" ] = "en_US"; configRoot[ "key_switch_perspective" ] = sf::Keyboard::P; configRoot[ "key_move_up" ] = sf::Keyboard::Up; configRoot[ "key_move_down" ] = sf::Keyboard::Down; configRoot[ "key_move_left" ] = sf::Keyboard::Left; configRoot[ "key_move_right" ] = sf::Keyboard::Right; configRoot[ "key_terminal" ] = sf::Keyboard::Tilde; configRoot[ "key_pause" ] = sf::Keyboard::Num1; configRoot[ "key_play" ] = sf::Keyboard::Num2; configRoot[ "key_play_fast" ] = sf::Keyboard::Num3; configRoot[ "key_rotate_right" ] = sf::Keyboard::E; configRoot[ "key_rotate_left" ] = sf::Keyboard::Q; configRoot[ "key_zoom_in" ] = sf::Keyboard::Add; configRoot[ "key_zoom_out" ] = sf::Keyboard::Subtract; configRoot[ "disable_image_cache" ] = false; configRoot[ "disable_texture_cache" ] = false; configRoot[ "ui_theme" ] = "system/ui/default.theme"; configRoot[ "max_ingame_terminal_scrollback" ] = 100; // Load settings.json from file std::ifstream settingsFile( SETTINGS_PATH ); Json::Value settingsJSON; Json::Reader reader; if( reader.parse( settingsFile, settingsJSON ) ) { // Override defaults // iterators - barf for( Json::Value::iterator jsonIterator = settingsJSON.begin(); jsonIterator != settingsJSON.end(); ++jsonIterator ) { // BARF Json::Value key = jsonIterator.key(); Json::Value value = *jsonIterator; // Store every value as a string because strong typing is a PITA configRoot[ key.asString() ] = value; } } }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, MAIL_CFG_PATH, root) != 0) return -1; for(Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int id = ::atoi(iter.key().asCString()); mail_obj *mo = new mail_obj(); this->mail_obj_map_.insert(id, mo); if (this->load_json(*iter, mo) != 0) return -1; } return 0; }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, SCENE_MONSTER_CFG_PATH, root) != 0) return -1; for(Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int scene_cid = ::atoi(iter.key().asCString()); monster_info *mi = new monster_info(); this->scene_mst_map_.insert(scene_cid, mi); if (mi->load_json(*iter) != 0) return -1; } return 0; }
bool CPhilipsHue::GetScenes(const Json::Value &root) { if (root["scenes"].empty()) return false; int ii=0; for (Json::Value::iterator iScene = root["scenes"].begin(); iScene != root["scenes"].end(); ++iScene) { Json::Value scene = *iScene; if (scene.isObject()) { _tHueScene hscene; hscene.id = iScene.key().asString();; hscene.name = scene["name"].asString(); hscene.lastupdated = scene["lastupdated"].asString(); //Strip some info size_t tpos = hscene.name.find(" from "); if (tpos != std::string::npos) { hscene.name = hscene.name.substr(0, tpos); } int sID = ii + 1; bool bDoSend = true; if (m_scenes.find(hscene.id) != m_scenes.end()) { _tHueScene ascene = m_scenes[hscene.id]; if (ascene.lastupdated == hscene.lastupdated) { bDoSend = false; } } m_scenes[hscene.id] = hscene; if (bDoSend) { std::string Name = "Scene " + hscene.name; InsertUpdateSwitch(2000 + sID, HLTYPE_SCENE, false, 1000, 0, 0, Name, hscene.id); } } ii++; } return true; }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, FA_BAO_DENG_JIE_CFG_PATH, root) != 0) return -1; for(Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int dj = ::atoi(iter.key().asCString()); fa_bao_dj_cfg_obj *p = new fa_bao_dj_cfg_obj(); this->fa_bao_dj_map_.insert(dj, p); if (dj > FA_BAO_MAX_DJ) return -1; Json::Value &jv = *iter; char bf[256] = {0}; ::strncpy(bf, jv["part"].asCString(), sizeof(bf)); char *tok_p = NULL; char *token = NULL; int part = 1; for (token = ::strtok_r(bf, ",", &tok_p); token != NULL; token = ::strtok_r(NULL, ",", &tok_p)) { if (part > FA_BAO_PART_CNT) return -1; p->part_fa_bao_cid_[part++] = ::atoi(token); } p->hp_recover_ = jv["sheng_ming_recover"].asInt(); p->mp_recover_ = jv["fa_li_recover"].asInt(); p->add_extra_hurt_ = jv["add_extra_hurt"].asInt(); p->reduce_hurt_ = jv["reduce_hurt"].asInt(); p->attr_rate_[ATTR_T_HP] = jv["sheng_ming"].asInt(); p->attr_rate_[ATTR_T_MP] = jv["fa_li"].asInt(); p->attr_rate_[ATTR_T_GONG_JI] = jv["gong_ji"].asInt(); p->attr_rate_[ATTR_T_FANG_YU] = jv["fang_yu"].asInt(); p->attr_rate_[ATTR_T_MING_ZHONG] = jv["ming_zhong"].asInt(); p->attr_rate_[ATTR_T_SHAN_BI] = jv["shan_bi"].asInt(); p->attr_rate_[ATTR_T_BAO_JI] = jv["bao_ji"].asInt(); p->attr_rate_[ATTR_T_KANG_BAO] = jv["kang_bao"].asInt(); p->attr_rate_[ATTR_T_SHANG_MIAN] = jv["shang_mian"].asInt(); } return 0; }
void configure( const std::string& jsonPath ) { mappings.clear(); std::ifstream schemaFile; // std::ifstream::failure schemaFile.exceptions( std::ios::failbit | std::ios::badbit ); schemaFile.open( jsonPath ); Json::Value schema; Json::Reader reader; if( !reader.parse( schemaFile, schema ) ) { throw CannotLoadFileException(); } // Create a base image on which to overlay existing images Json::Value baseProps = schema[ "base" ]; Json::Value components = schema[ "mappings" ]; // Dispose of any old image base = sf::Image(); if( baseProps[ "image" ].isString() ) { if( !base.loadFromFile( baseProps[ "image" ].asString() ) ) { throw CannotLoadFileException(); } } else { base.create( baseProps[ "width" ].asInt(), baseProps[ "height" ].asInt() ); } // Load all components into mappings for( Json::Value::iterator jsonIterator = components.begin(); jsonIterator != components.end(); ++jsonIterator ) { std::string key = jsonIterator.key().asString(); Json::Value value = *jsonIterator; mappings[ key ] = AtlasMapping{ ( unsigned int ) value[ "x" ].asInt(), ( unsigned int ) value[ "y" ].asInt(), ( unsigned int ) value[ "width" ].asInt(), ( unsigned int ) value[ "height" ].asInt(), "" }; } }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, LUCKY_GOODS_DRAW_CFG_PATH, root) != 0) return -1; for(Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int cnt = ::atoi(iter.key().asCString()); if (cnt >= MAX_LUCKY_GOODS_DRAW_CNT) return -1; ilist<lucky_goods_draw_cfg_obj *> *p = new ilist<lucky_goods_draw_cfg_obj *>(); this->draw_item_obj_map_.insert(cnt, p); Json::Value &v = *iter; for (Json::Value::iterator i_iter = v.begin(); i_iter != v.end(); ++i_iter) { Json::Value &item_v = *i_iter; lucky_goods_draw_cfg_obj *pi = new lucky_goods_draw_cfg_obj(); p->push_back(pi); pi->item_cid_ = item_v["item_cid"].asInt(); if (!item_config::instance()->find(pi->item_cid_)) { e_log->error("item %d not found!", pi->item_cid_); return -1; } pi->min_cnt_ = item_v["min_item_cnt"].asInt(); pi->max_cnt_ = item_v["max_item_cnt"].asInt(); if (pi->max_cnt_ < pi->min_cnt_) { e_log->rinfo("%d max cnt %d:%d is invalid!", pi->item_cid_, pi->max_cnt_, pi->min_cnt_); return -1; } pi->bind_type_ = item_v["bind"].asInt(); pi->rate_ = item_v["p"].asInt(); } } return 0; }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, WILD_BOSS_CFG_PATH, root) != 0) return -1; for (Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int id = ::atoi(iter.key().asCString()); wild_boss_config::wild_boss *wb = new wild_boss_config::wild_boss(); this->wild_boss_list_.push_back(wb); wb->index_ = id; if (this->load_json(*iter, wb) != 0) return -1; } return 0; }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, FA_BAO_HE_CHENG_CFG_PATH, root) != 0) return -1; for(Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int cid = ::atoi(iter.key().asCString()); if (!item_config::instance()->find(cid)) { e_log->error("fa_bao_he_cheng[%d] is nonexistent!", cid); return -1; } fa_bao_he_cheng_cfg_obj *p = new fa_bao_he_cheng_cfg_obj(); this->fa_bao_he_cheng_map_.insert(std::make_pair(cid, p)); if (this->load_json(*iter, p) != 0) return -1; } return 0; }
// json -> table bool json2table(lua_State* tolua_S, Json::Value& val) { if (!lua_istable(tolua_S, -1)) { return false; } if (val.type() != Json::objectValue) { return false; } for (Json::Value::iterator it = val.begin(); it != val.end(); ++it) { Json::Value& k = it.key(); Json::Value& v = (*it); string& strK = k.asString(); if (v.type() == Json::objectValue) { lua_newtable(tolua_S); if (!json2table(tolua_S, v)) { lua_pop(tolua_S, 1); return false; } } else { string& strV = v.asString(); tolua_pushstring(tolua_S, strV.c_str()); } lua_setfield(tolua_S, -2, strK.c_str()); } return true; }
int load_config(const char *cfg_root) { Json::Value root; if (this->load_json_cfg(cfg_root, TIANFU_SKILL_UPGRADE_CFG_PATH, root) != 0) return -1; for(Json::Value::iterator iter = root.begin(); iter != root.end(); ++iter) { int lvl = ::atoi(iter.key().asCString()); if (lvl > global_param_cfg::tianfu_lvl_limit) return -1; tianfu_skill_upgrade_cfg_obj *p = new tianfu_skill_upgrade_cfg_obj(); this->upgrade_cfg_obj_map_.insert(lvl, p); p->cost_ = (*iter)["cost"].asInt(); p->exp_ = (*iter)["exp"].asInt(); p->item_cid_ = (*iter)["item_cid"].asInt(); p->item_cnt_ = (*iter)["item_cnt"].asInt(); p->item_exp_ = (*iter)["item_exp"].asInt(); } return 0; }
int load_json(Json::Value &root, skill_cfg_obj *sco, const int skill_cid) { sco->skill_cid_ = skill_cid; sco->career_ = root["career"].asInt(); sco->hurt_delay_ = root["hurt_delay"].asInt(); Json::Value &detail_v = root["info"]; if (detail_v.empty()) return -1; for (Json::Value::iterator iter = detail_v.begin(); iter != detail_v.end(); ++iter) { int i = ::atoi(iter.key().asCString()); Json::Value &dv = *iter; if (!dv.empty()) { if (i < 1 || i >= MAX_SKILL_LEVEL) { e_log->error("skill lvl is invalid! lvl = %d", i); return -1; } skill_detail *sd = new skill_detail(); sd->cur_lvl_ = i; sco->details_[i] = sd; if (this->load_json(dv, sd) != 0) return -1; } } if (sco->get_detail(1) == NULL) { e_log->error("skill %d not found lvl 1 info!", skill_cid); return -1; } return 0; }
void Furnitures::loadJsonSheet(const std::string& jsonSheetPath, const double zoomX, const double zoomY) { Json::Reader jsonReader; Json::Value jsonRoot; ifstream jsonFile; jsonFile.open(jsonSheetPath.c_str(), ios::binary); if (jsonFile.is_open()) { if (jsonReader.parse(jsonFile, jsonRoot)) { for(Json::Value::iterator it = jsonRoot.begin(); it != jsonRoot.end(); it++) { SDL_Rect rect; rect = {(*it)["x"].asInt(), (*it)["y"].asInt(), (*it)["w"].asInt(), (*it)["h"].asInt()}; if (zoomX != 1 && zoomY != 1) { rect.x *= zoomX; rect.y *= zoomY; rect.w *= zoomX; rect.h *= zoomY; } furnituresPixelDimensions.insert(make_pair(it.key().asString(), rect)); } } } else { SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Error reading Json SpriteSheet file in : %s because:", jsonSheetPath.c_str(), strerror( errno )); throw error::READ_SPRITESHEETS_JSON_FAIL; } }
int gameplay_ctrl_db_proc::load_activity_data() { ctrl_data::instance()->map_act_.clear(); Json::Value root; Game_Data::Container_Mgr::instance()->get_json_value_by_file_name( root, ACTIVITY_CFG_FILE); for (Json::Value::iterator p = root.begin(); p != root.end(); p++) { //load each activity std::string s_act_id = p.key().asCString(); activity *act = new activity; act->id_ = atoi(s_act_id.c_str()); if (load_act_item(act,root[s_act_id]) == 0) gameplay_ctrl_data_mgr::load_act_item(act); } cout << "\n load activity data over----------------" << endl; return 0; }
ShipType::ShipType(const Id &_id, const std::string &path) { Json::Reader reader; Json::Value data; isGlobalColorDefined = false; auto fd = FileSystem::gameDataFiles.ReadFile(path); if (!fd) { Output("couldn't open ship def '%s'\n", path.c_str()); return; } if (!reader.parse(fd->GetData(), fd->GetData()+fd->GetSize(), data)) { Output("couldn't read ship def '%s': %s\n", path.c_str(), reader.getFormattedErrorMessages().c_str()); return; } // determine what kind (tag) of ship this is. const std::string tagStr = data.get("tag", "").asString(); if( tagStr.empty() || strcasecmp(tagStr.c_str(), "ship")==0 ) { tag = TAG_SHIP; } else if( strcasecmp(tagStr.c_str(), "static")==0 ) { tag = TAG_STATIC_SHIP; } else if( strcasecmp(tagStr.c_str(), "missile")==0 ) { tag = TAG_MISSILE; } id = _id; name = data.get("name", "").asString(); shipClass = data.get("ship_class", "").asString(); manufacturer = data.get("manufacturer", "").asString(); modelName = data.get("model", "").asString(); cockpitName = data.get("cockpit", "").asString(); linThrust[THRUSTER_REVERSE] = data.get("reverse_thrust", 0.0f).asFloat(); linThrust[THRUSTER_FORWARD] = data.get("forward_thrust", 0.0f).asFloat(); linThrust[THRUSTER_UP] = data.get("up_thrust", 0.0f).asFloat(); linThrust[THRUSTER_DOWN] = data.get("down_thrust", 0.0f).asFloat(); linThrust[THRUSTER_LEFT] = data.get("left_thrust", 0.0f).asFloat(); linThrust[THRUSTER_RIGHT] = data.get("right_thrust", 0.0f).asFloat(); angThrust = data.get("angular_thrust", 0.0f).asFloat(); // Parse global thrusters color bool error = false; int parse = 0; for( Json::Value::iterator thruster_color = data["thruster_global_color"].begin() ; thruster_color != data["thruster_global_color"].end() ; ++thruster_color ) { const std::string colorchannel = thruster_color.key().asString(); if (colorchannel.length()!=1) { error = true; break; } if (colorchannel.at(0) == 'r') { globalThrusterColor.r = data["thruster_global_color"].get(colorchannel, 0).asInt(); parse++; continue; } else if (colorchannel.at(0) == 'g') { globalThrusterColor.g = data["thruster_global_color"].get(colorchannel, 0).asInt(); parse++; continue; } else if (colorchannel.at(0) == 'b') { globalThrusterColor.b = data["thruster_global_color"].get(colorchannel, 0).asInt(); parse++; continue; } else { // No 'r', no 'g', no 'b', no good :/ error = true; break; } } if (error==true) { Output("In file \"%s.json\" global thrusters custom color must be \"r\",\"g\" and \"b\"\n", modelName.c_str()); } else if (parse>0 && parse<3) { Output("In file \"%s.json\" global thrusters custom color is malformed\n", modelName.c_str()); } else if (parse==3) { globalThrusterColor.a = 255; isGlobalColorDefined = true; } // Parse direction thrusters color for (int i=0; i<THRUSTER_MAX; i++) isDirectionColorDefined[i]=false; error = false; for( Json::Value::iterator thruster_color = data["thruster_direction_color"].begin() ; thruster_color != data["thruster_direction_color"].end() ; ++thruster_color ) { const std::string th_color_dir = thruster_color.key().asString(); Json::Value dir_color = data["thruster_direction_color"].get(th_color_dir, 0); Color color; if (!dir_color.isMember("r")||!dir_color.isMember("g")||!dir_color.isMember("b")) { error = true; continue /* for */; } else { color.r = dir_color["r"].asInt(); color.g = dir_color["g"].asInt(); color.b = dir_color["b"].asInt(); color.a = 255; } if (th_color_dir.find("forward")!=std::string::npos) { isDirectionColorDefined[THRUSTER_FORWARD]=true; directionThrusterColor[THRUSTER_FORWARD]= color; } if (th_color_dir.find("retro")!=std::string::npos) { isDirectionColorDefined[THRUSTER_REVERSE]=true; directionThrusterColor[THRUSTER_REVERSE]= color; } if (th_color_dir.find("left")!=std::string::npos) { isDirectionColorDefined[THRUSTER_LEFT]=true; directionThrusterColor[THRUSTER_LEFT]= color; } if (th_color_dir.find("right")!=std::string::npos) { isDirectionColorDefined[THRUSTER_RIGHT]=true; directionThrusterColor[THRUSTER_RIGHT]= color; } if (th_color_dir.find("up")!=std::string::npos) { isDirectionColorDefined[THRUSTER_UP]=true; directionThrusterColor[THRUSTER_UP]= color; } if (th_color_dir.find("down")!=std::string::npos) { isDirectionColorDefined[THRUSTER_DOWN]=true; directionThrusterColor[THRUSTER_DOWN]= color; } } if (error==true) { for (int i=0; i<THRUSTER_MAX; i++) isDirectionColorDefined[i]=false; Output("In file \"%s.json\" directional thrusters custom color must be \"r\",\"g\" and \"b\"\n", modelName.c_str()); } // invert values where necessary linThrust[THRUSTER_FORWARD] *= -1.f; linThrust[THRUSTER_LEFT] *= -1.f; linThrust[THRUSTER_DOWN] *= -1.f; // angthrust fudge (XXX: why?) angThrust = angThrust * 0.5f; hullMass = data.get("hull_mass", 100).asInt(); capacity = data.get("capacity", 0).asInt(); fuelTankMass = data.get("fuel_tank_mass", 5).asInt(); for( Json::Value::iterator slot = data["slots"].begin() ; slot != data["slots"].end() ; ++slot ) { const std::string slotname = slot.key().asString(); slots[slotname] = data["slots"].get(slotname, 0).asInt(); } for( Json::Value::iterator role = data["roles"].begin(); role != data["roles"].end(); ++role ) { const std::string rolename = role.key().asString(); roles[rolename] = data["roles"].get(rolename, 0).asBool(); } for(int it=0;it<4;it++) thrusterUpgrades[it] = 1.0 + (double(it)/10.0); for( Json::Value::iterator slot = data["thrust_upgrades"].begin() ; slot != data["thrust_upgrades"].end() ; ++slot ) { const std::string slotname = slot.key().asString(); const int index = Clamp(atoi(&slotname.c_str()[9]), 1, 3); thrusterUpgrades[index] = data["thrust_upgrades"].get(slotname, 0).asDouble(); } atmosphericPressureLimit = data.get("atmospheric_pressure_limit", 10.0).asDouble(); // 10 atmosphere is about 90 metres underwater (on Earth) { const auto it = slots.find("engine"); if (it != slots.end()) { it->second = Clamp(it->second, 0, 1); } } effectiveExhaustVelocity = data.get("effective_exhaust_velocity", -1.0f).asFloat(); const float thruster_fuel_use = data.get("thruster_fuel_use", -1.0f).asFloat(); if(effectiveExhaustVelocity < 0 && thruster_fuel_use < 0) { // default value of v_c is used effectiveExhaustVelocity = 55000000; } else if(effectiveExhaustVelocity < 0 && thruster_fuel_use >= 0) { // v_c undefined and thruster fuel use defined -- use it! effectiveExhaustVelocity = GetEffectiveExhaustVelocity(fuelTankMass, thruster_fuel_use, linThrust[Thruster::THRUSTER_FORWARD]); } else { if(thruster_fuel_use >= 0) { Output("Warning: Both thruster_fuel_use and effective_exhaust_velocity defined for %s, using effective_exhaust_velocity.\n", modelName.c_str()); } } baseprice = data.get("price", 0.0).asDouble(); minCrew = data.get("min_crew", 1).asInt(); maxCrew = data.get("max_crew", 1).asInt(); hyperdriveClass = data.get("hyperdrive_class", 1).asInt(); }
bool CPhilipsHue::GetGroups(const Json::Value &root) { //Groups (0=All) if (root["groups"].empty()) return false; for (Json::Value::iterator iGroup = root["groups"].begin(); iGroup != root["groups"].end(); ++iGroup) { Json::Value group = *iGroup; if (group.isObject()) { std::string szGID = iGroup.key().asString(); int gID = atoi(szGID.c_str()); bool bIsOn = false; int tbri = 255; int tsat = 255; int thue = 255; if (!group["action"]["on"].empty()) bIsOn = group["action"]["on"].asBool(); if (!group["action"]["bri"].empty()) tbri = group["action"]["bri"].asInt(); if (!group["action"]["sat"].empty()) tsat = group["action"]["sat"].asInt(); if (!group["action"]["hue"].empty()) thue = group["action"]["hue"].asInt(); if ((tbri != 0) && (tbri != 255)) tbri += 1; //hue reports 255 as 254 int BrightnessLevel = int((100.0f / 255.0f)*float(tbri)); _tHueLight tstate; if (bIsOn) { tstate.cmd = (BrightnessLevel != 0) ? Limitless_SetBrightnessLevel : Limitless_LedOn; } else tstate.cmd = Limitless_LedOff; tstate.level = BrightnessLevel; tstate.sat = tsat; tstate.hue = thue; bool bDoSend = true; if (m_groups.find(gID) != m_groups.end()) { _tHueGroup agroup = m_groups[gID]; if ( (agroup.gstate.cmd == tstate.cmd) && (agroup.gstate.level == tstate.level) && (agroup.gstate.sat == tstate.sat) && (agroup.gstate.hue == tstate.hue) ) { bDoSend = false; } } m_groups[gID].gstate = tstate; if (bDoSend) { std::string Name = "Group " + group["name"].asString(); InsertUpdateSwitch(1000 + gID, HLTYPE_RGBW, bIsOn, BrightnessLevel, tsat, thue, Name, ""); } } } //Special Request for Group0 (All Lights) std::stringstream sstr2; sstr2 << "http://" << m_IPAddress << ":" << m_Port << "/api/" << m_UserName << "/groups/0"; std::string sResult; std::vector<std::string> ExtraHeaders; if (!HTTPClient::GET(sstr2.str(), ExtraHeaders, sResult)) { //No group all(0) return true; } Json::Reader jReader; Json::Value root2; bool ret = jReader.parse(sResult, root2); ret = jReader.parse(sResult, root2); if (!ret) { _log.Log(LOG_ERROR, "Philips Hue: Invalid data received, or invalid IPAddress/Username!"); return false; } if (sResult.find("\"error\":") != std::string::npos) { //We had an error _log.Log(LOG_ERROR, "Philips Hue: Error received: %s", root2[0]["error"]["description"].asString().c_str()); return false; } if (sResult.find("lights") == std::string::npos) { return false; } bool bIsOn = false; int tbri = 255; int tsat = 255; int thue = 255; if (!root2["action"]["on"].empty()) bIsOn = root2["action"]["on"].asBool(); if (!root2["action"]["bri"].empty()) tbri = root2["action"]["bri"].asInt(); if (!root2["action"]["sat"].empty()) tsat = root2["action"]["sat"].asInt(); if (!root2["action"]["hue"].empty()) thue = root2["action"]["hue"].asInt(); if ((tbri != 0) && (tbri != 255)) tbri += 1; //hue reports 255 as 254 int BrightnessLevel = int((100.0f / 255.0f)*float(tbri)); _tHueLight tstate; if (bIsOn) { tstate.cmd = (BrightnessLevel != 0) ? Limitless_SetBrightnessLevel : Limitless_LedOn; } else tstate.cmd = Limitless_LedOff; tstate.level = BrightnessLevel; tstate.sat = tsat; tstate.hue = thue; bool bDoSend = true; int gID = 0; if (m_groups.find(gID) != m_groups.end()) { _tHueGroup agroup = m_groups[gID]; if ( (agroup.gstate.cmd == tstate.cmd) && (agroup.gstate.level == tstate.level) && (agroup.gstate.sat == tstate.sat) && (agroup.gstate.hue == tstate.hue) ) { bDoSend = false; } } m_groups[gID].gstate = tstate; if (bDoSend) { std::string Name = "Group All Lights"; InsertUpdateSwitch(1000 + gID, HLTYPE_RGBW, bIsOn, BrightnessLevel, tsat, thue, Name,""); } return true; }
bool CPhilipsHue::GetLights(const Json::Value &root) { if (root["lights"].empty()) return false; for (Json::Value::iterator iLight = root["lights"].begin(); iLight != root["lights"].end(); ++iLight) { Json::Value light = *iLight; if (light.isObject()) { std::string szLID = iLight.key().asString(); int lID = atoi(szLID.c_str()); _tHueLight tlight; int BrightnessLevel = 0; tlight.level = 0; tlight.sat = 0; tlight.hue = 0; int tbri = 0; bool bIsOn = light["state"]["on"].asBool(); bool bDoSend = true; _eHueLightType LType = HLTYPE_NORMAL; if (bIsOn) { tlight.cmd = light2_sOn; } else tlight.cmd = light2_sOff; if (!light["state"]["bri"].empty()) { //Lamp with brightness control LType = HLTYPE_DIM; tbri = light["state"]["bri"].asInt(); if ((tbri != 0) && (tbri != 255)) tbri += 1; //hue reports 255 as 254 tlight.level = tbri; BrightnessLevel = int((100.0f / 255.0f)*float(tbri)); if (bIsOn) { tlight.cmd = (BrightnessLevel != 0) ? light2_sSetLevel : light2_sOn; } else tlight.cmd = light2_sOff; } if ((!light["state"]["sat"].empty()) && (!light["state"]["hue"].empty())) { //Lamp with hue/sat control LType = HLTYPE_RGBW; tlight.sat = light["state"]["sat"].asInt(); tlight.hue = light["state"]["hue"].asInt(); if (bIsOn) { tlight.cmd = (BrightnessLevel != 0) ? Limitless_SetBrightnessLevel : Limitless_LedOn; } else tlight.cmd = Limitless_LedOff; } if (m_lights.find(lID) != m_lights.end()) { _tHueLight alight = m_lights[lID]; if ( (alight.cmd == tlight.cmd) && (alight.level == tlight.level) && (alight.sat == tlight.sat) && (alight.hue == tlight.hue) ) { bDoSend = false; } } m_lights[lID] = tlight; if (bDoSend) { InsertUpdateSwitch(lID, LType, bIsOn, BrightnessLevel, tlight.sat, tlight.hue, light["name"].asString(), ""); } } } return true; }