Skip to content

Commit

Permalink
Define Parse method for CSFParser
Browse files Browse the repository at this point in the history
  • Loading branch information
MahBoiDeveloper committed Jul 25, 2024
1 parent 58fe778 commit 45a952f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/GUI/Faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void Faction::SetHotkey(const QString& goName, const QString& actName, const QSt
{
if(currAct.iconName == actName)
{
CSFPARSER->SetHotkey(currAct.hotkeyString, hk.toStdWString()[0]);
CSF_PARSER->SetHotkey(currAct.hotkeyString, hk.toStdWString()[0]);
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/GUI/HotkeysMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void HotkeysMainWindow::SetGameObjectList(const QString& factionShortName)
for (const auto& go : goMap.keys(objectType))
{
QTreeWidgetItem* currentNewEntityItem = new QTreeWidgetItem();
currentNewEntityItem->setText(0, CSFPARSER->GetStringValue(go.ingameName));
currentNewEntityItem->setText(0, CSF_PARSER->GetStringValue(go.ingameName));
currentNewEntityItem->setIcon(0, QPixmap::fromImage(GUIConfig::DecodeWebpIcon(go.iconName)));
currentNewEntityItem->setData(0, Qt::UserRole, QVariant::fromValue(QPair{factionShortName, go.iconName}));
newTopEntityItem->addChild(currentNewEntityItem);
Expand Down Expand Up @@ -232,8 +232,8 @@ void HotkeysMainWindow::SetHotkeysPanelsWidget()

for (const auto& currAction : currLayout)
{
ActionHotkeyWidget* actionHotkey = new ActionHotkeyWidget{CSFPARSER->GetClearName(currAction.hotkeyString),
QString::fromStdWString(std::wstring{CSFPARSER->GetHotkey(currAction.hotkeyString)}),
ActionHotkeyWidget* actionHotkey = new ActionHotkeyWidget{CSF_PARSER->GetClearName(currAction.hotkeyString),
QString::fromStdWString(std::wstring{CSF_PARSER->GetHotkey(currAction.hotkeyString)}),
currAction.iconName};

// Remember widget
Expand Down
2 changes: 2 additions & 0 deletions src/GUI/WindowManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "LaunchWidget.hpp"
#include "HotkeysMainWindow.hpp"

#define WINDOW_MANAGER WindowManager::Instance

class WindowManager final
{
private: // Data
Expand Down
1 change: 0 additions & 1 deletion src/Logger.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#include <string>
#include <sstream>
#include <fstream>
Expand Down
4 changes: 2 additions & 2 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ int main(int argc, char *argv[])
QApplication HotkeyEditor(argc, argv);

// Define logger as a singleton class, that could be used anywhere in project
WindowManager::Instance = make_unique<WindowManager>();
CSFParser::Instance = make_unique<CSFParser>(Config::RESOURCE_FOLDER + "/DataSamples/generalsRU.csf");
WINDOW_MANAGER = make_unique<WindowManager>();
CSF_PARSER->Parse(Config::RESOURCE_FOLDER + "/DataSamples/generalsRU.csf");

try
{
Expand Down
17 changes: 11 additions & 6 deletions src/Parsers/CSFParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
using namespace std;

#pragma region CTORs and DTORs
CSFParser::CSFParser(const string& filePath) : Path{filePath}
CSFParser::CSFParser() {}
CSFParser::CSFParser(const string& filePath) {Parse(filePath);}
CSFParser::CSFParser(const char* filePath) {Parse(filePath);}
CSFParser::CSFParser(const QString& filePath) {Parse(filePath);}
#pragma endregion

#pragma region Parsing
void CSFParser::Parse(const char* strFilePath)
{
Path = QString{strFilePath}.toStdString();
ifstream csfFile(Path, ios::binary | ios::in);
LOGMSG("Attempt to read binary file \"" + Path + "\"...");

Expand All @@ -23,12 +31,9 @@ using namespace std;
throw Exception("Bad file name; unable to open file \"" + Path + "\"");
}
}
void CSFParser::Parse(const std::string& strFilePath) {Parse(strFilePath.c_str());}
void CSFParser::Parse(const QString& strFilePath) {Parse(strFilePath.toStdString().c_str());}

CSFParser::CSFParser(const char* filePath) : CSFParser{string{filePath}} {}
CSFParser::CSFParser(const QString& filePath) : CSFParser{filePath.toStdString()} {}
#pragma endregion

#pragma region Parsing
void CSFParser::ReadHeader(ifstream* csfFile)
{
csfFile->read(reinterpret_cast<char*>(&Header), sizeof(Header));
Expand Down
13 changes: 10 additions & 3 deletions src/Parsers/CSFParser.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

#include <list>
#include <memory>
#include <string>
#include <sstream>
#include <fstream>
#include <QStringList>

#define CSFPARSER CSFParser::Instance
#define CSF_PARSER CSFParser::Instance

class CSFParser final
{
Expand Down Expand Up @@ -46,7 +45,7 @@ class CSFParser final
std::list<CompiledString> Table;

public:
inline static std::unique_ptr<CSFParser> Instance;
inline const static std::unique_ptr<CSFParser> Instance = std::make_unique<CSFParser>();

private: // Methods
void ReadHeader(std::ifstream* csfFile);
Expand All @@ -61,10 +60,18 @@ class CSFParser final
std::wstring WharArrayToWstring(const size_t& arrayLength, const wchar_t* pArray) const;

public:
CSFParser();
CSFParser(const std::string& strFilePath);
CSFParser(const char* strFilePath);
CSFParser(const QString& strFilePath);

/// @brief Parse .csf file with direct path.
void Parse(const std::string& strFilePath);
/// @brief Parse .csf file with direct path.
void Parse(const char* strFilePath);
/// @brief Parse .csf file with direct path.
void Parse(const QString& strFilePath);

/// @brief Save compiled sting table data to the parsed file before.
void Save();
/// @brief Save compiled string table data to the specific file.
Expand Down

0 comments on commit 45a952f

Please sign in to comment.