void ChangeEmpireOptions::_exec(Game& game, unsigned int) { VariantMap emOpts = _vars.get( literals::empire ).toMap(); VariantMap advOptions = _vars.get( literals::adviser ).toMap(); if( !emOpts.empty() ) { world::EmpirePtr empire = game.empire(); unsigned int lastWorkerSalary = empire->workerSalary(); empire->load( emOpts ); if( empire->workerSalary() != lastWorkerSalary ) { bool raiseSalary = empire->workerSalary() - lastWorkerSalary; GameEventPtr e = ShowInfobox::create( "##rome##", raiseSalary ? "##rome_raises_wages##" : "##rome_lowers_wages##"); e->dispatch(); } } Variant adv_enabled = advOptions.get( literals::enabled ); if( adv_enabled.isValid() ) { game.city()->setOption( PlayerCity::adviserEnabled, adv_enabled ); } }
void set( Senate::Status status, const VariantMap& stream ) { if( stream.empty() ) return; Picture pic( stream.get( "rc"), stream.get( "index") ); Point offset = stream.get( "offset" ); set( status, pic, offset ); }
void Pathway::load(const Tilemap& tmap, const VariantMap& stream ) { if( stream.empty() ) { return; } VARIANT_LOAD_ANY_D( _d, startPos, stream ) VARIANT_LOAD_ANY_D( _d, endPos, stream ) VariantList vmTiles = stream.get( literals::tiles ).toList(); foreach( it, vmTiles ) { _d->tiles.push_back( const_cast<Tile*>( &tmap.at( it->toTilePos() )) ); }
void PictureBank::addAtlas( const std::string& filename ) { VariantMap options = SaveAdapter::load( filename ); if( !options.empty() ) { Logger::warning( "PictureBank: load atlas " + filename ); AtlasPreview atlas; atlas.filename = filename; VariantMap items = options.get( framesSection ).toMap(); foreach( i, items ) { unsigned int hash = StringHelper::hash( i->first ); atlas.images.insert( hash ); }
void HouseSpecHelper::loadHouseModel( const std::string& filename ) { VariantMap houses = SaveAdapter::load( filename ); if( houses.empty() ) { StringHelper::debug( 0xff, "Can't load house model from %s", filename.c_str() ); return; } for( VariantMap::iterator it = houses.begin(); it != houses.end(); it++ ) { // this is not a comment (comments start by #) // std::cout << "Line #" << linenum << ":" << line << std::endl; VariantMap hSpec = (*it).second.toMap(); HouseLevelSpec spec; spec._houseLevel = hSpec.get( "level" ).toInt(); spec._levelName = hSpec.get( "title" ).toString(); spec._maxHabitantsByTile = hSpec.get( "habitants" ).toInt(); spec._midDesirability = hSpec.get( "minDesirability" ).toInt(); // min desirability spec._maxDesirability = hSpec.get( "maxDesirability" ).toInt(); // desirability levelUp spec._minEntertainmentLevel = hSpec.get( "entertainment" ).toInt(); spec._minWaterLevel = hSpec.get( "water" ).toInt(); spec._minReligionLevel = hSpec.get( "religion" ).toInt(); spec._minEducationLevel = hSpec.get( "education" ).toInt(); spec._minHealthLevel = hSpec.get( "health" ).toInt(); spec._minFoodLevel = hSpec.get( "food" ).toInt(); spec._requiredGoods[G_WHEAT] = 1; // hard coded ... to be changed! spec._requiredGoods[G_POTTERY] = hSpec.get( "pottery" ).toInt(); // pottery spec._requiredGoods[G_OIL] = hSpec.get( "oil" ).toInt(); // oil spec._requiredGoods[G_FURNITURE] = hSpec.get( "furniture").toInt();// furniture spec._requiredGoods[G_WINE] = hSpec.get( "wine" ).toInt(); // wine spec._crime = hSpec.get( "crime" ).toInt();; // crime spec._prosperity = hSpec.get( "prosperity" ).toInt(); // prosperity spec._taxRate = hSpec.get( "tax" ).toInt();// tax_rate HouseSpecHelper::getInstance().setHouseLevelSpec( spec ); } }
void Storage::load( const VariantMap& stream ) { if( stream.empty() ) { Logger::warning( "!!! Storage::load from empty stream" ); return; } good::Store::load( stream ); _gsd->capacity = (int)stream.get( "max" ); _gsd->reset(); VariantList stockSave = stream.get( "stock" ).toList(); for( auto& sotckInfo : stockSave ) { SmStock::Ptr stock = SmStock::create( good::none ); stock->load( sotckInfo.toList() ); _gsd->stocks[ stock->type() ] = stock; } }
void PictureBank::addAtlas( const std::string& filename ) { VariantMap options = config::load( filename ); if( !options.empty() ) { Logger::warning( "PictureBank: load atlas " + filename ); AtlasPreview atlas; atlas.filename = filename; VariantMap items = options.get( framesSection ).toMap(); for( auto& i : items ) { unsigned int hash = Hash( i.first ); atlas.images.insert( hash ); } _d->atlases.push_back( atlas ); } }
void PictureBank::Impl::loadAtlas(const vfs::Path& filePath) { if( !filePath.exist() ) { Logger::warning( "PictureBank: cant find atlas " + filePath.toString() ); return; } VariantMap info = config::load( filePath ); vfs::Path texturePath = info.get( "texture" ).toString(); vfs::NFile file = vfs::NFile::open( texturePath ); Picture mainTexture; if( file.isOpen() ) { mainTexture = PictureLoader::instance().load( file ); } else { Logger::warning( "PictureBank: load atlas failed for texture" + texturePath.toString() ); mainTexture = Picture::getInvalid(); } //SizeF mainRectSize = mainTexture.size().toSizeF(); if( !info.empty() ) { VariantMap items = info.get( framesSection ).toMap(); for( auto& i : items ) { VariantList rInfo = i.second.toList(); Picture pic = mainTexture; Point start( rInfo.get( 0 ).toInt(), rInfo.get( 1 ).toInt() ); Size size( rInfo.get( 2 ).toInt(), rInfo.get( 3 ).toInt() ); pic.setOriginRect( Rect( start, size ) ); setPicture( i.first, pic ); } } }
std::string Json::serialize(const Variant &data, bool &success, const std::string& tab) { std::string str; success = true; if( data.isNull() ) // invalid or null? { return "null"; } switch( data.type() ) { case Variant::List: case Variant::NStringArray: // variant is a list? { StringArray values; const VariantList rlist = data.toList(); std::string serializedValue; serializedValue.reserve( 512 ); for( auto item : rlist ) { serializedValue = serialize( item, "" ); if( serializedValue.empty() ) { success = false; break; } values.push_back( serializedValue ); } str = "[ " + join( values, ", " ) + " ]"; } break; case Variant::Map: // variant is a map? { VariantMap vmap = data.toMap(); if( vmap.empty() ) { str = "{}"; } else { str = "{ \n"; StringArray pairs; std::string serializedValue; serializedValue.reserve( 512 ); for( auto item : vmap ) { serializedValue = serialize( item.second, tab + " "); if( serializedValue.empty()) { //success = false; pairs.push_back( tab + sanitizeString( item.first ) + std::string( " : \"nonSerializableValue\"" ) ); continue; } pairs.push_back( tab + sanitizeString( item.first ) + " : " + serializedValue ); } str += join(pairs, ",\n"); std::string rtab( tab ); rtab.resize( std::max<int>( 0, tab.size() - 2 ) ); str += std::string( "\n" ) + rtab + "}"; } } break; case Variant::String: case Variant::NByteArray: // a string or a byte array? { str = sanitizeString( data.toString() ); } break; case Variant::Double: case Variant::Float: // double? { // TODO: cheap hack - almost locale independent double formatting str = utils::format( 0xff, "\"%f\"", data.toDouble() ); str = utils::replace(str, ",", "."); if( str.find(".") == std::string::npos && str.find("e") == std::string::npos ) { str += ".0"; } } break; case Variant::NTilePos: { const TilePos& pos = data.toTilePos(); str = utils::format( 0xff, "[ %d, %d ]", pos.i(), pos.j() ); } break; case Variant::NSize: { const Size& size = data.toSize(); str = utils::format( 0xff, "[ %d, %d ]", size.width(), size.height() ); } break; case Variant::NPoint: { const Point& pos = data.toPoint(); str = utils::format( 0xff, "[ %d, %d ]", pos.x(), pos.y() ); } break; case Variant::NPointF: { PointF pos = data.toPointF(); // TODO: cheap hack - almost locale independent double formatting std::string posX = utils::replace(utils::format( 0xff, "%f", pos.x()), ",", "."); std::string posY = utils::replace(utils::format( 0xff, "%f", pos.y()), ",", "."); str = utils::format( 0xff, "[ \"%s\", \"%s\" ]", posX.c_str(), posY.c_str() ); } break; case Variant::Bool: // boolean value? { str = data.toBool() ? "true" : "false"; } break; case Variant::ULongLong: // large unsigned number? { str = utils::format( 0xff, "%u", data.toULongLong() ); } break; case Variant::Int: // simple int? { str = utils::format( 0xff, "%d", data.toInt() ); } break; case Variant::UInt: { str = utils::format( 0xff, "%d", data.toInt() ); } break; default: if ( data.canConvert( Variant::LongLong ) ) // any signed number? { str = utils::format( 0xff, "%d", data.toLongLong() ); } else if (data.canConvert( Variant::Long )) { str = utils::format( 0xff, "%d", data.toLongLong() ); } else if (data.canConvert( Variant::String ) ) // can value be converted to string? { // this will catch Date, DateTime, Url, ... str = sanitizeString( data.toString() ); } else { success = false; } break; } return success ? str : std::string(); }
bool empty() const { return _vm.empty(); }