本文整理汇总了C++中JsonArray::get_int方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonArray::get_int方法的具体用法?C++ JsonArray::get_int怎么用?C++ JsonArray::get_int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray::get_int方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_item_group
// Load an item group from JSON
void Item_factory::load_item_group(JsonObject &jsobj)
{
Item_tag group_id = jsobj.get_string("id");
Item_group *current_group;
if (m_template_groups.count(group_id) > 0) {
current_group = m_template_groups[group_id];
} else {
current_group = new Item_group(group_id);
m_template_groups[group_id] = current_group;
}
current_group->m_guns_have_ammo = jsobj.get_bool("guns_have_ammo", current_group->m_guns_have_ammo);
JsonArray items = jsobj.get_array("items");
while (items.has_more()) {
JsonArray pair = items.next_array();
current_group->add_entry(pair.get_string(0), pair.get_int(1));
}
JsonArray groups = jsobj.get_array("groups");
while (groups.has_more()) {
JsonArray pair = groups.next_array();
std::string name = pair.get_string(0);
int frequency = pair.get_int(1);
if (m_template_groups.count(name) == 0) {
m_template_groups[name] = new Item_group(name);
}
current_group->add_group(m_template_groups[name], frequency);
}
}
示例2: load_trait_group
void mutation_branch::load_trait_group( JsonObject &jsobj, const trait_group::Trait_group_tag &gid,
const std::string &subtype )
{
if( subtype != "distribution" && subtype != "collection" && subtype != "old" ) {
jsobj.throw_error( "unknown trait group type", "subtype" );
}
Trait_group &tg = make_group_or_throw( gid, ( subtype == "collection" || subtype == "old" ) );
// TODO: (sm) Looks like this makes the new code backwards-compatible with the old format. Great if so!
if( subtype == "old" ) {
JsonArray traits = jsobj.get_array( "traits" );
while( traits.has_more() ) {
JsonArray pair = traits.next_array();
tg.add_trait_entry( trait_id( pair.get_string( 0 ) ), pair.get_int( 1 ) );
}
return;
}
// TODO: (sm) Taken from item_factory.cpp almost verbatim. Ensure that these work!
if( jsobj.has_member( "entries" ) ) {
JsonArray traits = jsobj.get_array( "entries" );
while( traits.has_more() ) {
JsonObject subobj = traits.next_object();
add_entry( tg, subobj );
}
}
if( jsobj.has_member( "traits" ) ) {
JsonArray traits = jsobj.get_array( "traits" );
while( traits.has_more() ) {
if( traits.test_string() ) {
tg.add_trait_entry( trait_id( traits.next_string() ), 100 );
} else if( traits.test_array() ) {
JsonArray subtrait = traits.next_array();
tg.add_trait_entry( trait_id( subtrait.get_string( 0 ) ), subtrait.get_int( 1 ) );
} else {
JsonObject subobj = traits.next_object();
add_entry( tg, subobj );
}
}
}
if( jsobj.has_member( "groups" ) ) {
JsonArray traits = jsobj.get_array( "groups" );
while( traits.has_more() ) {
if( traits.test_string() ) {
tg.add_group_entry( trait_group::Trait_group_tag( traits.next_string() ), 100 );
} else if( traits.test_array() ) {
JsonArray subtrait = traits.next_array();
tg.add_group_entry( trait_group::Trait_group_tag( traits.get_string( 0 ) ), subtrait.get_int( 1 ) );
} else {
JsonObject subobj = traits.next_object();
add_entry( tg, subobj );
}
}
}
}
示例3: load_colors
void load_colors(JsonObject &jsobj)
{
std::string colors[16]={"BLACK","RED","GREEN","BROWN","BLUE","MAGENTA","CYAN","GRAY",
"DGRAY","LRED","LGREEN","YELLOW","LBLUE","LMAGENTA","LCYAN","WHITE"};
JsonArray jsarr;
for(int c=0;c<16;c++)
{
jsarr = jsobj.get_array(colors[c]);
if(jsarr.size()<3)continue;
consolecolors[colors[c]].clear();
consolecolors[colors[c]].push_back(jsarr.get_int(2));
consolecolors[colors[c]].push_back(jsarr.get_int(1));
consolecolors[colors[c]].push_back(jsarr.get_int(0));
}
}
示例4: 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 );
}
示例5: add_special_attack
void mtype::add_special_attack( JsonArray inner, const std::string & )
{
MonsterGenerator &gen = MonsterGenerator::generator();
const std::string name = inner.get_string( 0 );
const auto iter = gen.attack_map.find( name );
if( iter == gen.attack_map.end() ) {
inner.throw_error( "Invalid special_attacks" );
}
if( special_attacks.count( name ) > 0 ) {
special_attacks.erase( name );
const auto iter = std::find( special_attacks_names.begin(), special_attacks_names.end(), name );
if( iter != special_attacks_names.end() ) {
special_attacks_names.erase( iter );
}
if( test_mode ) {
debugmsg( "%s specifies more than one attack of (sub)type %s, ignoring all but the last",
id.c_str(), name.c_str() );
}
}
auto new_attack = mtype_special_attack( iter->second );
new_attack.actor->cooldown = inner.get_int( 1 );
special_attacks.emplace( name, new_attack );
special_attacks_names.push_back( name );
}
示例6: 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." );
}
}
}
示例7: 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();
}
示例8: load_vehicle_group
void VehicleFactory::load_vehicle_group(JsonObject &jo)
{
const Vehicle_tag group_id = jo.get_string("id");
JsonArray vehicles = jo.get_array("vehicles");
while (vehicles.has_more()) {
JsonArray pair = vehicles.next_array();
groups[group_id].add_vehicle(pair.get_string(0), pair.get_int(1));
}
}
示例9: load
void VehicleGroup::load(JsonObject &jo)
{
VehicleGroup &group = vgroups[vgroup_id(jo.get_string("id"))];
JsonArray vehicles = jo.get_array("vehicles");
while (vehicles.has_more()) {
JsonArray pair = vehicles.next_array();
group.add_vehicle(vproto_id(pair.get_string(0)), pair.get_int(1));
}
}
示例10: load_special_defense
void MonsterGenerator::load_special_defense(mtype *m, JsonObject &jo, std::string member) {
if (jo.has_array(member)) {
JsonArray jsarr = jo.get_array(member);
m->sp_defense = defense_map[jsarr.get_string(0)];
m->def_chance = jsarr.get_int(1);
}
if (m->sp_defense == NULL) {
m->sp_defense = defense_map["NONE"];
}
}
示例11: add_special_attack
void mtype::add_special_attack( JsonArray inner )
{
MonsterGenerator &gen = MonsterGenerator::generator();
const std::string name = inner.get_string( 0 );
const auto iter = gen.attack_map.find( name );
if( iter == gen.attack_map.end() ) {
inner.throw_error( "Invalid special_attacks" );
}
special_attacks[name] = mtype_special_attack( iter->second, inner.get_int( 1 ) );
special_attacks_names.push_back( name );
}
示例12: load
void tool_comp::load( JsonArray &ja )
{
if( ja.test_string() ) {
// constructions uses this format: [ "tool", ... ]
type = ja.next_string();
count = -1;
} else {
JsonArray comp = ja.next_array();
type = comp.get_string( 0 );
count = comp.get_int( 1 );
}
}
示例13: load
void item_comp::load( JsonArray &ja )
{
JsonArray comp = ja.next_array();
type = comp.get_string( 0 );
count = comp.get_int( 1 );
// Recoverable is true by default.
if( comp.size() > 2 ) {
recoverable = comp.get_string( 2 ) == "NO_RECOVER" ? false : true;
}
if( count <= 0 ) {
ja.throw_error( "item count must be a positive number" );
}
}
示例14: load_item_group
// Load an item group from JSON
void Item_factory::load_item_group(JsonObject &jsobj)
{
Item_tag group_id = jsobj.get_string("id");
Item_group *current_group = new Item_group(group_id);
m_template_groups[group_id] = current_group;
JsonArray items = jsobj.get_array("items");
while (items.has_more()) {
JsonArray pair = items.next_array();
current_group->add_entry(pair.get_string(0), pair.get_int(1));
}
JsonArray groups = jsobj.get_array("groups");
while (groups.has_more()) {
JsonArray pair = groups.next_array();
std::string name = pair.get_string(0);
int frequency = pair.get_int(1);
// we had better have loaded it already!
if (m_template_groups.find(name) == m_template_groups.end()) {
throw jsobj.line_number() + ": unrecognized group name: " + name;
}
current_group->add_group(m_template_groups[name], frequency);
}
}
示例15: load_special_defense
void MonsterGenerator::load_special_defense(mtype *m, JsonObject &jo, std::string member) {
if (jo.has_array(member)) {
JsonArray jsarr = jo.get_array(member);
if ( defense_map.find(jsarr.get_string(0)) != defense_map.end() ) {
m->sp_defense = defense_map[jsarr.get_string(0)];
m->def_chance = jsarr.get_int(1);
} else {
jsarr.throw_error("Invalid special_when_hit");
}
}
if (m->sp_defense == NULL) {
m->sp_defense = defense_map["NONE"];
}
}