Skip to content

Commit

Permalink
Merge pull request #109 from Cilda/improve-load-all-resources-on-startup
Browse files Browse the repository at this point in the history
リソースデータを起動時に全て読み込むように、読み込めなかった場合はエラーを表示する
  • Loading branch information
Cilda authored Oct 14, 2023
2 parents a04e9e7 + debb34e commit f4fc56c
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 136 deletions.
18 changes: 9 additions & 9 deletions UmaUmaChecker/UmaUmaChecker.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@
<ClCompile Include="src\UI\CheckUpdateDialog.cpp" />
<ClCompile Include="src\Recognizer\CombineImage.cpp" />
<ClCompile Include="src\UI\DebugImageCombineFrame.cpp" />
<ClCompile Include="src\Loader\Event\EventData.cpp" />
<ClCompile Include="src\Data\EventData.cpp" />
<ClCompile Include="src\UI\FontComboBox.cpp" />
<ClCompile Include="src\UI\GrandLiveMusicListFrame.cpp" />
<ClCompile Include="src\Log\Log.cpp" />
<ClCompile Include="src\Loader\Event\ScenarioData.cpp" />
<ClCompile Include="src\Data\ScenarioData.cpp" />
<ClCompile Include="src\Recognizer\ScrollbarDetector.cpp" />
<ClCompile Include="src\Tesseract\Tesseract.cpp" />
<ClCompile Include="src\UI\Theme\ThemeWrapper.cpp" />
Expand All @@ -266,9 +266,9 @@
<ClCompile Include="src\UI\PreviewFrame.cpp" />
<ClCompile Include="src\UI\SettingDialog.cpp" />
<ClCompile Include="src\System\SystemUsage.cpp" />
<ClCompile Include="src\Loader\Event\TextCollector.cpp" />
<ClCompile Include="src\Data\TextCollector.cpp" />
<ClCompile Include="src\Recognizer\Uma.cpp" />
<ClCompile Include="src\Loader\Event\EventLibrary.cpp" />
<ClCompile Include="src\Data\EventLibrary.cpp" />
<ClCompile Include="src\UI\MainFrame.cpp" />
<ClCompile Include="src\Utils\utility.cpp" />
<ClCompile Include="src\UI\wxTextPopupCtrl.cpp" />
Expand All @@ -288,13 +288,13 @@
<ClInclude Include="src\UI\CheckUpdateDialog.h" />
<ClInclude Include="src\Recognizer\CombineImage.h" />
<ClInclude Include="src\UI\DebugImageCombineFrame.h" />
<ClInclude Include="src\Loader\Event\EventData.h" />
<ClInclude Include="src\Data\EventData.h" />
<ClInclude Include="src\UI\FontComboBox.h" />
<ClInclude Include="src\UI\GrandLiveMusicListFrame.h" />
<ClInclude Include="src\Log\Log.h" />
<ClInclude Include="src\object_pool.hpp" />
<ClInclude Include="src\Point.h" />
<ClInclude Include="src\Loader\Event\ScenarioData.h" />
<ClInclude Include="src\Data\ScenarioData.h" />
<ClInclude Include="src\Recognizer\ScrollbarDetector.h" />
<ClInclude Include="src\Tesseract\Tesseract.h" />
<ClInclude Include="src\UI\Theme\ThemeWrapper.h" />
Expand All @@ -310,12 +310,12 @@
<ClInclude Include="src\UI\DebugFrame.h" />
<ClInclude Include="src\UI\PreviewFrame.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="src\Loader\Event\Event.h" />
<ClInclude Include="src\Data\Event.h" />
<ClInclude Include="src\UI\SettingDialog.h" />
<ClInclude Include="src\System\SystemUsage.h" />
<ClInclude Include="src\Loader\Event\TextCollector.h" />
<ClInclude Include="src\Data\TextCollector.h" />
<ClInclude Include="src\Recognizer\Uma.h" />
<ClInclude Include="src\Loader\Event\EventLibrary.h" />
<ClInclude Include="src\Data\EventLibrary.h" />
<ClInclude Include="src\UI\MainFrame.h" />
<ClInclude Include="src\Utils\utility.h" />
<ClInclude Include="src\version.h" />
Expand Down
18 changes: 9 additions & 9 deletions UmaUmaChecker/UmaUmaChecker.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<ClCompile Include="src\Utils\utility.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="src\Loader\Event\EventLibrary.cpp">
<ClCompile Include="src\Data\EventLibrary.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="src\Loader\Event\TextCollector.cpp">
<ClCompile Include="src\Data\TextCollector.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp">
Expand Down Expand Up @@ -87,7 +87,7 @@
<ClCompile Include="src\UI\FontComboBox.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="src\Loader\Event\EventData.cpp">
<ClCompile Include="src\Data\EventData.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="src\Log\Log.cpp">
Expand All @@ -102,7 +102,7 @@
<ClCompile Include="src\Tesseract\Tesseract.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="src\Loader\Event\ScenarioData.cpp">
<ClCompile Include="src\Data\ScenarioData.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="src\Capture\UmaWindowCapture.cpp">
Expand All @@ -128,13 +128,13 @@
<ClInclude Include="src\Utils\utility.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\Loader\Event\EventLibrary.h">
<ClInclude Include="src\Data\EventLibrary.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\Loader\Event\Event.h">
<ClInclude Include="src\Data\Event.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\Loader\Event\TextCollector.h">
<ClInclude Include="src\Data\TextCollector.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\UI\MainFrame.h">
Expand Down Expand Up @@ -197,7 +197,7 @@
<ClInclude Include="src\UI\FontComboBox.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\Loader\Event\EventData.h">
<ClInclude Include="src\Data\EventData.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\Log\Log.h">
Expand All @@ -212,7 +212,7 @@
<ClInclude Include="src\Tesseract\Tesseract.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\Loader\Event\ScenarioData.h">
<ClInclude Include="src\Data\ScenarioData.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="src\Capture\UmaWindowCapture.h">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
99 changes: 99 additions & 0 deletions UmaUmaChecker/src/Data/EventLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <string>

#include "EventLibrary.h"
#include "Utils/utility.h"

#include <sstream>
#include <fstream>
#include <regex>

#include <wx/msgdlg.h>

#include <nlohmann/json.hpp>
#include "simstring/simstring.h"
#include "Log/Log.h"

#include "version.h"

using json = nlohmann::ordered_json;

EventLibrary EventLib;

EventLibrary::EventLibrary()
{
std::string BasePath = utility::to_string(utility::GetExeDirectory());
DBPath = BasePath + "\\simstring\\";
}

EventLibrary::~EventLibrary()
{
}

void EventLibrary::Clear()
{
}

bool EventLibrary::Load()
{
auto start = std::chrono::system_clock::now();

CardEvent = EventData();
CharaEvent = EventData();
ScenarioEvent = ScenarioData();

std::wstring path = utility::GetExeDirectory();

DeleteDBFiles();

if (!CardEvent.Load(path + L"\\Library\\Events.json")) {
wxMessageBox(wxT("サポートカードイベントの読み込みに失敗しました。"), app_name, wxICON_ERROR);
return false;
}
if (!CharaEvent.Load(path + L"\\Library\\Chara.json")) {
wxMessageBox(wxT("キャライベントの読み込みに失敗しました。"), app_name, wxICON_ERROR);
return false;
}
if (!ScenarioEvent.Load(path + L"\\Library\\ScenarioEvents.json")) {
wxMessageBox(wxT("シナリオイベントの読み込みに失敗しました。"), app_name, wxICON_ERROR);
return false;
}
if (!LoadSkills()) {
wxMessageBox(wxT("スキルデータの読み込みに失敗しました。"), app_name, wxICON_ERROR);
return false;
}

auto end = std::chrono::system_clock::now();
auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

LOG_INFO << "Loaded EventData at " << msec << " msec!";

return true;
}

void EventLibrary::DeleteDBFiles()
{
std::filesystem::remove_all(DBPath);
}

bool EventLibrary::LoadSkills()
{
SkillMap.clear();

std::fstream stream(utility::GetExeDirectory() + L"\\Library\\Skills.json");
if (stream.good()) {
try {
json skills = json::parse(stream);

for (auto skill : skills) {
SkillMap[utility::from_u8string(skill["Name"].get<std::string>())] = utility::from_u8string(skill["Description"].get<std::string>());
}
}
catch (json::exception& ex) {
return false;
}

return true;
}

return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class EventLibrary

private:
void DeleteDBFiles();
bool LoadSkills();

public:
EventData CardEvent;
EventData CharaEvent;
ScenarioData ScenarioEvent;
std::unordered_map<std::wstring, std::wstring> SkillMap; // スキル名 -> 説明

private:
std::string DBPath;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ void TextCollector::Load()
{
std::fstream stream(utility::GetExeDirectory() + L"\\Library\\ReplaceText.json");
if (stream.good()) {
std::stringstream text;

text << stream.rdbuf();

try {
json replaces = json::parse(text.str());
json replaces = json::parse(stream);

for (auto& arr : replaces["replaces"]) {
collections.emplace_back(
Expand Down
File renamed without changes.
63 changes: 0 additions & 63 deletions UmaUmaChecker/src/Loader/Event/EventLibrary.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions UmaUmaChecker/src/Recognizer/Uma.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "Loader/Event/EventLibrary.h"
#include "Loader/Event/TextCollector.h"
#include "Data/EventLibrary.h"
#include "Data/TextCollector.h"

#include <wx/frame.h>

Expand Down
38 changes: 2 additions & 36 deletions UmaUmaChecker/src/UI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,6 @@ void MainFrame::Init()

SetTrainingCharaComboBox();

if (!LoadSkills()) wxMessageBox(wxT("Skills.json を読み込めませんでした。"), app_name, wxICON_ERROR);

/*
if (Config::GetInstance()->EnableDebug) {
m_DebugFrame = new DebugFrame(this);
m_DebugFrame->Show();
}
*/

#ifdef _DEBUG
new wxLogWindow(this, wxT("ログ"));
DebugFrame* debug = new DebugFrame(this);
Expand All @@ -214,31 +205,6 @@ void MainFrame::Init()
#endif
}

bool MainFrame::LoadSkills()
{
std::fstream stream(utility::GetExeDirectory() + L"\\Library\\Skills.json");
if (stream.good()) {
std::stringstream text;

text << stream.rdbuf();

try {
json skills = json::parse(text.str());

for (auto skill : skills) {
SkillMap[utility::from_u8string(skill["Name"].get<std::string>())] = utility::from_u8string(skill["Description"].get<std::string>());
}
}
catch (json::exception& ex) {
return false;
}

return true;
}

return false;
}

void MainFrame::OnClose(wxCloseEvent& event)
{
if (thread.joinable()) {
Expand Down Expand Up @@ -704,9 +670,9 @@ std::wstring MainFrame::GetSkillDescFromOption(const std::wstring& option)
begin = match[0].second;
auto name = match[1].str();

if (SkillSet.find(name) == SkillSet.end() && SkillMap.find(name) != SkillMap.end()) {
if (SkillSet.find(name) == SkillSet.end() && EventLib.SkillMap.find(name) != EventLib.SkillMap.end()) {
if (!desc.empty()) desc += L"\n\n";
desc += L"" + match[1].str() + L"\n" + SkillMap.at(name);
desc += L"" + match[1].str() + L"\n" + EventLib.SkillMap.at(name);
SkillSet.insert(name);
}
}
Expand Down
Loading

0 comments on commit f4fc56c

Please sign in to comment.