Skip to content

Commit

Permalink
Merge pull request #140 from Cilda/change-umamusume-order
Browse files Browse the repository at this point in the history
育成ウマ娘を名前の昇順で並ぶよう変更
  • Loading branch information
Cilda authored Oct 5, 2024
2 parents 266f6f2 + f470413 commit b4c8a42
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 30 deletions.
16 changes: 7 additions & 9 deletions UmaUmaChecker/src/Data/EventData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EventData::~EventData()
{
}

bool EventData::Load(const std::wstring& path)
bool EventData::Load(const std::wstring& path, bool sort)
{
std::fstream stream(path);
if (!stream.good()) return false;
Expand All @@ -28,8 +28,6 @@ bool EventData::Load(const std::wstring& path)
json skills = json::parse(stream);

for (auto& cards : skills.items().begin().value()) {
std::vector<std::shared_ptr<EventRoot>> RankList;

for (auto& card : cards.items()) {
auto name = card.key();
auto events = card.value()["Events"];
Expand Down Expand Up @@ -75,23 +73,23 @@ bool EventData::Load(const std::wstring& path)
}

EventRoots.push_back(skill);
RankList.push_back(skill);

NameMap[skill->Name] = skill;
}
}

std::sort(RankList.begin(), RankList.end(), [](std::shared_ptr<EventRoot> a, std::shared_ptr<EventRoot> b) {
if (sort) {
std::sort(EventRoots.begin(), EventRoots.end(), [](std::shared_ptr<EventRoot> a, std::shared_ptr<EventRoot> b) {
std::wregex regex(L"^[(.+?)](.+?)$");
std::wcmatch m1, m2;

std::regex_search(a->Name.c_str(), m1, regex);
std::regex_search(b->Name.c_str(), m2, regex);

return m1[2].str() < m2[2].str();
});
int comp = m1[2].str().compare(m2[2].str());

ByRank.push_back(RankList);
RankList.clear();
return comp != 0 ? comp < 0 : m1[1].str() < m2[1].str();
});
}
}
catch (json::exception& ex) {
Expand Down
6 changes: 2 additions & 4 deletions UmaUmaChecker/src/Data/EventData.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ class EventData : public BaseData
EventData();
~EventData();

bool Load(const std::wstring& path);
bool Load(const std::wstring& path, bool sort = false);

std::shared_ptr<EventSource> RetrieveTitle(const std::wstring& title, EventRoot* root = nullptr) override;
std::shared_ptr<EventSource> RetrieveOption(const std::wstring& option, EventRoot* root = nullptr) override;
std::wstring RetrieveOptionTitle(const std::wstring& option, EventRoot* root = nullptr) override;
std::shared_ptr<EventRoot> RetrieveName(const std::wstring& name);
std::shared_ptr<EventRoot> GetName(const std::wstring& name);
const std::vector<std::shared_ptr<EventRoot>>& GetRoots() const { return EventRoots; }

bool IsEventNameDuplicate(const std::wstring& name);

const std::vector<std::vector<std::shared_ptr<EventRoot>>>& GetRanks() const { return ByRank; }

private:
void InitDB(const std::filesystem::path& path);
std::wstring GetBestMatchString(const std::vector<std::wstring>& xstrs, const std::wstring& text);

private:
std::vector<std::shared_ptr<EventRoot>> EventRoots;
std::vector<std::vector<std::shared_ptr<EventRoot>>> ByRank;
std::unordered_map<std::wstring, std::shared_ptr<EventSource>> EventMap;
std::unordered_map<std::wstring, std::shared_ptr<EventSource>> OptionMap;
std::unordered_map<std::wstring, std::shared_ptr<EventRoot>> NameMap;
Expand Down
2 changes: 1 addition & 1 deletion UmaUmaChecker/src/Data/EventLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool EventLibrary::Load()
wxMessageBox(_("Failed to load SupportCard Event Data."), app_name, wxICON_ERROR);
return false;
}
if (!CharaEvent.Load(path + L"\\Library\\Chara.json")) {
if (!CharaEvent.Load(path + L"\\Library\\Chara.json", true)) {
wxMessageBox(_("Failed to load Umamusume Event Data."), app_name, wxICON_ERROR);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions UmaUmaChecker/src/Recognizer/Uma.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Uma
bool SetTrainingCharacter(const std::wstring& CharaName);
std::wstring GetTrainingCharacter() const { return CurrentCharacter ? CurrentCharacter->Name : L""; }

const std::vector<std::vector<std::shared_ptr<EventRoot>>>& GetCharacters() const {
return EventLib.CharaEvent.GetRanks();
const std::vector<std::shared_ptr<EventRoot>>& GetCharacters() const {
return EventLib.CharaEvent.GetRoots();
}

std::shared_ptr<EventSource> DetectEvent(const cv::Mat& srcImg, uint64* pHash = nullptr, std::vector<std::wstring>* pEvents = nullptr, bool* bScaned = nullptr);
Expand Down
18 changes: 4 additions & 14 deletions UmaUmaChecker/src/UI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,9 @@ void MainFrame::OnComboTextUpdate(wxCommandEvent& event)
}

m_comboPopup->ClearList();
for (auto& rank : umaMgr->GetCharacters()) {
for (auto& chara : rank) {
if (chara->Name.find(value) != std::wstring::npos) {
m_comboPopup->AddString(chara->Name);
}
for (auto& chara : umaMgr->GetCharacters()) {
if (chara->Name.find(value) != std::wstring::npos) {
m_comboPopup->AddString(chara->Name);
}
}
}
Expand Down Expand Up @@ -708,17 +706,9 @@ void MainFrame::ChangeTheme()

void MainFrame::SetTrainingCharaComboBox()
{
int r = 3;

auto& characters = umaMgr->GetCharacters();
for (auto itr = characters.begin(); itr != characters.end(); itr++) {
m_comboBoxUma->Append(std::wstring(L"") + std::to_wstring(r));

for (auto& chara : *itr) {
m_comboBoxUma->Append(chara->Name);
}

r--;
m_comboBoxUma->Append((*itr)->Name);
}
}

Expand Down

0 comments on commit b4c8a42

Please sign in to comment.