reflect : format code

This commit is contained in:
2026-06-21 07:05:59 +08:00
Unverified
parent e475259310
commit edbec18b0b
9 changed files with 291 additions and 264 deletions
+35 -20
View File
@@ -11,6 +11,8 @@
#include "ll/api/data/IndirectValue.h"
#include "gmlib/gm/i18n/LangI18n.h"
#include "gmlib/gm/i18n/ResourceI18n.h"
#include "ll/api/mod/ModManagerRegistry.h"
#include <ll/api/service/Bedrock.h>
ll::io::LoggerRegistry& loggerRegistry = ll::io::LoggerRegistry::getInstance();
std::shared_ptr<ll::io::Logger> logger = loggerRegistry.getOrCreate(MOD_NAME);
@@ -26,27 +28,32 @@ Entry& Entry::getInstance() {
}
bool Entry::load() {
isResourceI18nLoaded=false;
mConfig.emplace();
if (!ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / u8"config.json")) {
ll::config::saveConfig(*mConfig, getSelf().getConfigDir() / u8"config.json");
}
if (getConfig().ServerSideTranslation.Enabled) {
loadI18n();
} else {
loadResourcePack();
}
if (getConfig().FileLog.Enabled) {
auto& path = getConfig().FileLog.Path;
ll::Polymorphic<ll::io::PatternFormatter> polymorphicFormatter =
ll::makePolymorphic<ll::io::PatternFormatter>("[{3:.3%F %T.} {2}][{1}] {0}", false);
deathLogger->addSink(std::make_shared<ll::io::FileSink>(path, polymorphicFormatter));
}
loadI18n();
if ((!getConfig().ServerSideTranslation.Enabled)&&ll::mod::ModManagerRegistry::getInstance().hasMod("ModAPI")) {
loadResourcePack();
}
return true;
}
bool Entry::enable() {
RegisterDamageDefinition();
/* ListenEvents();*/
if (!ll::mod::ModManagerRegistry::getInstance().hasMod("ModAPI")) {
getSelf().getLogger().warn(tr("plugin.deathmessages.modapi.warn"));
}
RegisterDamageDefinition();
ListenEvents();
return true;
}
@@ -55,13 +62,16 @@ bool Entry::disable() { return true; }
bool Entry::unload() {
mConfig.reset();
mI18n.reset();
uninstallHooks();
// getInstance().reset();
return true;
}
Config& Entry::getConfig() { return mConfig.value(); }
std::unique_ptr<gmlib::i18n::LangI18n> Entry::getI18n() { return std::move(mI18n); }
gmlib::i18n::LangI18n& Entry::getI18n() {
return *mI18n;
}
void Entry::loadI18n() {
mI18n= std::make_unique<gmlib::i18n::LangI18n>(getSelf().getLangDir(), getConfig().ServerSideTranslation.Language);
@@ -71,24 +81,29 @@ void Entry::loadI18n() {
mI18n->setDefaultLanguage("zh_CN");
}
void Entry::loadResourcePack() {
auto resource = gmlib::i18n::ResourceI18n{getSelf().getModDir() / u8"lang", MOD_NAME, 0, 8, 0};
resource.addLanguage("en_US", en_US);
resource.addLanguage("zh_CN", zh_CN);
resource.loadAllLanguages();
auto mResource = std::make_unique<gmlib::i18n::ResourceI18n>(getSelf().getModDir() / u8"lang", MOD_NAME, 0, 16, 0);
mResource->addLanguage("en_US", en_US);
mResource->addLanguage("zh_CN", zh_CN);
mResource->loadAllLanguages();
isResourceI18nLoaded=true;
}
} // namespace DeathMessages
LL_REGISTER_MOD(DeathMessages::Entry, DeathMessages::Entry::getInstance());
/*std::string tr(std::string const& key, std::vector<std::string> const& params) {
if (auto i18n = DeathMessages::Entry::getInstance().getI18n()) {
return i18n->get(key, params);
}
auto i18n = DeathMessages::Entry::getI18n();
return i18n->get(key, params);
std::string tr(std::string const& key, std::vector<std::string> const& params) {
auto& i18n = DeathMessages::Entry::getInstance().getI18n();
return i18n.get(key, params);
}*/
return key;
}