本文整理汇总了C++中JsonObject::get_array方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::get_array方法的具体用法?C++ JsonObject::get_array怎么用?C++ JsonObject::get_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject::get_array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deserialize
////////////////// mission.h
////
void mission::deserialize(JsonIn &jsin)
{
JsonObject jo = jsin.get_object();
if (jo.has_member("type_id")) {
type = &(g->mission_types[jo.get_int("type_id")]);
}
jo.read("description", description);
jo.read("failed", failed);
jo.read("value", value);
jo.read("reward", reward);
jo.read("uid", uid );
JsonArray ja = jo.get_array("target");
if (ja.size() == 2) {
target.x = ja.get_int(0);
target.y = ja.get_int(1);
}
follow_up = mission_id(jo.get_int("follow_up", follow_up));
item_id = itype_id(jo.get_string("item_id", item_id));
jo.read("deadline", deadline );
jo.read("step", step );
jo.read("count", count );
jo.read("npc_id", npc_id );
jo.read("good_fac_id", good_fac_id );
jo.read("bad_fac_id", bad_fac_id );
}
示例2: load_fault
void fault::load_fault( JsonObject &jo )
{
fault f;
f.id_ = fault_id( jo.get_string( "id" ) );
f.name_ = _( jo.get_string( "name" ) );
f.description_ = _( jo.get_string( "description" ) );
f.time_ = jo.get_int( "time" );
auto sk = jo.get_array( "skills" );
while( sk.has_more() ) {
auto cur = sk.next_array();
f.skills_.emplace( skill_id( cur.get_string( 0 ) ), cur.size() >= 2 ? cur.get_int( 1 ) : 1 );
}
if( jo.has_string( "requirements" ) ) {
f.requirements_ = requirement_id( jo.get_string( "requirements" ) );
} else {
auto req = jo.get_object( "requirements" );
const requirement_id req_id( std::string( "inline_fault_" ) + f.id_.str() );
requirement_data::load_requirement( req, req_id );
f.requirements_ = req_id;
}
if( faults_all.find( f.id_ ) != faults_all.end() ) {
jo.throw_error( "parsed fault overwrites existing definition", "id" );
} else {
faults_all[ f.id_ ] = f;
}
}
示例3: load_trap
void load_trap(JsonObject &jo)
{
std::vector<std::string> drops;
if(jo.has_member("drops")) {
JsonArray drops_list = jo.get_array("drops");
while(drops_list.has_more()) {
drops.push_back(drops_list.next_string());
}
}
std::string name = jo.get_string("name");
if (!name.empty()) {
name = _(name.c_str());
}
trap *new_trap = new trap(
jo.get_string("id"), // "tr_beartrap"
traplist.size(), // tr_beartrap
name, // "bear trap"
color_from_string(jo.get_string("color")),
jo.get_string("symbol").at(0),
jo.get_int("visibility"),
jo.get_int("avoidance"),
jo.get_int("difficulty"),
trap_function_from_string(jo.get_string("action")),
drops
);
new_trap->benign = jo.get_bool("benign", false);
new_trap->funnel_radius_mm = jo.get_int("funnel_radius", 0);
new_trap->trigger_weight = jo.get_int("trigger_weight", -1);
trapmap[new_trap->id] = new_trap->loadid;
traplist.push_back(new_trap);
}
示例4: load_gun
void Item_factory::load_gun(JsonObject& jo)
{
it_gun* gun_template = new it_gun();
gun_template->ammo = jo.get_string("ammo");
gun_template->skill_used = Skill::skill(jo.get_string("skill"));
gun_template->dmg_bonus = jo.get_int("ranged_damage");
gun_template->range = jo.get_int("range");
gun_template->dispersion = jo.get_int("dispersion");
gun_template->recoil = jo.get_int("recoil");
gun_template->durability = jo.get_int("durability");
gun_template->burst = jo.get_int("burst");
gun_template->clip = jo.get_int("clip_size");
gun_template->reload_time = jo.get_int("reload");
gun_template->pierce = jo.get_int("pierce", 0);
gun_template->ammo_effects = jo.get_tags("ammo_effects");
if ( jo.has_array("valid_mod_locations") ) {
JsonArray jarr = jo.get_array("valid_mod_locations");
while (jarr.has_more()){
JsonArray curr = jarr.next_array();
gun_template->valid_mod_locations.insert(std::pair<std::string, int>(curr.get_string(0), curr.get_int(1)));
gun_template->occupied_mod_locations.insert(std::pair<std::string, int>(curr.get_string(0), 0));
}
}
itype *new_item_template = gun_template;
load_basic_info(jo, new_item_template);
}
示例5: load_special_attacks
void MonsterGenerator::load_special_attacks(mtype *m, JsonObject &jo, std::string member) {
m->special_attacks.clear(); // make sure we're running with everything cleared
if( !jo.has_array( member ) ) {
return;
}
JsonArray outer = jo.get_array(member);
while( outer.has_more() ) {
if( outer.test_array() ) {
JsonArray inner = outer.next_array();
const auto &aname = inner.get_string(0);
if ( attack_map.find(aname) != attack_map.end() ) {
auto new_entry = mtype_special_attack(
attack_map[aname], inner.get_int(1) );
m->special_attacks[aname] = new_entry;
m->special_attacks_names.push_back(aname);
} else {
inner.throw_error("Invalid special_attacks");
}
} else if( outer.test_object() ) {
set_attack_from_object(
outer.next_object(), m->special_attacks, m->special_attacks_names );
} else {
outer.throw_error( "array element is neither array nor object." );
}
}
}
示例6: load_trap
void game::load_trap(JsonObject &jo)
{
std::vector<std::string> drops;
if(jo.has_member("drops")) {
JsonArray drops_list = jo.get_array("drops");
while(drops_list.has_more()) {
drops.push_back(drops_list.next_string());
}
}
trap *new_trap = new trap(
jo.get_string("id"), // "tr_beartrap"
g->traps.size(), // tr_beartrap
jo.get_string("name"), // "bear trap"
color_from_string(jo.get_string("color")),
jo.get_string("symbol").at(0),
jo.get_int("visibility"),
jo.get_int("avoidance"),
jo.get_int("difficulty"),
trap_function_from_string(jo.get_string("player_action")),
trap_function_mon_from_string(jo.get_string("monster_action")),
drops
);
new_trap->benign = jo.get_bool("benign", false);
new_trap->funnel_radius_mm = jo.get_int("funnel_radius", 0);
trapmap[new_trap->id] = new_trap->loadid;
traps.push_back(new_trap);
}
示例7: deserialize
void it_artifact_armor::deserialize(JsonObject &jo)
{
id = jo.get_string("id");
name = jo.get_string("name");
description = jo.get_string("description");
sym = jo.get_int("sym");
color = int_to_color(jo.get_int("color"));
price = jo.get_int("price");
m1 = jo.get_string("m1");
m2 = jo.get_string("m2");
volume = jo.get_int("volume");
weight = jo.get_int("weight");
melee_dam = jo.get_int("melee_dam");
melee_cut = jo.get_int("melee_cut");
m_to_hit = jo.get_int("m_to_hit");
item_tags = jo.get_tags("item_flags");
covers = jo.get_int("covers");
encumber = jo.get_int("encumber");
coverage = jo.get_int("coverage");
thickness = jo.get_int("material_thickness");
env_resist = jo.get_int("env_resist");
warmth = jo.get_int("warmth");
storage = jo.get_int("storage");
power_armor = jo.get_bool("power_armor");
JsonArray ja = jo.get_array("effects_worn");
while (ja.has_more()) {
effects_worn.push_back((art_effect_passive)ja.next_int());
}
}
示例8: load_vehicle_spawn
void VehicleFactory::load_vehicle_spawn(JsonObject &jo)
{
const std::string spawn_id = jo.get_string("id");
VehicleSpawn spawn;
JsonArray types = jo.get_array("spawn_types");
while (types.has_more()) {
JsonObject type = types.next_object();
if(type.has_object("vehicle_json")) {
JsonObject vjo = type.get_object("vehicle_json");
spawn.add(type.get_float("weight"), std::make_shared<VehicleFunction_json>(vjo));
}
else if(type.has_string("vehicle_function")) {
if(builtin_functions.count(type.get_string("vehicle_function")) == 0) {
type.throw_error("load_vehicle_spawn: unable to find builtin function", "vehicle_function");
}
spawn.add(type.get_float("weight"), std::make_shared<VehicleFunction_builtin>(
builtin_functions[type.get_string("vehicle_function")]));
}
else {
type.throw_error("load_vehicle_spawn: missing required vehicle_json (object) or vehicle_function (string).");
}
}
spawns[spawn_id] = spawn;
}
示例9: load_technique
void load_technique(JsonObject &jo)
{
ma_technique tec;
tec.id = jo.get_string("id");
tec.name = jo.get_string("name", "");
if (!tec.name.empty()) {
tec.name = _(tec.name.c_str());
}
JsonArray jsarr = jo.get_array("messages");
while (jsarr.has_more()) {
tec.messages.push_back(_(jsarr.next_string().c_str()));
}
tec.reqs.unarmed_allowed = jo.get_bool("unarmed_allowed", false);
tec.reqs.melee_allowed = jo.get_bool("melee_allowed", false);
tec.reqs.min_melee = jo.get_int("min_melee", 0);
tec.reqs.min_unarmed = jo.get_int("min_unarmed", 0);
tec.reqs.min_bashing = jo.get_int("min_bashing", 0);
tec.reqs.min_cutting = jo.get_int("min_cutting", 0);
tec.reqs.min_stabbing = jo.get_int("min_stabbing", 0);
tec.reqs.min_bashing_damage = jo.get_int("min_bashing_damage", 0);
tec.reqs.min_cutting_damage = jo.get_int("min_cutting_damage", 0);
tec.reqs.req_buffs = jo.get_tags("req_buffs");
tec.reqs.req_flags = jo.get_tags("req_flags");
tec.crit_tec = jo.get_bool("crit_tec", false);
tec.defensive = jo.get_bool("defensive", false);
tec.disarms = jo.get_bool("disarms", false);
tec.dodge_counter = jo.get_bool("dodge_counter", false);
tec.block_counter = jo.get_bool("block_counter", false);
tec.miss_recovery = jo.get_bool("miss_recovery", false);
tec.grab_break = jo.get_bool("grab_break", false);
tec.flaming = jo.get_bool("flaming", false);
tec.hit = jo.get_int("pain", 0);
tec.bash = jo.get_int("bash", 0);
tec.cut = jo.get_int("cut", 0);
tec.pain = jo.get_int("pain", 0);
tec.weighting = jo.get_int("weighting", 1);
tec.bash_mult = jo.get_float("bash_mult", 1.0);
tec.cut_mult = jo.get_float("cut_mult", 1.0);
tec.speed_mult = jo.get_float("speed_mult", 1.0);
tec.down_dur = jo.get_int("down_dur", 0);
tec.stun_dur = jo.get_int("stun_dur", 0);
tec.knockback_dist = jo.get_int("knockback_dist", 0);
tec.knockback_spread = jo.get_int("knockback_spread", 0);
tec.aoe = jo.get_string("aoe", "");
tec.flags = jo.get_tags("flags");
ma_techniques[tec.id] = tec;
}
示例10: load
bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) {
if( jsobj.has_object(member) ) {
JsonObject j = jsobj.get_object(member);
str_min = j.get_int("str_min", 0);
str_max = j.get_int("str_max", 0);
str_min_blocked = j.get_int("str_min_blocked", -1);
str_max_blocked = j.get_int("str_max_blocked", -1);
str_min_roll = j.get_int("str_min_roll", str_min);
str_max_roll = j.get_int("str_min_roll", str_max);
explosive = j.get_int("explosive", -1);
destroy_only = j.get_bool("destroy_only", false);
sound = j.get_string("sound", _("smash!"));
sound_fail = j.get_string("sound_fail", _("thump!"));
if (isfurniture) {
furn_set = j.get_string("furn_set", "f_null");
} else {
ter_set = j.get_string("ter_set");
}
if ( j.has_array("items") ) {
load_map_bash_item_drop_list(j.get_array("items"), items);
}
return true;
} else {
return false;
}
}
示例11: load_trait_blacklist
void mutation_branch::load_trait_blacklist( JsonObject &jsobj )
{
JsonArray jarr = jsobj.get_array( "traits" );
while( jarr.has_more() ) {
trait_blacklist.insert( trait_id( jarr.next_string() ) );
}
}
示例12: load
void trap::load( JsonObject &jo )
{
std::unique_ptr<trap> trap_ptr( new trap() );
trap &t = *trap_ptr;
if( jo.has_member( "drops" ) ) {
JsonArray drops_list = jo.get_array( "drops" );
while( drops_list.has_more() ) {
t.components.push_back( drops_list.next_string() );
}
}
t.name = jo.get_string( "name" );
if( !t.name.empty() ) {
t.name = _( t.name.c_str() );
}
t.id = trap_str_id( jo.get_string( "id" ) );
t.loadid = trap_id( traplist.size() );
t.color = color_from_string( jo.get_string( "color" ) );
t.sym = jo.get_string( "symbol" ).at( 0 );
t.visibility = jo.get_int( "visibility" );
t.avoidance = jo.get_int( "avoidance" );
t.difficulty = jo.get_int( "difficulty" );
t.act = trap_function_from_string( jo.get_string( "action" ) );
t.benign = jo.get_bool( "benign", false );
t.funnel_radius_mm = jo.get_int( "funnel_radius", 0 );
t.trigger_weight = jo.get_int( "trigger_weight", -1 );
trapmap[t.id] = t.loadid;
traplist.push_back( &t );
trap_ptr.release();
if( t.is_funnel() ) {
funnel_traps.push_back( &t );
}
}
示例13: load_recipe_category
void load_recipe_category( JsonObject &jsobj )
{
JsonArray subcats;
std::string category = jsobj.get_string( "id" );
if( category.find( "CC_" ) != 0 ) {
jsobj.throw_error( "Crafting category id has to be prefixed with 'CC_'" );
}
// Don't store noncraft as a category.
// We're storing the subcategory so we can look it up in load_recipes
// for the fallback subcategory.
if( category != "CC_NONCRAFT" ) {
craft_cat_list.push_back( category );
}
std::string cat_name = get_cat_name( category );
craft_subcat_list[category] = std::vector<std::string>();
subcats = jsobj.get_array( "recipe_subcategories" );
while( subcats.has_more() ) {
std::string subcat_id = subcats.next_string();
if( subcat_id.find( "CSC_" + cat_name + "_" ) != 0 && subcat_id != "CSC_ALL" &&
subcat_id != "CSC_NONCRAFT" ) {
jsobj.throw_error( "Crafting sub-category id has to be prefixed with CSC_<category_name>_" );
}
craft_subcat_list[category].push_back( subcat_id );
}
}
示例14: load_material
// load a material object from incoming JSON
void material_type::load_material( JsonObject &jsobj )
{
material_type mat;
mat._ident = jsobj.get_string( "ident" );
mat._name = _( jsobj.get_string( "name" ).c_str() );
mat._salvage_id = jsobj.get_string( "salvage_id", "null" );
mat._salvage_multiplier = jsobj.get_float( "salvage_multiplier", 1.0 );
mat._bash_resist = jsobj.get_int( "bash_resist" );
mat._cut_resist = jsobj.get_int( "cut_resist" );
mat._bash_dmg_verb = _( jsobj.get_string( "bash_dmg_verb" ).c_str() );
mat._cut_dmg_verb = _( jsobj.get_string( "cut_dmg_verb" ).c_str() );
mat._acid_resist = jsobj.get_int( "acid_resist" );
mat._elec_resist = jsobj.get_int( "elec_resist" );
mat._fire_resist = jsobj.get_int( "fire_resist" );
mat._chip_resist = jsobj.get_int( "chip_resist" );
mat._density = jsobj.get_int( "density" );
JsonArray jsarr = jsobj.get_array( "dmg_adj" );
mat._dmg_adj[0] = _( jsarr.next_string().c_str() );
mat._dmg_adj[1] = _( jsarr.next_string().c_str() );
mat._dmg_adj[2] = _( jsarr.next_string().c_str() );
mat._dmg_adj[3] = _( jsarr.next_string().c_str() );
_all_materials[mat._ident] = mat;
DebugLog( D_INFO, DC_ALL ) << "Loaded material: " << mat._name;
}
示例15: load_distribution
distribution load_distribution( JsonObject &jo )
{
if( jo.has_float( "constant" ) ) {
return distribution::constant( jo.get_float( "constant" ) );
}
if( jo.has_float( "one_in" ) ) {
return distribution::one_in( jo.get_float( "one_in" ) );
}
if( jo.has_array( "dice" ) ) {
JsonArray jarr = jo.get_array( "dice" );
return distribution::dice_roll( jarr.get_int( 0 ), jarr.get_int( 1 ) );
}
if( jo.has_array( "rng" ) ) {
JsonArray jarr = jo.get_array( "rng" );
return distribution::rng_roll( jarr.get_int( 0 ), jarr.get_int( 1 ) );
}
if( jo.has_array( "sum" ) ) {
JsonArray jarr = jo.get_array( "sum" );
JsonObject obj = jarr.next_object();
distribution ret = load_distribution( obj );
while( jarr.has_more() ) {
obj = jarr.next_object();
ret = ret + load_distribution( obj );
}
return ret;
}
if( jo.has_array( "mul" ) ) {
JsonArray jarr = jo.get_array( "mul" );
JsonObject obj = jarr.next_object();
distribution ret = load_distribution( obj );
while( jarr.has_more() ) {
obj = jarr.next_object();
ret = ret * load_distribution( obj );
}
return ret;
}
jo.throw_error( "Invalid distribution" );
return distribution();
}