This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "Config.h" | ||
#include "entry/Entry.h" | ||
|
||
#include <filesystem> | ||
#include <ll/api/Config.h> | ||
#include <ll/api/i18n/I18n.h> | ||
|
||
namespace tls::config { | ||
|
||
S_Config cfg; // init Config | ||
|
||
#define CONFIG_FILE_NAME "Config.json" | ||
using ll::i18n_literals::operator""_tr; | ||
|
||
|
||
bool loadConfig() { | ||
auto& mSelf = entry::entry::getInstance().getSelf(); | ||
auto filePath = mSelf.getConfigDir() / CONFIG_FILE_NAME; | ||
auto& logger = mSelf.getLogger(); | ||
// init file | ||
std::filesystem::path p = filePath; | ||
if (!std::filesystem::exists(p)) { | ||
logger.info("Saving default configurations"); | ||
writeConfig(cfg); | ||
} | ||
// loading | ||
if (!ll::config::loadConfig(cfg, filePath)) { | ||
logger.warn("Unable to load configuration from {}"_tr(filePath)); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool writeConfig(S_Config newCfg) { | ||
auto& mSelf = entry::entry::getInstance().getSelf(); | ||
auto configFilePath = mSelf.getConfigDir() / CONFIG_FILE_NAME; | ||
auto& logger = mSelf.getLogger(); | ||
|
||
if (!ll::config::saveConfig(newCfg, configFilePath)) { | ||
logger.error("Cannot save configurations to {}"_tr(configFilePath)); | ||
return false; | ||
} | ||
return true; | ||
} | ||
bool writeConfig() { return writeConfig(cfg); } | ||
|
||
} // namespace tls::config |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
#include "mc/world/actor/player/Player.h" | ||
#include <functional> | ||
#include <string> | ||
#include <unordered_map> | ||
#include "mc/world/actor/player/Player.h" | ||
|
||
|
||
namespace tls::form { | ||
|
||
extern std::unordered_map<std::string, std::function<void(Player&)>> mapping; | ||
bool initMapping(); | ||
|
||
} | ||
} // namespace tls::form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ enum Permission { | |
|
||
void initPermission(); | ||
|
||
} // namespace tls::perm | ||
} // namespace tls::perms |