void Load::loadData(std::string fileName, EntityManager* entitymanager) { rapidjson::Document doc = loadJsonFile(fileName); if(doc.HasMember("JSONParsingError")) { std::cout << "[ERROR] " << doc["JSONParsingError"].GetString() << "\n"; return; } //Load blocks const rapidjson::Value& blocks = doc["blocks"]; for(rapidjson::SizeType i = 0; i < blocks.Size(); i++) { const rapidjson::Value& block = blocks[i]; entitymanager->addEntity(block["name"].GetString()); entitymanager->entities[block["name"].GetString()]->addProperty(STATIC); entitymanager->setBody(block["name"].GetString(), block["rect"][0].GetInt() * entitymanager->tileSize, block["rect"][1].GetInt() * entitymanager->tileSize, block["rect"][2].GetInt() * entitymanager->tileSize, block["rect"][3].GetInt() * entitymanager->tileSize); entitymanager->setColor(block["name"].GetString(), block["color"][0].GetInt(), block["color"][1].GetInt(), block["color"][2].GetInt()); } }
bool UserBank::load() { QJsonArray a; QJsonDocument d; bool ok = loadJsonFile("giftrecord.json", d); a = d.array(); if (!ok) { qDebug()<< " load record file failed!!"; return false; } else { qDebug()<< " load record file succeed!!"; } for (int i=0; i<a.size(); i++) { QJsonObject b = a[i].toObject(); record[b["name"].toString()] = b["money"].toInt(); } record[myTr("麻由の天蝎1000")] = 10000000; record[myTr("麻由の天蝎10000")] = 10000000; record[myTr("麻由の天蝎1000000")] = 10000000; return true; }
void Config::handleOption(const QString &option, const QVariant &value) { bool boolValue = false; QStringList booleanFlags; booleanFlags << "debug"; booleanFlags << "disk-cache"; booleanFlags << "ignore-ssl-errors"; booleanFlags << "load-images"; booleanFlags << "local-to-remote-url-access"; booleanFlags << "remote-debugger-autorun"; booleanFlags << "web-security"; if (booleanFlags.contains(option)) { if ((value != "true") && (value != "yes") && (value != "false") && (value != "no")) { setUnknownOption(QString("Invalid values for '%1' option.").arg(option)); return; } boolValue = (value == "true") || (value == "yes"); } if (option == "cookies-file") { setCookiesFile(value.toString()); } if (option == "config") { loadJsonFile(value.toString()); } if (option == "debug") { setPrintDebugMessages(boolValue); } if (option == "disk-cache") { setDiskCacheEnabled(boolValue); } if (option == "ignore-ssl-errors") { setIgnoreSslErrors(boolValue); } if (option == "load-images") { setAutoLoadImages(boolValue); } if (option == "local-storage-path") { setOfflineStoragePath(value.toString()); } if (option == "local-storage-quota") { setOfflineStorageDefaultQuota(value.toInt()); } if (option == "local-to-remote-url-access") { setLocalToRemoteUrlAccessEnabled(boolValue); } if (option == "max-disk-cache-size") { setMaxDiskCacheSize(value.toInt()); } if (option == "output-encoding") { setOutputEncoding(value.toString()); } if (option == "remote-debugger-autorun") { setRemoteDebugAutorun(boolValue); } if (option == "remote-debugger-port") { setDebug(true); setRemoteDebugPort(value.toInt()); } if (option == "proxy") { setProxy(value.toString()); } if (option == "proxy-type") { setProxyType(value.toString()); } if (option == "proxy-auth") { setProxyAuth(value.toString()); } if (option == "script-encoding") { setScriptEncoding(value.toString()); } if (option == "script-language") { setScriptLanguage(value.toString()); } if (option == "web-security") { setWebSecurityEnabled(boolValue); } if (option == "ssl-protocol") { setSslProtocol(value.toString()); } if (option == "ssl-certificates-path") { setSslCertificatesPath(value.toString()); } if (option == "webdriver") { setWebdriver(value.toString().length() > 0 ? value.toString() : DEFAULT_WEBDRIVER_CONFIG); } if (option == "webdriver-logfile") { setWebdriverLogFile(value.toString()); } if (option == "webdriver-loglevel") { setWebdriverLogLevel(value.toString()); } if (option == "webdriver-selenium-grid-hub") { setWebdriverSeleniumGridHub(value.toString()); } }
void Config::processArgs(const QStringList &args) { QStringListIterator it(args); while (it.hasNext()) { const QString &arg = it.next(); if (arg == "--version") { setVersionFlag(true); return; } if (arg == "--load-images=yes") { setAutoLoadImages(true); continue; } if (arg == "--load-images=no") { setAutoLoadImages(false); continue; } if (arg == "--load-plugins=yes") { setPluginsEnabled(true); continue; } if (arg == "--load-plugins=no") { setPluginsEnabled(false); continue; } if (arg == "--disk-cache=yes") { setDiskCacheEnabled(true); continue; } if (arg == "--disk-cache=no") { setDiskCacheEnabled(false); continue; } if (arg.startsWith("--max-disk-cache-size=")) { setMaxDiskCacheSize(arg.mid(arg.indexOf("=") + 1).trimmed().toInt()); continue; } if (arg == "--ignore-ssl-errors=yes") { setIgnoreSslErrors(true); continue; } if (arg == "--ignore-ssl-errors=no") { setIgnoreSslErrors(false); continue; } if (arg == "--local-to-remote-url-access=no") { setLocalToRemoteUrlAccessEnabled(false); continue; } if (arg == "--local-to-remote-url-access=yes") { setLocalToRemoteUrlAccessEnabled(true); continue; } if (arg.startsWith("--proxy-type=")) { setProxyType(arg.mid(13).trimmed()); continue; } if (arg.startsWith("--proxy=")) { setProxy(arg.mid(8).trimmed()); continue; } if (arg.startsWith("--cookies-file=")) { setCookiesFile(arg.mid(15).trimmed()); continue; } if (arg.startsWith("--output-encoding=")) { setOutputEncoding(arg.mid(18).trimmed()); continue; } if (arg.startsWith("--script-encoding=")) { setScriptEncoding(arg.mid(18).trimmed()); continue; } if (arg.startsWith("--config=")) { QString configPath = arg.mid(9).trimmed(); loadJsonFile(configPath); continue; } if (arg.startsWith("--remote-debugger-port=")) { setDebug(true); setRemoteDebugPort(arg.mid(23).trimmed().toInt()); continue; } if (arg.startsWith("--")) { setUnknownOption(QString("Unknown option '%1'").arg(arg)); return; } // There are no more options at this point. // The remaining arguments are available for the script. m_scriptFile = arg; while (it.hasNext()) { m_scriptArgs += it.next(); } } }
void Config::handleOption(const QString &option, const QVariant &value) { bool boolValue = false; QStringList booleanFlags; booleanFlags << "debug"; booleanFlags << "disk-cache"; booleanFlags << "ignore-ssl-errors"; booleanFlags << "load-images"; booleanFlags << "local-to-remote-url-access"; booleanFlags << "remote-debugger-autorun"; booleanFlags << "web-security"; if (booleanFlags.contains(option)) { if ((value != "true") && (value != "yes") && (value != "false") && (value != "no")) { setUnknownOption(QString("Invalid values for '%1' option.").arg(option)); return; } boolValue = (value == "true") || (value == "yes"); } if (option == "cookies-file") { setCookiesFile(value.toString()); } if (option == "config") { loadJsonFile(value.toString()); } if (option == "debug") { setPrintDebugMessages(boolValue); } if (option == "disk-cache") { setDiskCacheEnabled(boolValue); } if (option == "ignore-ssl-errors") { setIgnoreSslErrors(boolValue); } if (option == "load-images") { setAutoLoadImages(boolValue); } if (option == "local-storage-path") { setOfflineStoragePath(value.toString()); } if (option == "local-storage-quota") { setOfflineStorageDefaultQuota(value.toInt()); } if (option == "local-to-remote-url-access") { setLocalToRemoteUrlAccessEnabled(boolValue); } if (option == "max-disk-cache") { setMaxDiskCacheSize(value.toInt()); } if (option == "output-encoding") { setOutputEncoding(value.toString()); } if (option == "remote-debugger-autorun") { setRemoteDebugAutorun(boolValue); } if (option == "remote-debugger-port") { setDebug(true); setRemoteDebugPort(value.toInt()); } if (option == "proxy") { setProxy(value.toString()); } if (option == "proxy-type") { setProxyType(value.toString()); } if (option == "proxy-auth") { setProxyAuth(value.toString()); } if (option == "script-encoding") { setScriptEncoding(value.toString()); } if (option == "web-security") { setWebSecurityEnabled(boolValue); } }
////////////////////////////////////////////////////////////////////////// // import BcBool CsPackageImporter::import( const BcName& Name ) { Name_ = Name; BcPath Path = CsCore::pImpl()->getPackageImportPath( Name ); PSY_LOGSCOPEDCATEGORY( "Import" ); PSY_LOG( "Importing %s...\n", (*Path).c_str() ); PSY_LOGSCOPEDINDENT; BcTimer TotalTimer; TotalTimer.mark(); // Store source file info. FsStats Stats; if( FsCore::pImpl()->fileStats( (*Path).c_str(), Stats ) ) { Header_.SourceFileStatsHash_ = BcHash( reinterpret_cast< BcU8* >( &Stats ), sizeof( Stats ) ); } else { Header_.SourceFileStatsHash_ = 0; } beginImport(); Header_.SourceFile_ = addString( (*Path).c_str() ); endImport(); Json::Value Root; if( loadJsonFile( (*Path).c_str(), Root ) ) { // Add as dependency. beginImport(); addDependency( (*Path).c_str() ); // Get resource list. Json::Value Resources( Root.get( "resources", Json::Value( Json::arrayValue ) ) ); // Add all package cross refs. addAllPackageCrossRefs( Resources ); // Set resource id to zero. ResourceIds_.store( 0 ); // Import everything. for( const auto& ResourceObject : Resources ) { addImport( ResourceObject, BcFalse ); } endImport(); // Sort importers. std::sort( Resources_.begin(), Resources_.end() ); // Iterate over all resources and import (import calls can append to the list) size_t CurrResourceIdx = 0; while( CurrResourceIdx < Resources_.size() ) { // Grab first resource in the list. auto ResourceEntry = std::move( Resources_[ CurrResourceIdx++ ] ); // Import resource. BcTimer ResourceTimer; ResourceTimer.mark(); try { PSY_LOGSCOPEDINDENT; beginImport(); if( importResource( std::move( ResourceEntry.Importer_ ), ResourceEntry.Resource_ ) ) { PSY_LOG( "SUCCEEDED: Time: %.2f seconds.\n", ResourceTimer.time() ); } else { PSY_LOG( "FAILED: Time: %.2f seconds.\n", ResourceTimer.time() ); BcBreakpoint; endImport(); return BcFalse; } endImport(); } catch( CsImportException ImportException ) { PSY_LOG( "FAILED: Time: %.2f seconds.\n", ResourceTimer.time() ); PSY_LOG( "ERROR: in file %s:\n%s\n", ImportException.file().c_str(), ImportException.what() ); endImport(); return BcFalse; } } // Save and return. BcPath PackedPackage( CsCore::pImpl()->getPackagePackedPath( Name ) ); BcBool SaveSuccess = save( PackedPackage ); if( SaveSuccess ) { PSY_LOG( "SUCCEEDED: Time: %.2f seconds.\n", TotalTimer.time() ); // Write out dependencies. std::string OutputDependencies = *CsCore::pImpl()->getPackageIntermediatePath( Name ) + "/deps.json"; CsSerialiserPackageObjectCodec ObjectCodec( nullptr, (BcU32)bcRFF_ALL, (BcU32)bcRFF_TRANSIENT, 0 ); SeJsonWriter Writer( &ObjectCodec ); Writer << Dependencies_; Writer.save( OutputDependencies.c_str() ); } else { PSY_LOG( "FAILED: Time: %.2f seconds.\n", TotalTimer.time() ); BcBreakpoint; } return SaveSuccess; } return BcFalse; }
JsonCppWrapper::JsonCppWrapper(std::string filePath) { loadJsonFile(filePath); }