1
0

feat: initialize BMapInspector project

This commit is contained in:
2026-01-30 20:23:39 +08:00
parent 6b0d73177b
commit 8dfa4bd039
8 changed files with 237 additions and 1 deletions

View File

@@ -1,4 +1,26 @@
#include "Utils.hpp"
#include <VTAll.hpp>
#include <yycc.hpp>
#include <yycc/carton/termcolor.hpp>
#include <yycc/patch/stream.hpp>
#include <iostream>
using namespace yycc::patch::stream;
namespace termcolor = yycc::carton::termcolor;
int main(int argc, char *argv[]) {
// Show splash
std::cout << termcolor::colored(u8"Ballance Map Inspector", termcolor::Color::LightYellow)
<< " (based on LibCmo " LIBCMO_VER_STR ") built at " __DATE__ " " __TIME__ << std::endl
<< u8"The inspector for checking whether your Ballance custom map can be loaded without any issues." << std::endl;
// Create reporter
BMapInspector::Utils::Reporter reporter;
// Show report
reporter.PrintConclusion();
reporter.PrintDetails();
return 0;
}

View File

@@ -5,6 +5,7 @@ target_sources(BMapInspector
PRIVATE
BMapInspector.cpp
Utils.cpp
Ruleset.cpp
)
# Setup headers
target_sources(BMapInspector
@@ -12,7 +13,7 @@ PRIVATE
FILE_SET HEADERS
FILES
Utils.hpp
Rule.hpp
Ruleset.hpp
)
# Setup header infomation
target_include_directories(BMapInspector

View File

@@ -0,0 +1,27 @@
#include "Ruleset.hpp"
namespace BMapInspector::Ruleset {
#pragma region IRule
IRule::IRule() {}
IRule::~IRule() {}
#pragma endregion
#pragma region Rule Collection
RuleCollection::RuleCollection() : rules() {
// TODO: create instance for each rules.
}
RuleCollection::~RuleCollection() {}
const std::vector<IRule*>& RuleCollection::GetRules() const {
return this->rules;
}
#pragma endregion
} // namespace BMapInspector::Ruleset

View File

@@ -0,0 +1,34 @@
#pragma once
#include <yycc.hpp>
#include <yycc/macro/class_copy_move.hpp>
#include <string>
#include <string_view>
#include <vector>
namespace BMapInspector::Ruleset {
class IRule {
public:
IRule();
virtual ~IRule();
YYCC_DELETE_COPY_MOVE(IRule)
public:
virtual std::u8string_view GetRuleName() const = 0;
virtual void Check() const = 0;
};
class RuleCollection {
public:
RuleCollection();
~RuleCollection();
YYCC_DELETE_COPY_MOVE(RuleCollection)
public:
const std::vector<IRule *> &GetRules() const;
private:
std::vector<IRule *> rules;
};
} // namespace BMapInspector::Ruleset

View File

@@ -0,0 +1,109 @@
#include "Utils.hpp"
#include <yycc/carton/termcolor.hpp>
#include <yycc/string/op.hpp>
#include <yycc/patch/stream.hpp>
#include <iostream>
#include <cstdarg>
using namespace yycc::patch::stream;
namespace strop = yycc::string::op;
namespace termcolor = yycc::carton::termcolor;
#define PRIuSIZET "zu"
namespace BMapInspector::Utils {
#pragma region Reporter
Reporter::Reporter() {}
Reporter::~Reporter() {}
void Reporter::AddReport(ReportKind kind, const std::u8string_view &rule, const std::u8string_view &content) {
this->reports.emplace_back(Report{
.kind = kind,
.rule = std::u8string(rule),
.content = std::u8string(content),
});
}
void Reporter::WriteInfo(const std::u8string_view &rule, const std::u8string_view &content) {
this->AddReport(ReportKind::Info, rule, content);
}
void Reporter::FormatInfo(const std::u8string_view &rule, const char8_t *fmt, ...) {
va_list argptr;
va_start(argptr, fmt);
this->WriteInfo(rule, strop::vprintf(fmt, argptr));
va_end(argptr);
}
void Reporter::WriteWarning(const std::u8string_view &rule, const std::u8string_view &content) {
this->AddReport(ReportKind::Warning, rule, content);
}
void Reporter::FormatWarning(const std::u8string_view &rule, const char8_t *fmt, ...) {
va_list argptr;
va_start(argptr, fmt);
this->WriteWarning(rule, strop::vprintf(fmt, argptr));
va_end(argptr);
}
void Reporter::WriteError(const std::u8string_view &rule, const std::u8string_view &content) {
this->AddReport(ReportKind::Error, rule, content);
}
void Reporter::FormatError(const std::u8string_view &rule, const char8_t *fmt, ...) {
va_list argptr;
va_start(argptr, fmt);
this->WriteError(rule, strop::vprintf(fmt, argptr));
va_end(argptr);
}
void Reporter::PrintConclusion() const {
// Conclude count
size_t cnt_err = 0, cnt_warn = 0, cnt_info = 0;
for (const auto &report : this->reports) {
switch (report.kind) {
case ReportKind::Error:
++cnt_err;
break;
case ReportKind::Warning:
++cnt_warn;
break;
case ReportKind::Info:
++cnt_info;
break;
}
}
// Show in console
termcolor::cprintln(strop::printf(u8"Total %" PRIuSIZET " error(s), %" PRIuSIZET " warning(s) and %" PRIuSIZET " info(s).",
cnt_err,
cnt_warn,
cnt_info),
termcolor::Color::LightBlue);
}
void Reporter::PrintDetails() const {
// Print all entries by different color
for (const auto &report : this->reports) {
switch (report.kind) {
case ReportKind::Error:
termcolor::cprintln(strop::printf(u8"[ERROR] [RULE: %s] %s", report.rule.c_str(), report.content.c_str()),
termcolor::Color::LightRed);
break;
case ReportKind::Warning:
termcolor::cprintln(strop::printf(u8"[WARNING] [RULE: %s] %s", report.rule.c_str(), report.content.c_str()),
termcolor::Color::LightYellow);
break;
case ReportKind::Info:
termcolor::cprintln(strop::printf(u8"[INFO] [RULE: %s] %s", report.rule.c_str(), report.content.c_str()),
termcolor::Color::Default);
break;
}
}
}
#pragma endregion
} // namespace BMapInspector::Utils

View File

@@ -0,0 +1,43 @@
#pragma once
#include <yycc.hpp>
#include <yycc/macro/class_copy_move.hpp>
#include <string>
#include <string_view>
#include <vector>
namespace BMapInspector::Utils {
enum class ReportKind { Error, Warning, Info };
struct Report {
ReportKind kind; ///< The kind of this report.
std::u8string rule; ///< The name of rule adding this report.
std::u8string content; ///< The content of this report.
};
class Reporter {
public:
Reporter();
~Reporter();
YYCC_DEFAULT_COPY_MOVE(Reporter)
private:
void AddReport(ReportKind kind, const std::u8string_view& rule, const std::u8string_view& content);
public:
void WriteInfo(const std::u8string_view& rule, const std::u8string_view& content);
void FormatInfo(const std::u8string_view& rule, const char8_t* fmt, ...);
void WriteWarning(const std::u8string_view& rule, const std::u8string_view& content);
void FormatWarning(const std::u8string_view& rule, const char8_t* fmt, ...);
void WriteError(const std::u8string_view& rule, const std::u8string_view& content);
void FormatError(const std::u8string_view& rule, const char8_t* fmt, ...);
public:
void PrintConclusion() const;
void PrintDetails() const;
private:
std::vector<Report> reports;
};
} // namespace BMapInspector::Utils