Exemplo n.º 1
0
    void SpellCheckWorker::detectAffEncoding() {
        // detect encoding analyzing the SET option in the affix file
        QDir resourcesDir(getHunspellResourcesPath());
        QString affPath = resourcesDir.absoluteFilePath(EN_HUNSPELL_AFF);

        m_Encoding = "ISO8859-1";
        QFile affixFile(affPath);

        if (affixFile.open(QIODevice::ReadOnly)) {
            QTextStream stream(&affixFile);
            QRegExp encDetector("^\\s*SET\\s+([A-Z0-9\\-]+)\\s*", Qt::CaseInsensitive);

            for (QString line = stream.readLine(); !line.isEmpty(); line = stream.readLine()) {
                if (encDetector.indexIn(line) > -1) {
                    m_Encoding = encDetector.cap(1);
                    qDebug() << QString("Encoding of AFF set to ") + m_Encoding;
                    break;
                }
            }

            affixFile.close();
        }

        m_Codec = QTextCodec::codecForName(m_Encoding.toLatin1().constData());
    }
Exemplo n.º 2
0
SpellChecker::SpellChecker(const QString &dictionaryPath, const QString &userDictionary, const QString &lan)
{
    this->lan = lan;
    this->userDictionary = userDictionary;
    QString dictFilePath = dictionaryPath + ".dic";
    QString affixFilePath = dictionaryPath + ".aff";
    QByteArray dictFilePathBA = dictFilePath.toLocal8Bit();
    QByteArray affixFilePathBA = affixFilePath.toLocal8Bit();
    hunspell = std::make_shared<Hunspell>(affixFilePathBA.constData(), dictFilePathBA.constData());

    encoding = "ISO8859-1";
    QFile affixFile(affixFilePath);
    if(affixFile.open(QIODevice::ReadOnly)) {
        QTextStream stream(&affixFile);
        QRegExp enc_detector("^\\s*SET\\s+([A-Z0-9\\-]+)\\s*", Qt::CaseInsensitive);
        for(QString line = stream.readLine(); !line.isEmpty(); line=stream.readLine()) {
            if(enc_detector.indexIn(line) > -1) {
                encoding = enc_detector.cap(1);
                qDebug("Encoding set to %s", encoding.toLocal8Bit().constData());
                break;
            }
        }
        affixFile.close();
    }
    codec = QTextCodec::codecForName(encoding.toLatin1().constData());
    if(userDictionary.isEmpty()) {
        QFile userDictionaryFile(userDictionary);
        if(userDictionaryFile.open(QIODevice::ReadOnly)) {
            QTextStream stream(&userDictionaryFile);
            for(QString word=stream.readLine(); !word.isEmpty(); word=stream.readLine())
                put_word(word);
            userDictionaryFile.close();
        } else {
            qWarning("User dictionary in %s could not be opened", userDictionary.toLocal8Bit().constData());
        }
    } else {
        qDebug("User dictionary not set.");
    }
}
Exemplo n.º 3
0
void GenerateItems(json::Value& value, json::Value& data) {
  auto names = Strings::list("Items");
  auto powers = Strings::list("ItemPassivePowerDescriptions");
  uint32 powId = fixAttrId(1270, true);
  std::map<std::string, std::string> powerFix;
  powerFix.emplace("Unique_Amulet_109_x1_210", "ItemPassive_x1_Amulet_norm_unique_25_DemonHunter");

  std::map<uint32, GameBalance::Type::AffixTableEntry*> affixes;
  SnoFile<GameBalance> affixFile("1xx_AffixList");
  for (auto& afx : affixFile->x078_AffixTable) {
    affixes.emplace(HashNameLower(afx.x000_Text), &afx);
  }
  for (auto& rcp : SnoLoader::All<Recipe>()) {
    std::string item = rcp->x0C_ItemSpecifierData.x00_ItemsGameBalanceId.name();
    if (item.empty()) continue;
    uint32 power = 0;
    for (auto& id : rcp->x0C_ItemSpecifierData.x08_GameBalanceIds) {
      if (affixes.count(id)) {
        for (auto& attr : affixes[id]->x260_AttributeSpecifiers) {
          if (attr.x00_Type == powId) {
            power = attr.x04_Param;
            break;
          }
        }
      }
      if (power) break;
    }
    char const* pname = (power ? Power::name(power) : nullptr);
    if (pname) powerFix.emplace(item, pname);
  }

  for (auto& kv : data["itemById"].getMap()) {
    if (kv.second.has("required")) {
      std::string key = kv.second["required"]["custom"]["id"].getString();
      data["legendaryMap"][key] = kv.first;
    }
    auto* item = ItemLibrary::get(kv.first);
    if (!names.has(kv.first) || !item) {
      if (kv.first != "Unique_Ring_017_p4") {
        Logger::log("Item not found: %s", kv.first.c_str());
        continue;
      }
    }
    auto& dst = value["itemById"][kv.first];
    dst["name"] = names[kv.first == "Unique_Ring_017_p4" ? "Unique_Ring_017_p2" : kv.first];
    if (kv.second.has("required")) {
      std::string key = kv.second["required"]["custom"]["id"].getString();
      data["stringlist"]["Items"][key]["text"] = kv.second["required"]["custom"]["name"];
      data["stringlist"]["Items"][key]["tip"] = names[kv.first] + " (short effect name)";
      dst["required"]["custom"]["name"] = fmtstring("$Items/%s$", key.c_str());
      bool found = false;
      for (auto& attr : item->x1F8_AttributeSpecifiers) {
        if (attr.x00_Type != powId) continue;
        char const* name = Power::name(attr.x04_Param);
        auto* tag = PowerTags::getraw(attr.x04_Param);
        if (!name || !tag || !powers.has(name)) {
          Logger::log("Power not found for %s", kv.first.c_str());
          continue;
        }
        auto values = GameAffixes::defaultMap();
        AttributeValue value = ExecFormula(
          reinterpret_cast<uint32 const*>(attr.x08_Data.begin()),
          reinterpret_cast<uint32 const*>(attr.x08_Data.end()),
          values);
        if (value.min != value.max) {
          values["value1"] = AttributeValue("%");
        } else {
          values["value1"] = value;
        }
        dst["required"]["custom"]["format"] = FormatDescription(powers[name], FormatTags, values, tag);
        found = true;
        break;
      }
      if (!found) {
        if (powerFix.count(kv.first)) {
          auto* tag = PowerTags::get(powerFix[kv.first]);
          auto values = GameAffixes::defaultMap();
          values["value1"] = AttributeValue("%");
          dst["required"]["custom"]["format"] = FormatDescription(powers[powerFix[kv.first]], FormatTags, values, tag);
        } else if (kv.first == "x1_Amulet_norm_unique_25") {
          // hellfire
          std::string x = powers["ItemPassive_Unique_Ring_770_x1"];
          std::string y = Strings::get("Powers", "Trait_PoundOfFlesh");
          size_t pos = x.find(y);
          if (pos != std::string::npos) {
            x.replace(pos, y.length(), "%p");
            dst["required"]["custom"]["format"] = x;
          }
        } else {
          Logger::log("Power not found for %s", kv.first.c_str());
        }
      }
      if (dst["required"]["custom"].has("format")) {
        data["locale_tips"]["Items"][key] = dst["required"]["custom"]["format"];
      }
    }
  }
}