make CardAuctionPool name matching more lenient
This commit is contained in:
@@ -1769,6 +1769,7 @@ CardIndex::CardIndex(const string& filename, const string& decompressed_filename
|
|||||||
// unindexed (they can still be looked up by ID, of course)
|
// unindexed (they can still be looked up by ID, of course)
|
||||||
string name = entry->def.en_name;
|
string name = entry->def.en_name;
|
||||||
this->card_definitions_by_name.emplace(name, entry);
|
this->card_definitions_by_name.emplace(name, entry);
|
||||||
|
this->card_definitions_by_name_normalized.emplace(this->normalize_card_name(name), entry);
|
||||||
|
|
||||||
entry->def.hp.decode_code();
|
entry->def.hp.decode_code();
|
||||||
entry->def.ap.decode_code();
|
entry->def.ap.decode_code();
|
||||||
@@ -1840,6 +1841,10 @@ shared_ptr<const CardIndex::CardEntry> CardIndex::definition_for_name(const stri
|
|||||||
return this->card_definitions_by_name.at(name);
|
return this->card_definitions_by_name.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<const CardIndex::CardEntry> CardIndex::definition_for_name_normalized(const string& name) const {
|
||||||
|
return this->card_definitions_by_name_normalized.at(this->normalize_card_name(name));
|
||||||
|
}
|
||||||
|
|
||||||
set<uint32_t> CardIndex::all_ids() const {
|
set<uint32_t> CardIndex::all_ids() const {
|
||||||
set<uint32_t> ret;
|
set<uint32_t> ret;
|
||||||
for (const auto& it : this->card_definitions) {
|
for (const auto& it : this->card_definitions) {
|
||||||
@@ -1852,6 +1857,17 @@ uint64_t CardIndex::definitions_mtime() const {
|
|||||||
return this->mtime_for_card_definitions;
|
return this->mtime_for_card_definitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string CardIndex::normalize_card_name(const string& name) {
|
||||||
|
string ret;
|
||||||
|
for (char ch : name) {
|
||||||
|
if (ch == ' ') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ret.push_back(tolower(ch));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
MapIndex::MapIndex(const string& directory) {
|
MapIndex::MapIndex(const string& directory) {
|
||||||
auto add_maps_from_dir = [&](const string& dir, bool is_quest) -> void {
|
auto add_maps_from_dir = [&](const string& dir, bool is_quest) -> void {
|
||||||
for (const auto& filename : list_directory(dir)) {
|
for (const auto& filename : list_directory(dir)) {
|
||||||
|
|||||||
@@ -1048,13 +1048,17 @@ public:
|
|||||||
const std::string& get_compressed_definitions() const;
|
const std::string& get_compressed_definitions() const;
|
||||||
std::shared_ptr<const CardEntry> definition_for_id(uint32_t id) const;
|
std::shared_ptr<const CardEntry> definition_for_id(uint32_t id) const;
|
||||||
std::shared_ptr<const CardEntry> definition_for_name(const std::string& name) const;
|
std::shared_ptr<const CardEntry> definition_for_name(const std::string& name) const;
|
||||||
|
std::shared_ptr<const CardEntry> definition_for_name_normalized(const std::string& name) const;
|
||||||
std::set<uint32_t> all_ids() const;
|
std::set<uint32_t> all_ids() const;
|
||||||
uint64_t definitions_mtime() const;
|
uint64_t definitions_mtime() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static std::string normalize_card_name(const std::string& name);
|
||||||
|
|
||||||
std::string compressed_card_definitions;
|
std::string compressed_card_definitions;
|
||||||
std::unordered_map<uint32_t, std::shared_ptr<CardEntry>> card_definitions;
|
std::unordered_map<uint32_t, std::shared_ptr<CardEntry>> card_definitions;
|
||||||
std::unordered_map<std::string, std::shared_ptr<CardEntry>> card_definitions_by_name;
|
std::unordered_map<std::string, std::shared_ptr<CardEntry>> card_definitions_by_name;
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<CardEntry>> card_definitions_by_name_normalized;
|
||||||
uint64_t mtime_for_card_definitions;
|
uint64_t mtime_for_card_definitions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -833,7 +833,7 @@ void ServerState::load_ep3_data() {
|
|||||||
config_log.info("Resolving Episode 3 card auction pool");
|
config_log.info("Resolving Episode 3 card auction pool");
|
||||||
for (auto& e : this->ep3_card_auction_pool) {
|
for (auto& e : this->ep3_card_auction_pool) {
|
||||||
try {
|
try {
|
||||||
const auto& card = this->ep3_card_index->definition_for_name(e.card_name);
|
const auto& card = this->ep3_card_index->definition_for_name_normalized(e.card_name);
|
||||||
e.card_id = card->def.card_id;
|
e.card_id = card->def.card_id;
|
||||||
} catch (const out_of_range&) {
|
} catch (const out_of_range&) {
|
||||||
throw runtime_error(string_printf("Ep3 card \"%s\" does not exist", e.card_name.c_str()));
|
throw runtime_error(string_printf("Ep3 card \"%s\" does not exist", e.card_name.c_str()));
|
||||||
|
|||||||
Reference in New Issue
Block a user