mirror of
https://github.com/sebastiandine/Card-Collection-Manager-3.git
synced 2026-08-28 17:01:02 +00:00
@@ -20,7 +20,6 @@ struct YuGiOhCard {
|
||||
Set set;
|
||||
std::string setNo;
|
||||
std::string rarity;
|
||||
std::string rarityCode;
|
||||
std::string note;
|
||||
std::vector<std::string> images;
|
||||
Language language{Language::English};
|
||||
|
||||
@@ -59,6 +59,7 @@ enum class YuGiOhSortColumn {
|
||||
Language,
|
||||
Condition,
|
||||
Amount,
|
||||
Rarity,
|
||||
FirstEdition,
|
||||
Signed,
|
||||
Altered,
|
||||
|
||||
@@ -69,4 +69,31 @@ namespace ccm {
|
||||
&& std::isdigit(static_cast<unsigned char>(tail[1])) != 0;
|
||||
}
|
||||
|
||||
// Canonical short-form for Yu-Gi-Oh rarities used by the overview table.
|
||||
// Returns empty when rarity is unknown.
|
||||
[[nodiscard]] inline std::string ygoRarityShortCode(std::string_view rarity) {
|
||||
std::string normalized;
|
||||
normalized.reserve(rarity.size());
|
||||
for (unsigned char c : rarity) {
|
||||
if (std::isspace(c) != 0) continue;
|
||||
if (c == '\'' || c == '`' || c == '-') continue;
|
||||
normalized.push_back(static_cast<char>(std::tolower(c)));
|
||||
}
|
||||
|
||||
if (normalized == "common") return "C";
|
||||
if (normalized == "rare") return "R";
|
||||
if (normalized == "superrare") return "SR";
|
||||
if (normalized == "ultrarare") return "UR";
|
||||
if (normalized == "secretrare") return "ScR";
|
||||
if (normalized == "quartercenturysecretrare") return "QCScR";
|
||||
if (normalized == "qcsr") return "QCScR";
|
||||
if (normalized == "starlightrare") return "StR";
|
||||
if (normalized == "collectorsrare") return "CR";
|
||||
if (normalized == "ghostrare") return "GR";
|
||||
if (normalized == "ultimaterare") return "UtR";
|
||||
if (normalized == "platinumsecretrare") return "PlScR";
|
||||
if (normalized == "prismaticsecretrare") return "PScR";
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace ccm
|
||||
|
||||
@@ -15,7 +15,6 @@ void to_json(nlohmann::json& j, const YuGiOhCard& c) {
|
||||
{"condition", c.condition},
|
||||
{"firstEdition", c.firstEdition},
|
||||
{"rarity", c.rarity},
|
||||
{"rarityCode", c.rarityCode},
|
||||
{"signed", c.signed_},
|
||||
{"altered", c.altered},
|
||||
};
|
||||
@@ -33,8 +32,6 @@ void from_json(const nlohmann::json& j, YuGiOhCard& c) {
|
||||
j.at("condition").get_to(c.condition);
|
||||
j.at("firstEdition").get_to(c.firstEdition);
|
||||
j.at("rarity").get_to(c.rarity);
|
||||
if (j.contains("rarityCode")) j.at("rarityCode").get_to(c.rarityCode);
|
||||
else c.rarityCode.clear();
|
||||
j.at("signed").get_to(c.signed_);
|
||||
j.at("altered").get_to(c.altered);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "ccm/games/yugioh/YuGiOhCardPreviewSource.hpp"
|
||||
#include "ccm/util/YuGiOhPrintingSlot.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -134,6 +135,10 @@ std::string YuGiOhCardPreviewSource::normalizeName(std::string_view name) {
|
||||
}
|
||||
|
||||
std::string YuGiOhCardPreviewSource::rarityCodeFor(std::string_view rarityName) {
|
||||
if (const std::string canonical = ygoRarityShortCode(rarityName); !canonical.empty()) {
|
||||
return canonical;
|
||||
}
|
||||
|
||||
// Compare case-insensitively, ignoring whitespace, against a table of
|
||||
// CCM3 dialog values (see ui_wx/src/YuGiOhCardEditDialog.cpp:kRarityOptions)
|
||||
// plus a few extras occasionally seen in imported collections. The codes
|
||||
@@ -171,7 +176,7 @@ std::string YuGiOhCardPreviewSource::rarityCodeFor(std::string_view rarityName)
|
||||
{"ultraparallelrare", "UPR"},
|
||||
{"holographicrare", "HGR"},
|
||||
{"starlightrare", "StR"},
|
||||
{"collectorsrare", "ColR"},
|
||||
{"collectorsrare", "CR"},
|
||||
{"prismaticcollectorsrare", "PColR"},
|
||||
{"quartercenturysecretrare", "QCScR"},
|
||||
{"prismaticultimaterare", "PUtR"},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ccm/services/CardFilter.hpp"
|
||||
|
||||
#include "ccm/domain/Enums.hpp"
|
||||
#include "ccm/util/YuGiOhPrintingSlot.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
@@ -72,6 +73,7 @@ bool matchesYuGiOhFilter(const YuGiOhCard& card, std::string_view filter) {
|
||||
if (containsLower(card.set.name, needle)) return true;
|
||||
if (containsLower(card.setNo, needle)) return true;
|
||||
if (containsLower(card.rarity, needle)) return true;
|
||||
if (containsLower(ygoRarityShortCode(card.rarity), needle)) return true;
|
||||
if (containsLower(to_string(card.language), needle)) return true;
|
||||
if (containsLower(to_string(card.condition), needle)) return true;
|
||||
if (containsLower(std::to_string(card.amount), needle)) return true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ccm/services/CardSorter.hpp"
|
||||
|
||||
#include "ccm/domain/Enums.hpp"
|
||||
#include "ccm/util/YuGiOhPrintingSlot.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
@@ -203,6 +204,12 @@ void sortYuGiOhCards(std::vector<YuGiOhCard>& cards, YuGiOhSortColumn column,
|
||||
return a.amount < b.amount;
|
||||
}, ascending));
|
||||
break;
|
||||
case YuGiOhSortColumn::Rarity:
|
||||
std::stable_sort(cards.begin(), cards.end(), directional(
|
||||
[](const YuGiOhCard& a, const YuGiOhCard& b) {
|
||||
return asciiLower(ygoRarityShortCode(a.rarity)) < asciiLower(ygoRarityShortCode(b.rarity));
|
||||
}, ascending));
|
||||
break;
|
||||
case YuGiOhSortColumn::FirstEdition:
|
||||
std::stable_sort(cards.begin(), cards.end(), directional(
|
||||
[](const YuGiOhCard& a, const YuGiOhCard& b) {
|
||||
|
||||
Reference in New Issue
Block a user