void CObjectClassesHandler::loadObjectEntry(const JsonNode & entry, ObjectContainter * obj) { if (!handlerConstructors.count(obj->handlerName)) { logGlobal->errorStream() << "Handler with name " << obj->handlerName << " was not found!"; return; } si32 id = selectNextID(entry["index"], obj->objects, 1000); auto handler = handlerConstructors.at(obj->handlerName)(); handler->setType(obj->id, id); if (customNames.count(obj->id) && customNames.at(obj->id).size() > id) handler->init(entry, customNames.at(obj->id).at(id)); else handler->init(entry); if (handler->getTemplates().empty()) { auto range = legacyTemplates.equal_range(std::make_pair(obj->id, id)); for (auto & templ : boost::make_iterator_range(range.first, range.second)) { handler->addTemplate(templ.second); } legacyTemplates.erase(range.first, range.second); } logGlobal->debugStream() << "Loaded object " << obj->id << ":" << id; assert(!obj->objects.count(id)); // DO NOT override obj->objects[id] = handler; }
/** * Read the configuration files from the specified path. * @param path the path from which to read the files. * @param extension the filename extension of the files to read. * @param templates the available @a DataFieldTemplates. * @param messages the @a MessageMap to load the messages into. * @param recursive whether to load all files recursively. * @param verbose whether to verbosely log problems. * @return the result code. */ static result_t readConfigFiles(const string path, const string extension, MessageMap* messages, bool recursive, bool verbose) { vector<string> files, dirs; bool hasTemplates = false; result_t result = collectConfigFiles(path, "", extension, files, &dirs, &hasTemplates); if (result!=RESULT_OK) return result; DataFieldTemplates* templates = getTemplates(path, extension, hasTemplates, verbose); for (vector<string>::iterator it = files.begin(); it != files.end(); it++) { string name = *it; logInfo(lf_main, "reading file %s", name.c_str()); result_t result = messages->readFromFile(name, templates, verbose); if (result != RESULT_OK) return result; } if (recursive) { for (vector<string>::iterator it = dirs.begin(); it != dirs.end(); it++) { string name = *it; logInfo(lf_main, "reading dir %s", name.c_str()); result_t result = readConfigFiles(name, extension, messages, true, verbose); if (result != RESULT_OK) return result; } } return RESULT_OK; };
CRmgTemplateStorage::CRmgTemplateStorage() { auto jsonLoader = make_unique<CJsonRmgTemplateLoader>(); jsonLoader->loadTemplates(); const auto & tpls = jsonLoader->getTemplates(); templates.insert(tpls.begin(), tpls.end()); }
boost::optional<ObjectTemplate> AObjectTypeHandler::getOverride(si32 terrainType, const CGObjectInstance * object) const { std::vector<ObjectTemplate> ret = getTemplates(terrainType); for (auto & tmpl : ret) { if (objectFilter(object, tmpl)) return tmpl; } return boost::optional<ObjectTemplate>(); }
OP_TemplatePair * wendy_GIO_ROP::getTemplatePair() { static OP_TemplatePair *ropPair = 0; if (!ropPair) { OP_TemplatePair *base; base = new OP_TemplatePair(getTemplates()); ropPair = new OP_TemplatePair(ROP_Node::getROPbaseTemplate(), base); } return ropPair; }
void CGObjectInstance::setType(si32 ID, si32 subID) { const TerrainTile &tile = cb->gameState()->map->getTile(visitablePos()); this->ID = Obj(ID); this->subID = subID; //recalculate blockvis tiles - new appearance might have different blockmap than before cb->gameState()->map->removeBlockVisTiles(this, true); auto handler = VLC->objtypeh->getHandlerFor(ID, subID); if(!handler) { logGlobal->error("Unknown object type %d:%d at %s", ID, subID, visitablePos().toString()); return; } if(!handler->getTemplates(tile.terType).empty()) appearance = handler->getTemplates(tile.terType)[0]; else appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash cb->gameState()->map->addBlockVisTiles(this); }
std::vector<ObjectTemplate> AObjectTypeHandler::getTemplates(si32 terrainType) const// FIXME: replace with ETerrainType { std::vector<ObjectTemplate> templates = getTemplates(); std::vector<ObjectTemplate> filtered; std::copy_if(templates.begin(), templates.end(), std::back_inserter(filtered), [&](const ObjectTemplate & obj) { return obj.canBePlacedAt(ETerrainType(terrainType)); }); // H3 defines allowed terrains in a weird way - artifacts, monsters and resources have faulty masks here // Perhaps we should re-define faulty templates and remove this workaround (already done for resources) if (type == Obj::ARTIFACT || type == Obj::MONSTER) return templates; else return filtered; }
void CObjectClassesHandler::loadObjectEntry(const std::string & identifier, const JsonNode & entry, ObjectContainter * obj) { if (!handlerConstructors.count(obj->handlerName)) { logGlobal->error("Handler with name %s was not found!", obj->handlerName); return; } std::string convertedId = VLC->modh->normalizeIdentifier(entry.meta, "core", identifier); si32 id = selectNextID(entry["index"], obj->subObjects, 1000); auto handler = handlerConstructors.at(obj->handlerName)(); handler->setType(obj->id, id); handler->setTypeName(obj->identifier, convertedId); if (customNames.count(obj->id) && customNames.at(obj->id).size() > id) handler->init(entry, customNames.at(obj->id).at(id)); else handler->init(entry); if (handler->getTemplates().empty()) { auto range = legacyTemplates.equal_range(std::make_pair(obj->id, id)); for (auto & templ : boost::make_iterator_range(range.first, range.second)) { handler->addTemplate(templ.second); } legacyTemplates.erase(range.first, range.second); } logGlobal->debug("Loaded object %s(%d)::%s(%d)", obj->identifier, obj->id, convertedId, id); assert(!obj->subObjects.count(id)); // DO NOT override obj->subObjects[id] = handler; obj->subIds[convertedId] = id; }
void Ustawienia::init() { // connect all slots connect(zastButton, SIGNAL(clicked()), this, SLOT(apply())); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); connect(okButton, SIGNAL(clicked()), this, SLOT(okButtonClick())); connect(currAddBtn, SIGNAL(clicked()), this, SLOT(currAddBtnClick())); connect(currDelBtn, SIGNAL(clicked()), this, SLOT(currDelBtnClick())); connect(currencyAddBtn, SIGNAL(clicked()), this, SLOT(currencyAddBtnClick())); connect(currencyDelBtn, SIGNAL(clicked()), this, SLOT(currencyDelBtnClick())); connect(paymAddBtn, SIGNAL(clicked()), this, SLOT(paymAddBtnClick())); connect(paymDelBtn, SIGNAL(clicked()), this, SLOT(paymDelBtnClick())); connect(paymDownBtn, SIGNAL(clicked()), this, SLOT(paymDownBtnClick())); connect(paymUpBtn, SIGNAL(clicked()), this, SLOT(paymUpBtnClick())); connect(vatAddBtn, SIGNAL(clicked()), this, SLOT(vatAddBtnClick())); connect(vatDelBtn, SIGNAL(clicked()), this, SLOT(vatDelBtnClick())); connect(korAddBtn, SIGNAL(clicked()), this, SLOT(korAddBtnClick())); connect(korDelBtn, SIGNAL(clicked()), this, SLOT(korDelBtnClick())); connect(vatUpBtn, SIGNAL(clicked()), this, SLOT(vatUpBtnClick())); connect(vatDownBtn, SIGNAL(clicked()), this, SLOT(vatDownBtnClick())); connect(addLogoBtn, SIGNAL(clicked()), this, SLOT(addLogoBtnClick())); connect(workingDirBtn, SIGNAL(clicked()), this, SLOT(workingDirBtnClick())); connect(pushButton, SIGNAL(clicked()), this, SLOT(setDefaultClick())); connect(defTextBtn, SIGNAL(clicked()), this, SLOT(defTextBtnClick())); connect(pushButtonMaskHelp, SIGNAL(clicked()), this, SLOT(maskHelpClick())); connect( cssList, SIGNAL( currentIndexChanged (int)), this, SLOT( zastBtnEnable() ) ); // QFaktury 0.6.0 connect( langList, SIGNAL( currentIndexChanged (int)), this, SLOT( zastBtnEnable() ) ); connect( codecList, SIGNAL( currentIndexChanged (int)), this, SLOT( zastBtnEnable() ) ); connect( logoEdit, SIGNAL( textChanged (const QString &)), this, SLOT( zastBtnEnable() ) ); connect( workingDirEdit, SIGNAL( textChanged (const QString &)), this, SLOT( zastBtnEnable() ) ); connect( nipMaskEdit, SIGNAL( textChanged (const QString &)), this, SLOT( zastBtnEnable() ) ); connect( accountMaskEdit, SIGNAL( textChanged (const QString &)), this, SLOT( zastBtnEnable() ) ); connect( prefixEdit, SIGNAL( textChanged (const QString &) ), this, SLOT( zastBtnEnable() ) ); connect( sufixEdit, SIGNAL( textChanged (const QString &) ), this, SLOT( zastBtnEnable() ) ); connect( spbNumb, SIGNAL( valueChanged (const QString &) ), this, SLOT( zastBtnEnable() ) ); connect( spbNumCopies, SIGNAL( valueChanged (const QString &) ), this, SLOT( zastBtnEnable() ) ); connect( cbDay, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable()) ); connect( cbMonth, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cbYear, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( shortYear, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cbEdit, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cbSmbEdit, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cbSmbEdit_2, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( additText, SIGNAL( textChanged() ), this, SLOT( zastBtnEnable() ) ); connect( userinfonazwa, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( userinfomiejscowosc, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( userinfoadres, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( userinfokonto, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( userinfonip, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( userinfotel, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( userinfomail, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( userinfowww, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb1, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb2, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb3, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb4, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb5, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb6, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb7, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb8, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb9, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb10, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb11, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb12, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb13, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); connect( cb14, SIGNAL( stateChanged(int) ), this, SLOT( zastBtnEnable() ) ); langList->clear(); langList->insertItems(0, getTranslations()); cssList->clear(); cssList->insertItems(0, getTemplates()); getEncodings(); readSettings(); // disable apply button :) zastButton->setEnabled(false); }
result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolString& data, string& relativeFile) { PartType partType; if (isMaster(address)) { address = (unsigned char)(data[0]+5); // slave address of sending master partType = pt_masterData; if (data.size()<5+1+5+2+2) // skip QQ ZZ PB SB NN return RESULT_EMPTY; } else { partType = pt_slaveData; if (data.size()<1+1+5+2+2) // skip NN return RESULT_EMPTY; } DataFieldSet* identFields = DataFieldSet::getIdentFields(); // MANUFACTURER/ZZ. ( C.S.H., C.H., C.S., S.H., C., S., H., "" ) .*csv string path, prefix, ident, sw, hw; // path: cfgpath/MANUFACTURER, prefix: ZZ., ident: C[C[C[C[C]]]], sw: xxxx, hw: xxxx ostringstream out; unsigned char offset = 0; size_t field = 0; result_t result = (*identFields)[field]->read(partType, data, offset, out, 0); // manufacturer name if (result==RESULT_ERR_NOTFOUND) result = (*identFields)[field]->read(partType, data, offset, out, OF_NUMERIC); // manufacturer name if (result==RESULT_OK) { path = out.str(); transform(path.begin(), path.end(), path.begin(), ::tolower); path = string(opt.configPath) + "/" + path; out.str(""); out << setw(2) << hex << setfill('0') << nouppercase << static_cast<unsigned>(address) << "."; prefix = out.str(); out.str(""); out.clear(); offset = (unsigned char)(offset+(*identFields)[field++]->getLength(partType)); result = (*identFields)[field]->read(partType, data, offset, out, 0); // identification string } if (result==RESULT_OK) { ident = out.str(); out.str(""); offset = (unsigned char)(offset+(*identFields)[field++]->getLength(partType)); result = (*identFields)[field]->read(partType, data, offset, out, 0); // software version number } if (result==RESULT_OK) { sw = out.str(); out.str(""); offset = (unsigned char)(offset+(*identFields)[field++]->getLength(partType)); result = (*identFields)[field]->read(partType, data, offset, out, 0); // hardware version number } if (result!=RESULT_OK) { logDebug(lf_main, "load scan config files: %s", getResultCode(result)); return result; } vector<string> files; bool hasTemplates = false; if (result==RESULT_OK) { hw = out.str(); result = collectConfigFiles(path, prefix, ".csv", files, NULL, &hasTemplates); } logDebug(lf_main, "found %d matching scan config files from %s with prefix %s: %s", files.size(), path.c_str(), prefix.c_str(), getResultCode(result)); if (result!=RESULT_OK) return result; if (files.empty()) return RESULT_ERR_NOTFOUND; // complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.SWxxxx][.HWxxxx][.*].csv for (string::iterator it = ident.begin(); it!=ident.end(); it++) { if (::isspace(*it)) { ident.erase(it--); } else { *it = (char)::tolower(*it); } } size_t prefixLen = path.length()+1+prefix.length()-1; size_t bestMatch = 0; string best; for (vector<string>::iterator it = files.begin(); it!=files.end(); it++) { string name = *it; name = name.substr(prefixLen, name.length()-prefixLen+1-strlen(".csv")); // .*. size_t match = 1; if (name.length()>2) { // more than just "." size_t pos = name.rfind(".SW"); // check for ".SWxxxx." if (pos!=string::npos && name.find(".", pos+1)==pos+7) { if (name.substr(pos+3, 4)==sw) match += 6; else { continue; // SW mismatch } } pos = name.rfind(".HW"); // check for ".HWxxxx." if (pos!=string::npos && name.find(".", pos+1)==pos+7) { if (name.substr(pos+3, 4)==hw) match += 6; else { continue; // HW mismatch } } pos = name.find(".", 1); // check for ".C[C[C[C[C]]]]." if (ident.length()>0 && pos!=string::npos && pos>1 && pos<=6) { // up to 5 chars between two "."s, immediately after "ZZ." string check = name.substr(1, pos-1); string remain = ident; bool matches = false; while (remain.length()>0 && remain.length()>=check.length()) { if (check==remain) { matches = true; break; } if (remain[remain.length()-1]!='0') break; remain.erase(remain.length()-1); } if (matches) match += remain.length(); else { continue; // IDENT mismatch } } } if (match>=bestMatch) { bestMatch = match; best = *it; } } if (best.length()==0) return RESULT_ERR_NOTFOUND; // found the right file. load the templates if necessary, then load the file itself bool readCommon = false; DataFieldTemplates* templates = getTemplates(path, ".csv", hasTemplates, false, &readCommon); if (readCommon) { result = collectConfigFiles(path, "", ".csv", files); if (result==RESULT_OK && !files.empty()) { for (vector<string>::iterator it = files.begin(); it!=files.end(); it++) { string name = *it; name = name.substr(path.length()+1, name.length()-path.length()-strlen(".csv")); // *. if (name=="_templates.") // skip templates continue; if (name.length()<3 || name.find_first_of('.')!=2) { // different from the scheme "ZZ." name = *it; result = messages->readFromFile(name, templates); if (result==RESULT_OK) logNotice(lf_main, "read common config file %s for scan %s", name.c_str(), ident.c_str()); else logError(lf_main, "error reading common config file %s for scan %s: %s", name.c_str(), ident.c_str(), getResultCode(result)); } } } } result = messages->readFromFile(best, templates); if (result!=RESULT_OK) { logError(lf_main, "error reading config file %s for scan %s: %s", best.c_str(), ident.c_str(), getResultCode(result)); return result; } logNotice(lf_main, "read config file %s for scan %s", best.c_str(), ident.c_str()); result = messages->resolveConditions(false); if (result != RESULT_OK) logError(lf_main, "error resolving conditions: %s, %s", getResultCode(result), messages->getLastError().c_str()); logNotice(lf_main, "found messages: %d (%d conditional on %d conditions, %d poll, %d update)", messages->size(), messages->sizeConditional(), messages->sizeConditions(), messages->sizePoll(), messages->sizePassive()); relativeFile = best.substr(strlen(opt.configPath)+1); return RESULT_OK; }