From 8dfa4bd0395c221d9a2a9fdc5525dc9426f1203c Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Fri, 30 Jan 2026 20:23:39 +0800 Subject: [PATCH] feat: initialize BMapInspector project --- Ballance/BMapInspector/BMapInspector.cpp | 22 +++++ Ballance/BMapInspector/CMakeLists.txt | 3 +- Ballance/BMapInspector/Rule.hpp | 0 Ballance/BMapInspector/Ruleset.cpp | 27 ++++++ Ballance/BMapInspector/Ruleset.hpp | 34 +++++++ Ballance/BMapInspector/Rulesets.hpp | 0 Ballance/BMapInspector/Utils.cpp | 109 +++++++++++++++++++++++ Ballance/BMapInspector/Utils.hpp | 43 +++++++++ 8 files changed, 237 insertions(+), 1 deletion(-) delete mode 100644 Ballance/BMapInspector/Rule.hpp create mode 100644 Ballance/BMapInspector/Ruleset.cpp create mode 100644 Ballance/BMapInspector/Ruleset.hpp delete mode 100644 Ballance/BMapInspector/Rulesets.hpp diff --git a/Ballance/BMapInspector/BMapInspector.cpp b/Ballance/BMapInspector/BMapInspector.cpp index bcb9efe..0b6cc04 100644 --- a/Ballance/BMapInspector/BMapInspector.cpp +++ b/Ballance/BMapInspector/BMapInspector.cpp @@ -1,4 +1,26 @@ +#include "Utils.hpp" +#include +#include +#include +#include +#include + +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; } diff --git a/Ballance/BMapInspector/CMakeLists.txt b/Ballance/BMapInspector/CMakeLists.txt index 6fe9b68..c71efee 100644 --- a/Ballance/BMapInspector/CMakeLists.txt +++ b/Ballance/BMapInspector/CMakeLists.txt @@ -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 diff --git a/Ballance/BMapInspector/Rule.hpp b/Ballance/BMapInspector/Rule.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/Ballance/BMapInspector/Ruleset.cpp b/Ballance/BMapInspector/Ruleset.cpp new file mode 100644 index 0000000..eff1531 --- /dev/null +++ b/Ballance/BMapInspector/Ruleset.cpp @@ -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& RuleCollection::GetRules() const { + return this->rules; + } + +#pragma endregion + +} // namespace BMapInspector::Ruleset diff --git a/Ballance/BMapInspector/Ruleset.hpp b/Ballance/BMapInspector/Ruleset.hpp new file mode 100644 index 0000000..2671cc4 --- /dev/null +++ b/Ballance/BMapInspector/Ruleset.hpp @@ -0,0 +1,34 @@ +#pragma once +#include +#include +#include +#include +#include + +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 &GetRules() const; + + private: + std::vector rules; + }; + +} // namespace BMapInspector::Ruleset diff --git a/Ballance/BMapInspector/Rulesets.hpp b/Ballance/BMapInspector/Rulesets.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/Ballance/BMapInspector/Utils.cpp b/Ballance/BMapInspector/Utils.cpp index e69de29..820ee37 100644 --- a/Ballance/BMapInspector/Utils.cpp +++ b/Ballance/BMapInspector/Utils.cpp @@ -0,0 +1,109 @@ +#include "Utils.hpp" +#include +#include +#include +#include +#include + +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 diff --git a/Ballance/BMapInspector/Utils.hpp b/Ballance/BMapInspector/Utils.hpp index e69de29..0d75772 100644 --- a/Ballance/BMapInspector/Utils.hpp +++ b/Ballance/BMapInspector/Utils.hpp @@ -0,0 +1,43 @@ +#pragma once +#include +#include +#include +#include +#include + +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 reports; + }; + +} // namespace BMapInspector::Utils