moved messages to Json, some refactoring

This commit is contained in:
ALEXks
2025-05-23 15:56:37 +03:00
parent 6c16cc5432
commit 879094a6b7
6 changed files with 74 additions and 55 deletions

View File

@@ -1,5 +1,7 @@
#pragma once
#include <string>
#include "json.hpp"
#ifdef __SPF
#include "dvm.h"
#endif
@@ -164,18 +166,40 @@ public:
engMessage.erase(engMessage.begin() + engMessage.size() - 1);
}
std::wstring toString() const
nlohmann::json toJson() const
{
std::wstring retVal = L"|";
retVal += std::to_wstring((int)type) + L" ";
retVal += std::to_wstring(line) + L" ";
retVal += std::to_wstring(group);
retVal += L"|" + value;
return retVal;
nlohmann::json resVal;
resVal["line"] = line;
resVal["group"] = group;
resVal["value"] = std::string(value.begin(), value.end());
return resVal;
}
std::string getString() const { return std::string(engMessage.begin(), engMessage.end()); }
public:
typeMessage getType() const { return type; }
int getLine() const { return line; }
void print(const std::string& file) const
{
std::string toPrint = "";
for (int z = 0; z < engMessage.size(); ++z)
toPrint += engMessage[z];
std::string typeStr;
if (type == WARR)
typeStr = "WARR";
else if (type == ERROR)
typeStr = "ERROR";
else if (type == NOTE)
typeStr = "NOTE";
else
typeStr = "UNKN";
printf("%s - [#%d: %s: line %d]: %s\n", typeStr.c_str(), group, file.c_str(), line, toPrint.c_str());
}
auto getUniqKey() const { return std::make_tuple(type, group, line, value); }
private:
typeMessage type;
int group;
int line;