Skip to content

Commit

Permalink
Merge pull request #126 from Cilda/fix-wrong-result-at-same-event-name
Browse files Browse the repository at this point in the history
同名のサポートカードイベントが存在する場合、選択肢を優先して読み取るように修正
  • Loading branch information
Cilda authored Feb 3, 2024
2 parents 9d26585 + 2c7e073 commit 54032fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions UmaUmaChecker/src/Data/EventData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ bool EventData::Load(const std::wstring& path)
if (EventMap.find(EventName) == EventMap.end()) {
EventMap[EventName] = event;
}

if (EventDuplicationCount.find(EventName) == EventDuplicationCount.end()) {
EventDuplicationCount[EventName] = 1;
}
else {
EventDuplicationCount[EventName]++;
}
}
}

Expand Down Expand Up @@ -199,6 +206,13 @@ std::shared_ptr<EventRoot> EventData::GetName(const std::wstring& name)
return itr->second;
}

bool EventData::IsEventNameDuplicate(const std::wstring& name)
{
if (EventDuplicationCount.find(name) == EventDuplicationCount.end()) return false;

return EventDuplicationCount[name] > 1;
}

void EventData::InitDB(const std::filesystem::path& path)
{
this->dbpath = path / L"event.db";
Expand Down
3 changes: 3 additions & 0 deletions UmaUmaChecker/src/Data/EventData.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class EventData : public BaseData
std::shared_ptr<EventRoot> RetrieveName(const std::wstring& name);
std::shared_ptr<EventRoot> GetName(const std::wstring& name);

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

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

private:
Expand All @@ -36,6 +38,7 @@ class EventData : public BaseData
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;
std::unordered_map<std::wstring, int> EventDuplicationCount;

std::filesystem::path dbpath;
std::filesystem::path optiondbpath;
Expand Down
2 changes: 1 addition & 1 deletion UmaUmaChecker/src/Recognizer/Uma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ EventSource* Uma::DetectEvent(const cv::Mat& srcImg, uint64* pHash, std::vector<
if (pHash) *pHash = hash;

auto event = GetCardEvent(events);
if (!event) event = GetEventByBottomOption(srcImg);
if (!event || EventLib.CardEvent.IsEventNameDuplicate(event->Name)) event = GetEventByBottomOption(srcImg);
if (config->EnableDebug && event && event.get() != CurrentEvent) LOG_DEBUG << L"[サポートカード] イベント名: " << event->Name;
return event.get();
}
Expand Down

0 comments on commit 54032fc

Please sign in to comment.