本文整理汇总了C++中JsonArray::get_string方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonArray::get_string方法的具体用法?C++ JsonArray::get_string怎么用?C++ JsonArray::get_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray::get_string方法的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_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);
}
示例3: 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 );
}
}
}
}
示例4: get_next
profession::itypedec get_next( JsonIn &jin ) const {
// either a plain item type id string, or an array with item type id
// and as second entry the item description.
if( jin.test_string() ) {
return profession::itypedec( jin.get_string(), "" );
}
JsonArray jarr = jin.get_array();
const auto id = jarr.get_string( 0 );
const auto s = jarr.get_string( 1 );
const auto snippet = _( s.c_str() );
return profession::itypedec( id, snippet );
}
示例5: 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" );
}
}
示例6: 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"];
}
}
示例7: 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 );
}
示例8: 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." );
}
}
}
示例9: 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 );
requirement = comp.size() > 2 && comp.get_string( 2 ) == "LIST";
}
if( count == 0 ) {
ja.throw_error( "tool count must not be 0" );
}
// Note: negative count means charges (of the tool) should be consumed
}
示例10: 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));
}
}
示例11: 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));
}
}
示例12: 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 );
}
示例13: 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"];
}
}
示例14: 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 );
}
}
示例15: 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");
// LEGACY: Since it seems artifacts get serialized out to disk, and they're
// dynamic, we need to allow for them to be read from disk for, oh, I guess
// quite some time. Loading and saving once will write things out as a JSON
// array.
if (jo.has_string("m1")) {
materials.push_back(jo.get_string("m1"));
}
if (jo.has_string("m2")) {
materials.push_back(jo.get_string("m2"));
}
// Assumption, perhaps dangerous, that we won't wind up with m1 and m2 and
// a materials array in our serialized objects at the same time.
if (jo.has_array("materials")) {
JsonArray jarr = jo.get_array("materials");
for (int i = 0; i < jarr.size(); ++i) {
materials.push_back(jarr.get_string(i));
}
}
if (materials.size() == 0) {
// I don't think we need this, but a lot of code seems to want at least
// one material and I'm not sure I found every single corner case.
materials.push_back("null");
}
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");
jo.read( "covers", 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());
}
}