Skip to content

Commit

Permalink
fix: remove to_underlying in DataItem
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Apr 13, 2024
1 parent 3838b66 commit d05cc1d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
7 changes: 6 additions & 1 deletion src/ll/api/schedule/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#include <ctime>
#include <iomanip>
#include <optional>
#include <spanstream>
#include <string_view>
#include <thread>

#if _HAS_CXX23
#include <spanstream>
#endif

#include "ll/api/Logger.h"
#include "ll/api/utils/ErrorUtils.h"
#include "ll/core/LeviLamina.h"
Expand All @@ -35,9 +38,11 @@ static std::optional<time_t> tryParseTime(std::string_view expression, std::stri
std::tm tm{};
auto time_now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
localtime_s(&tm, &time_now);
#if _HAS_CXX23
if (std::ispanstream{expression} >> std::get_time(&tm, format.data())) {
return std::mktime(&tm);
}
#endif
return std::nullopt;
}
std::chrono::system_clock::time_point parseTime(std::string_view expression) {
Expand Down
2 changes: 2 additions & 0 deletions src/ll/core/LeviLamina.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ void leviLaminaMain() {
}
if (globalConfig.modules.crashLogger.enabled) {
if (globalConfig.modules.crashLogger.useBuiltin) {
#if _HAS_CXX23
static CrashLoggerNew crashLogger{};
#endif
} else {
CrashLogger::initCrashLogger();
}
Expand Down
4 changes: 2 additions & 2 deletions src/ll/core/command/PluginManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void registerPluginManageCommand() {
}
break;
default:
std::unreachable();
_STL_UNREACHABLE;
}
}>();
cmd.overload<LeviCommand2>()
Expand Down Expand Up @@ -142,7 +142,7 @@ void registerPluginManageCommand() {
break;
}
default:
std::unreachable();
_STL_UNREACHABLE;
}
}>();
cmd.overload().text("list").execute<[](CommandOrigin const&, CommandOutput& output) {
Expand Down
28 changes: 16 additions & 12 deletions src/ll/core/plugin/PluginRegistrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <chrono>
#include <cstddef>
#include <expected>
#include <filesystem>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -33,6 +32,7 @@
#include "ll/core/plugin/NativePluginManager.h"


#include "mc/external/expected_lite/expected.h"
#include "mc/server/ServerInstance.h"
#include "mc/world/events/ServerInstanceEventCoordinator.h"

Expand Down Expand Up @@ -60,29 +60,29 @@ enum class DirState {
Success,
};

static std::expected<Manifest, DirState> loadManifest(std::filesystem::path const& dir) {
static nonstd::expected<Manifest, DirState> loadManifest(std::filesystem::path const& dir) {
auto content = file_utils::readFile(dir / u8"manifest.json");
if (!content || content->empty()) {
return std::unexpected{DirState::Empty};
return nonstd::make_unexpected(DirState::Empty);
}
auto json = nlohmann::json::parse(*content, nullptr, false, true);
if (json.is_discarded()) {
return std::unexpected{DirState::Error};
return nonstd::make_unexpected(DirState::Error);
}
std::string dirName = string_utils::u8str2str(dir.filename().u8string());
Manifest manifest;
try {
reflection::deserialize<nlohmann::json, Manifest>(manifest, json);
} catch (...) {
error_utils::printCurrentException(logger);
return std::unexpected{DirState::Error};
return nonstd::make_unexpected(DirState::Error);
}
if (manifest.type == "preload-native" /*NativePluginTypeName*/) {
return std::unexpected{DirState::Empty}; // bypass preloader plugin
return nonstd::make_unexpected(DirState::Empty); // bypass preloader plugin
}
if (manifest.name != dirName) {
logger.error("Plugin name {} do not match folder {}"_tr(manifest.name, dirName));
return std::unexpected{DirState::Error};
return nonstd::make_unexpected(DirState::Error);
}
return manifest;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ void PluginRegistrar::loadAllPlugins() {
}
auto res = loadManifest(file.path())
.transform([&](auto&& manifest) {
manifests.emplace(std::string{manifest.name}, std::forward<decltype(manifest)>(manifest));
manifests.try_emplace(manifest.name, std::forward<decltype(manifest)>(manifest));
})
.error_or(DirState::Success);
if (res != DirState::Success) {
Expand All @@ -136,8 +136,11 @@ void PluginRegistrar::loadAllPlugins() {
error = true;
#if _HAS_CXX23
logger.error("Missing dependency {}"_tr(
dependency.version.transform([&](auto& ver) { return dependency.name + " " + ver.to_string(); }
).value_or(dependency.name)
dependency.version
.transform([&](auto& ver) {
return fmt::format("{} v{}", dependency.name, ver.to_string());
})
.value_or(dependency.name)
));
#endif
}
Expand Down Expand Up @@ -171,8 +174,9 @@ void PluginRegistrar::loadAllPlugins() {
#if _HAS_CXX23
logger.error("{} conflicts with {}"_tr(
name,
conflict.version.transform([&](auto& ver) { return conflict.name + " " + ver.to_string(); }
).value_or(conflict.name)
conflict.version
.transform([&](auto& ver) { return fmt::format("{} v{}", conflict.name, ver.to_string()); })
.value_or(conflict.name)
));
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/ll/core/tweak/ModifyInfomation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ LL_STATIC_HOOK(
}
if (success && bufferCount > 0) {
buffer = std::string(bufferCount, '\0');
vsprintf(buffer.data(), pszFormat, va);
vsprintf_s(buffer.data(), buffer.size() + 1, pszFormat, va);
}
va_end(va);

Expand Down
2 changes: 1 addition & 1 deletion src/mc/nbt/detail/SnbtErrorCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ inline std::error_category const& snbt_category() noexcept {
return std::_Immortalize_memcpy_image<struct snbt_category>();
}

std::error_code makeSnbtError(SnbtErrorCode code) { return std::error_code{std::to_underlying(code), snbt_category()}; }
std::error_code makeSnbtError(SnbtErrorCode code) { return std::error_code{fmt::underlying(code), snbt_category()}; }

} // namespace ll::nbt::detail
2 changes: 1 addition & 1 deletion src/mc/world/actor/DataItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DataItem {
template <typename T>
requires(DataItem::TypeList::contains<std::remove_cvref_t<T>>)
[[nodiscard]] constexpr static std::unique_ptr<DataItem> create(::ActorDataIDs key, T&& value) {
return create(std::to_underlying(key), std::forward<T>(value));
return create(static_cast<std::underlying_type_t<::ActorDataIDs>>(key), std::forward<T>(value));
}
[[nodiscard]] constexpr static std::unique_ptr<DataItem> create(::ActorDataIDs key, bool value) {
return create(key, (schar)value);
Expand Down
5 changes: 3 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
add_rules("mode.debug", "mode.release")
add_rules("mode.release", "mode.debug")
set_allowedarchs("windows|x64")
set_defaultarchs("windows|x64")

add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")

Expand Down Expand Up @@ -64,7 +66,6 @@ target("LeviLamina")
)
add_defines(
"_AMD64_",
"_CRT_SECURE_NO_WARNINGS",
"NOMINMAX",
"UNICODE",
"WIN32_LEAN_AND_MEAN",
Expand Down

0 comments on commit d05cc1d

Please sign in to comment.